Support gles animation.
[vuplus_openvuplus_3.0] / meta-openvuplus / recipes-support / libshairport / libshairport / 006_no_printf.patch
1 --- src/alac.c  2011-08-21 00:06:21.000000000 +0200
2 +++ src/alac.c  2011-10-01 04:12:09.000000000 +0200
3 @@ -804,7 +804,7 @@
4              }
5              else
6              {
7 -                fprintf(stderr, "FIXME: unhandled predicition type: %i\n", prediction_type);
8 +                xprintf("FIXME: unhandled predicition type: %i\n", prediction_type);
9                  /* i think the only other prediction type (or perhaps this is just a
10                   * boolean?) runs adaptive fir twice.. like:
11                   * predictor_decompress_fir_adapt(predictor_error, tempout, ...)
12 @@ -885,7 +885,7 @@
13          }
14          case 20:
15          case 32:
16 -            fprintf(stderr, "FIXME: unimplemented sample size %i\n", alac->setinfo_sample_size);
17 +            xprintf("FIXME: unimplemented sample size %i\n", alac->setinfo_sample_size);
18              break;
19          default:
20              break;
21 @@ -1004,7 +1004,7 @@
22              }
23              else
24              { /* see mono case */
25 -                fprintf(stderr, "FIXME: unhandled predicition type: %i\n", prediction_type_a);
26 +                xprintf("FIXME: unhandled predicition type: %i\n", prediction_type_a);
27              }
28  
29              /* channel 2 */
30 @@ -1029,7 +1029,7 @@
31              }
32              else
33              {
34 -                fprintf(stderr, "FIXME: unhandled predicition type: %i\n", prediction_type_b);
35 +                xprintf("FIXME: unhandled predicition type: %i\n", prediction_type_b);
36              }
37          }
38          else
39 @@ -1106,7 +1106,7 @@
40          }
41          case 20:
42          case 32:
43 -            fprintf(stderr, "FIXME: unimplemented sample size %i\n", alac->setinfo_sample_size);
44 +            xprintf("FIXME: unimplemented sample size %i\n", alac->setinfo_sample_size);
45              break;
46          default:
47              break;
48 --- src/hairtunes.c     2011-10-01 17:45:08.000000000 +0200
49 +++ src/hairtunes.c     2011-10-01 17:42:07.000000000 +0200
50 @@ -121,8 +121,8 @@
51  pthread_cond_t ab_buffer_ready;
52  
53  static void die(char *why) {
54 -    fprintf(stderr, "FATAL: %s\n", why);
55 -    exit(1);
56 +    xprintf("FATAL: %s\n", why);
57 +    //exit(1);
58  }
59  
60  static int hex2bin(unsigned char *buf, char *hex) {
61 @@ -245,13 +245,13 @@
62              continue;
63          }
64          if (!strcmp(line, "exit\n")) {
65 -            exit(0);
66 +            ;//exit(0);
67          }
68          if (!strcmp(line, "flush\n")) {
69              hairtunes_flush();
70          }
71      }
72 -    fprintf(stderr, "bye!\n");
73 +    xprintf("bye!\n");
74      fflush(stderr);
75  #endif
76  
77 @@ -262,7 +262,7 @@
78  {
79    assert(f<=0);
80    if (debug)
81 -      fprintf(stderr, "VOL: %lf\n", f);
82 +      xprintf("VOL: %lf\n", f);
83    volume = pow(10.0,0.05*f);
84    fix_volume = 65536.0 * volume;
85  }
86 @@ -273,7 +273,7 @@
87    ab_resync();
88    pthread_mutex_unlock(&ab_mutex);
89    if (debug)
90 -      fprintf(stderr, "FLUSH\n");
91 +      xprintf("FLUSH\n");
92  }
93  
94  #ifdef HAIRTUNES_STANDALONE
95 @@ -423,7 +423,7 @@
96      } else if (seq_order(ab_read, seqno)) {     // late but not yet played
97          abuf = audio_buffer + BUFIDX(seqno);
98      } else {    // too late.
99 -        fprintf(stderr, "\nlate packet %04X (%04X:%04X)\n", seqno, ab_read, ab_write);
100 +        xprintf("\nlate packet %04X (%04X:%04X)\n", seqno, ab_read, ab_write);
101      }
102      buf_fill = ab_write - ab_read;
103      pthread_mutex_unlock(&ab_mutex);
104 @@ -520,7 +520,7 @@
105      if (seq_order(last, first))
106          return;
107  
108 -    fprintf(stderr, "requesting resend on %d packets (port %d)\n", last-first+1, controlport);
109 +    xprintf("requesting resend on %d packets (port %d)\n", last-first+1, controlport);
110  
111      char req[8];    // *not* a standard RTCP NACK
112      req[0] = 0x80;
113 @@ -604,8 +604,8 @@
114          port += 3;
115      }
116  
117 -    printf("port: %d\n", port); // let our handler know where we end up listening
118 -    printf("cport: %d\n", port+1);
119 +    xprintf("port: %d\n", port); // let our handler know where we end up listening
120 +    xprintf("cport: %d\n", port+1);
121  
122      rtp_sockets[0] = sock;
123      rtp_sockets[1] = csock;
124 @@ -708,7 +708,7 @@
125      bf_est_drift = biquad_filt(&bf_drift_lpf, CONTROL_B*(bf_est_err*CONTROL_A + err_deriv) + bf_est_drift);
126  
127      if (debug)
128 -        fprintf(stderr, "bf %d err %f drift %f desiring %f ed %f estd %f\r", fill, bf_est_err, bf_est_drift, desired_fill, err_deriv, err_deriv + CONTROL_A*bf_est_err);
129 +        xprintf("bf %d err %f drift %f desiring %f ed %f estd %f\r", fill, bf_est_err, bf_est_drift, desired_fill, err_deriv, err_deriv + CONTROL_A*bf_est_err);
130      bf_playback_rate = 1.0 + CONTROL_A*bf_est_err + bf_est_drift;
131  
132      bf_last_err = bf_est_err;
133 @@ -724,7 +724,7 @@
134      buf_fill = ab_write - ab_read;
135      if (buf_fill < 1 || !ab_synced || ab_buffering) {    // init or underrun. stop and wait
136          if (ab_synced)
137 -          fprintf(stderr, "\nunderrun\n");
138 +          xprintf("\nunderrun\n");
139  
140          ab_buffering = 1;
141          pthread_cond_wait(&ab_buffer_ready, &ab_mutex);
142 @@ -736,7 +736,7 @@
143          return 0;
144      }
145      if (buf_fill >= BUFFER_FRAMES) {   // overrunning! uh-oh. restart at a sane distance
146 -        fprintf(stderr, "\noverrun.\n");
147 +        xprintf("\noverrun.\n");
148          ab_read = ab_write - START_FILL;
149      }
150      read = ab_read;
151 @@ -748,7 +748,7 @@
152  
153      volatile abuf_t *curframe = audio_buffer + BUFIDX(read);
154      if (!curframe->ready) {
155 -        fprintf(stderr, "\nmissing frame.\n");
156 +        xprintf("\nmissing frame.\n");
157          memset(curframe->data, 0, FRAME_BYTES);
158      }
159      curframe->ready = 0;
160 @@ -775,13 +775,13 @@
161      if (stuff) {
162          if (stuff==1) {
163              if (debug)
164 -                fprintf(stderr, "+++++++++\n");
165 +                xprintf("+++++++++\n");
166              // interpolate one sample
167              *outptr++ = dithered_vol(((long)inptr[-2] + (long)inptr[0]) >> 1);
168              *outptr++ = dithered_vol(((long)inptr[-1] + (long)inptr[1]) >> 1);
169          } else if (stuff==-1) {
170              if (debug)
171 -                fprintf(stderr, "---------\n");
172 +                xprintf("---------\n");
173              inptr++;
174              inptr++;
175          }
176 --- src/shairport.c     2011-10-01 17:45:08.000000000 +0200
177 +++ src/shairport.c     2011-10-01 17:41:04.000000000 +0200
178 @@ -31,6 +31,27 @@
179  #include "shairport.h"
180  #include "hairtunes.h"
181  
182 +static struct printfPtr g_printf={NULL};
183 +
184 +int xprintf(const char *format, ...)
185 +{
186 +  char dbg[2048];
187 +  va_list args;
188 +  va_start(args, format);
189 +  vsnprintf(dbg, sizeof(dbg), format, args);
190 +  va_end(args);
191 +  if(g_printf.extprintf)
192 +  {
193 +    g_printf.extprintf(dbg, sizeof(dbg));
194 +  }
195 +  else 
196 +  {
197 +    printf(dbg);
198 +  }
199 +
200 +  return 1;
201 +}
202 +
203  #ifndef TRUE
204  #define TRUE (-1)
205  #endif
206 @@ -98,6 +119,11 @@
207  {
208   g_ao=*ao;
209  }
210 +
211 +void shairport_set_printf(struct printfPtr *funcPtr)
212 +{
213 +  g_printf = *funcPtr;
214 +}
215  #endif
216  
217  #ifndef XBMC
218 @@ -106,7 +132,7 @@
219  int shairport_main(int argc, char **argv)
220  #endif
221  {
222 -  printf("initializing shairport\n");
223 +  xprintf("initializing shairport\n",NULL);
224    char tHWID_Hex[HWID_SIZE * 2 + 1];
225    char tKnownHwid[32];
226  
227 @@ -185,22 +211,22 @@
228      }    
229      else if(!strcmp(arg, "-h") || !strcmp(arg, "--help"))
230      {
231 -      slog(LOG_INFO, "ShairPort version 0.05 C port - Airport Express emulator\n");
232 -      slog(LOG_INFO, "Usage:\nshairport [OPTION...]\n\nOptions:\n");
233 -      slog(LOG_INFO, "  -a, --apname=AirPort    Sets Airport name\n");
234 -      slog(LOG_INFO, "  -p, --password=secret   Sets Password (not working)\n");
235 -      slog(LOG_INFO, "  -o, --server_port=5000  Sets Port for Avahi/dns-sd\n");
236 -      slog(LOG_INFO, "  -b, --buffer=282        Sets Number of frames to buffer before beginning playback\n");
237 -      slog(LOG_INFO, "  -d                      Daemon mode\n");
238 -      slog(LOG_INFO, "  -q, --quiet             Supresses all output.\n");
239 -      slog(LOG_INFO, "  -v,-v2,-v3,-vv          Various debugging levels\n");
240 -      slog(LOG_INFO, "\n");
241 +      xprintf("ShairPort version 0.05 C port - Airport Express emulator\n");
242 +      xprintf("Usage:\nshairport [OPTION...]\n\nOptions:\n");
243 +      xprintf("  -a, --apname=AirPort    Sets Airport name\n");
244 +      xprintf("  -p, --password=secret   Sets Password (not working)\n");
245 +      xprintf("  -o, --server_port=5000  Sets Port for Avahi/dns-sd\n");
246 +      xprintf("  -b, --buffer=282        Sets Number of frames to buffer before beginning playback\n");
247 +      xprintf("  -d                      Daemon mode\n");
248 +      xprintf("  -q, --quiet             Supresses all output.\n");
249 +      xprintf("  -v,-v2,-v3,-vv          Various debugging levels\n");
250 +      xprintf("\n");
251        return 0;
252      }    
253    }
254  
255    if ( buffer_start_fill < 30 || buffer_start_fill > BUFFER_FRAMES ) { 
256 -     fprintf(stderr, "buffer value must be > 30 and < %d\n", BUFFER_FRAMES);
257 +     xprintf("buffer value must be > 30 and < %d\n", BUFFER_FRAMES);
258       return(0);
259    }
260  
261 @@ -209,11 +235,11 @@
262      int tPid = fork();
263      if(tPid < 0)
264      {
265 -      exit(1); // Error on fork
266 +      //exit(1); // Error on fork
267      }
268      else if(tPid > 0)
269      {
270 -      exit(0);
271 +      //exit(0);
272      }
273      else
274      {
275 @@ -254,10 +280,10 @@
276      sscanf(tHWID_Hex, "%02X%02X%02X%02X%02X%02X", &tHWID[0], &tHWID[1], &tHWID[2], &tHWID[3], &tHWID[4], &tHWID[5]);
277    }
278  
279 -  slog(LOG_INFO, "LogLevel: %d\n", kCurrentLogLevel);
280 -  slog(LOG_INFO, "AirName: %s\n", tServerName);
281 -  slog(LOG_INFO, "HWID: %.*s\n", HWID_SIZE, tHWID+1);
282 -  slog(LOG_INFO, "HWID_Hex(%d): %s\n", strlen(tHWID_Hex), tHWID_Hex);
283 +  xprintf("LogLevel: %d\n", kCurrentLogLevel);
284 +  xprintf("AirName: %s\n", tServerName);
285 +  xprintf("HWID: %.*s\n", HWID_SIZE, tHWID+1);
286 +  xprintf("HWID_Hex(%d): %s\n", strlen(tHWID_Hex), tHWID_Hex);
287  
288    if(tSimLevel >= 1)
289    {
290 @@ -271,12 +297,12 @@
291  #ifndef XBMC
292      startAvahi(tHWID_Hex, tServerName, tPort);
293  #endif
294 -    slog(LOG_DEBUG_V, "Starting connection server: specified server port: %d\n", tPort);
295 +    xprintf("Starting connection server: specified server port: %d\n", tPort);
296      tServerSock = setupListenServer(&tAddrInfo, tPort);
297      if(tServerSock < 0)
298      {
299        freeaddrinfo(tAddrInfo);
300 -      slog(LOG_INFO, "Error setting up server socket on port %d, try specifying a different port\n", tPort);
301 +      xprintf("Error setting up server socket on port %d, try specifying a different port\n", tPort);
302        return 0;
303      }
304  
305 @@ -303,7 +329,7 @@
306  
307      int readsock;
308  
309 -    slog(LOG_DEBUG_V, "Waiting for clients to connect\n");
310 +    xprintf("Waiting for clients to connect\n");
311  
312      while(m_running)
313      {
314 @@ -335,7 +361,7 @@
315          {
316            freeaddrinfo(tAddrInfo);
317            tAddrInfo = NULL;
318 -          slog(LOG_DEBUG, "...Accepted Client Connection..\n");
319 +          xprintf("...Accepted Client Connection..\n");
320            close(tServerSock);
321            handleClient(tClientSock, tPassword, tHWID);
322            //close(tClientSock);
323 @@ -343,11 +369,11 @@
324          }
325          else
326          {
327 -          slog(LOG_DEBUG_VV, "Child now busy handling new client\n");
328 +          xprintf("Child now busy handling new client\n");
329            close(tClientSock);
330          }
331  #else
332 -      slog(LOG_DEBUG, "...Accepted Client Connection..\n");
333 +      xprintf("...Accepted Client Connection..\n");
334        handleClient(tClientSock, tPassword, tHWID);
335  #endif
336        }
337 @@ -357,7 +383,7 @@
338        }
339    }
340  
341 -  slog(LOG_DEBUG_VV, "Finished\n");
342 +  xprintf("Finished\n");
343    if(tAddrInfo != NULL)
344    {
345      freeaddrinfo(tAddrInfo);
346 @@ -416,7 +442,7 @@
347  
348  void handleClient(int pSock, char *pPassword, char *pHWADDR)
349  {
350 -  slog(LOG_DEBUG_VV, "In Handle Client\n");
351 +  xprintf("In Handle Client\n");
352    fflush(stdout);
353  
354    socklen_t len;
355 @@ -435,7 +461,7 @@
356  
357    // deal with both IPv4 and IPv6:
358    if (addr.ss_family == AF_INET) {
359 -      slog(LOG_DEBUG_V, "Constructing ipv4 address\n");
360 +      xprintf("Constructing ipv4 address\n");
361        struct sockaddr_in *s = (struct sockaddr_in *)&addr;
362        port = ntohs(s->sin_port);
363        inet_ntop(AF_INET, &s->sin_addr, ipstr, sizeof ipstr);
364 @@ -455,20 +481,20 @@
365        if(memcmp(&addr.bin[0], "\x00\x00\x00\x00" "\x00\x00\x00\x00" "\x00\x00\xff\xff", 12) == 0)
366        {
367          // its ipv4...
368 -        slog(LOG_DEBUG_V, "Constructing ipv4 from ipv6 address\n");
369 +        xprintf("Constructing ipv4 from ipv6 address\n");
370          memcpy(ipbin, &addr.bin[12], 4);
371          ipbinlen = 4;
372        }
373        else
374        {
375 -        slog(LOG_DEBUG_V, "Constructing ipv6 address\n");
376 +        xprintf("Constructing ipv6 address\n");
377          memcpy(ipbin, &s->sin6_addr, 16);
378          ipbinlen = 16;
379        }
380    }
381  
382 -  slog(LOG_DEBUG_V, "Peer IP address: %s\n", ipstr);
383 -  slog(LOG_DEBUG_V, "Peer port      : %d\n", port);
384 +  xprintf("Peer IP address: %s\n", ipstr);
385 +  xprintf("Peer port      : %d\n", port);
386  
387    int tMoreDataNeeded = 1;
388    struct keyring     tKeys;
389 @@ -489,16 +515,16 @@
390        tError = readDataFromClient(pSock, &(tConn.recv));
391        if(!tError && strlen(tConn.recv.data) > 0)
392        {
393 -        slog(LOG_DEBUG_VV, "Finished Reading some data from client\n");
394 +        xprintf("Finished Reading some data from client\n");
395          // parse client request
396          tMoreDataNeeded = parseMessage(&tConn, ipbin, ipbinlen, pHWADDR);
397          if(1 == tMoreDataNeeded)
398          {
399 -          slog(LOG_DEBUG_VV, "\n\nNeed to read more data\n");
400 +          xprintf("\n\nNeed to read more data\n");
401          }
402          else if(-1 == tMoreDataNeeded) // Forked process down below ended.
403          {
404 -          slog(LOG_DEBUG_V, "Forked Process ended...cleaning up\n");
405 +          xprintf("Forked Process ended...cleaning up\n");
406            cleanup(&tConn);
407            // pSock was already closed
408            return;
409 @@ -507,13 +533,13 @@
410        }
411        else
412        {
413 -        slog(LOG_DEBUG, "Error reading from socket, closing client\n");
414 +        xprintf("Error reading from socket, closing client\n");
415          // Error reading data....quit.
416          cleanup(&tConn);
417          return;
418        }
419      }
420 -    slog(LOG_DEBUG_VV, "Writing: %d chars to socket\n", tConn.resp.current);
421 +    xprintf("Writing: %d chars to socket\n", tConn.resp.current);
422      //tConn->resp.data[tConn->resp.current-1] = '\0';
423      writeDataToClient(pSock, &(tConn.resp));
424     // Finished reading one message...
425 @@ -526,9 +552,9 @@
426  
427  void writeDataToClient(int pSock, struct shairbuffer *pResponse)
428  {
429 -  slog(LOG_DEBUG_VV, "\n----Beg Send Response Header----\n%.*s\n", pResponse->current, pResponse->data);
430 +  xprintf("\n----Beg Send Response Header----\n%.*s\n", pResponse->current, pResponse->data);
431    send(pSock, pResponse->data, pResponse->current,0);
432 -  slog(LOG_DEBUG_VV, "----Send Response Header----\n");
433 +  xprintf("----Send Response Header----\n");
434  }
435  
436  int readDataFromClient(int pSock, struct shairbuffer *pClientBuffer)
437 @@ -541,7 +567,7 @@
438    while(tRetval > 0 && tEnd < 0)
439    {
440       // Read from socket until \n\n, \r\n\r\n, or \r\r is found
441 -      slog(LOG_DEBUG_V, "Waiting To Read...\n");
442 +      xprintf("Waiting To Read...\n");
443        fflush(stdout);
444        tRetval = read(pSock, tReadBuf, MAX_SIZE);
445        // if new buffer contains the end of request string, only copy partial buffer?
446 @@ -552,40 +578,40 @@
447          {
448            pClientBuffer->marker = tEnd+1; // Marks start of content
449          }
450 -        slog(SOCKET_LOG_LEVEL, "Found end of http request at: %d\n", tEnd);
451 +        xprintf("Found end of http request at: %d\n", tEnd);
452          fflush(stdout);        
453        }
454        else
455        {
456          tEnd = MAX_SIZE;
457 -        slog(SOCKET_LOG_LEVEL, "Read %d of data so far\n%s\n", tRetval, tReadBuf);
458 +        xprintf("Read %d of data so far\n%s\n", tRetval, tReadBuf);
459          fflush(stdout);
460        }
461        if(tRetval > 0)
462        {
463          // Copy read data into tReceive;
464 -        slog(SOCKET_LOG_LEVEL, "Read %d data, using %d of it\n", tRetval, tEnd);
465 +        xprintf("Read %d data, using %d of it\n", tRetval, tEnd);
466          addNToShairBuffer(pClientBuffer, tReadBuf, tRetval);
467 -        slog(LOG_DEBUG_VV, "Finished copying data\n");
468 +        xprintf("Finished copying data\n");
469        }
470        else
471        {
472 -        slog(LOG_DEBUG, "Error reading data from socket, got: %d bytes", tRetval);
473 +        xprintf("Error reading data from socket, got: %d bytes", tRetval);
474          return tRetval;
475        }
476    }
477    if(tEnd + 1 != tRetval)
478    {
479 -    slog(SOCKET_LOG_LEVEL, "Read more data after end of http request. %d instead of %d\n", tRetval, tEnd+1);
480 +    xprintf("Read more data after end of http request. %d instead of %d\n", tRetval, tEnd+1);
481    }
482 -  slog(SOCKET_LOG_LEVEL, "Finished Reading Data:\n%s\nEndOfData\n", pClientBuffer->data);
483 +  xprintf("Finished Reading Data:\n%s\nEndOfData\n", pClientBuffer->data);
484    fflush(stdout);
485    return 0;
486  }
487  
488  char *getFromBuffer(char *pBufferPtr, const char *pField, int pLenAfterField, int *pReturnSize, char *pDelims)
489  {
490 -  slog(LOG_DEBUG_V, "GettingFromBuffer: %s\n", pField);
491 +  xprintf("GettingFromBuffer: %s\n", pField);
492    char* tFound = strstr(pBufferPtr, pField);
493    int tSize = 0;
494    if(tFound != NULL)
495 @@ -606,7 +632,7 @@
496      }
497      
498      tSize = (int) (tShortest - tFound);
499 -    slog(LOG_DEBUG_VV, "Found %.*s  length: %d\n", tSize, tFound, tSize);
500 +    xprintf("Found %.*s  length: %d\n", tSize, tFound, tSize);
501      if(pReturnSize != NULL)
502      {
503        *pReturnSize = tSize;
504 @@ -614,7 +640,7 @@
505    }
506    else
507    {
508 -    slog(LOG_DEBUG_V, "Not Found\n");
509 +    xprintf("Not Found\n");
510    }
511    return tFound;
512  }
513 @@ -648,10 +674,10 @@
514    {
515      char tTrim[tFoundSize + 2];
516      getTrimmed(tFound, tFoundSize, TRUE, TRUE, tTrim);
517 -    slog(LOG_DEBUG_VV, "HeaderChallenge:  [%s] len: %d  sizeFound: %d\n", tTrim, strlen(tTrim), tFoundSize);
518 +    xprintf("HeaderChallenge:  [%s] len: %d  sizeFound: %d\n", tTrim, strlen(tTrim), tFoundSize);
519      int tChallengeDecodeSize = 16;
520      char *tChallenge = decode_base64((unsigned char *)tTrim, tFoundSize, &tChallengeDecodeSize);
521 -    slog(LOG_DEBUG_VV, "Challenge Decode size: %d  expected 16\n", tChallengeDecodeSize);
522 +    xprintf("Challenge Decode size: %d  expected 16\n", tChallengeDecodeSize);
523  
524      int tCurSize = 0;
525      unsigned char tChalResp[38];
526 @@ -673,7 +699,7 @@
527      }
528  
529      char *tTmp = encode_base64((unsigned char *)tChalResp, tCurSize);
530 -    slog(LOG_DEBUG_VV, "Full sig: %s\n", tTmp);
531 +    xprintf("Full sig: %s\n", tTmp);
532      free(tTmp);
533  
534      // RSA Encrypt
535 @@ -722,10 +748,10 @@
536      {
537        if(isLogEnabledFor(HEADER_LOG_LEVEL))
538        {
539 -        slog(HEADER_LOG_LEVEL, "Content-Length: %s value -> %d\n", tContent, tContentSize);
540 +        xprintf("Content-Length: %s value -> %d\n", tContent, tContentSize);
541          if(pConn->recv.marker != 0)
542          {
543 -          slog(HEADER_LOG_LEVEL, "ContentPtr has %d, but needs %d\n", 
544 +          xprintf("ContentPtr has %d, but needs %d\n", 
545                    strlen(pConn->recv.data+pConn->recv.marker), tContentSize);
546          }
547        }
548 @@ -735,7 +761,7 @@
549    }
550    else
551    {
552 -    slog(LOG_DEBUG_VV, "No content, header only\n");
553 +    xprintf("No content, header only\n");
554    }
555  
556    // "Creates" a new Response Header for our response message
557 @@ -748,7 +774,7 @@
558      {
559        tLen = 20;
560      }
561 -    slog(LOG_INFO, "********** RECV %.*s **********\n", tLen, pConn->recv.data);
562 +    xprintf("********** RECV %.*s **********\n", tLen, pConn->recv.data);
563    }
564  
565    if(pConn->password != NULL)
566 @@ -758,7 +784,7 @@
567  
568    if(buildAppleResponse(pConn, pIpBin, pIpBinLen, pHWID)) // need to free sig
569    {
570 -    slog(LOG_DEBUG_V, "Added AppleResponse to Apple-Challenge request\n");
571 +    xprintf("Added AppleResponse to Apple-Challenge request\n");
572    }
573  
574    // Find option, then based on option, do different actions.
575 @@ -778,14 +804,14 @@
576        int tKeySize = 0;
577        char tEncodedAesIV[tSize + 2];
578        getTrimmed(tHeaderVal, tSize, TRUE, TRUE, tEncodedAesIV);
579 -      slog(LOG_DEBUG_VV, "AESIV: [%.*s] Size: %d  Strlen: %d\n", tSize, tEncodedAesIV, tSize, strlen(tEncodedAesIV));
580 +      xprintf("AESIV: [%.*s] Size: %d  Strlen: %d\n", tSize, tEncodedAesIV, tSize, strlen(tEncodedAesIV));
581        char *tDecodedIV =  decode_base64((unsigned char*) tEncodedAesIV, tSize, &tSize);
582  
583        // grab the key, copy it out of the receive buffer
584        tHeaderVal = getFromContent(tContent, "a=rsaaeskey", &tKeySize);
585        char tEncodedAesKey[tKeySize + 2]; // +1 for nl, +1 for \0
586        getTrimmed(tHeaderVal, tKeySize, TRUE, TRUE, tEncodedAesKey);
587 -      slog(LOG_DEBUG_VV, "AES KEY: [%s] Size: %d  Strlen: %d\n", tEncodedAesKey, tKeySize, strlen(tEncodedAesKey));
588 +      xprintf("AES KEY: [%s] Size: %d  Strlen: %d\n", tEncodedAesKey, tKeySize, strlen(tEncodedAesKey));
589        // remove base64 coding from key
590        char *tDecodedAesKey = decode_base64((unsigned char*) tEncodedAesKey,
591                                tKeySize, &tKeySize);  // Need to free DecodedAesKey
592 @@ -794,7 +820,7 @@
593        int tFmtpSize = 0;
594        char *tFmtp = getFromContent(tContent, "a=fmtp", &tFmtpSize);  // Don't need to free
595        tFmtp = getTrimmedMalloc(tFmtp, tFmtpSize, TRUE, FALSE); // will need to free
596 -      slog(LOG_DEBUG_VV, "Format: %s\n", tFmtp);
597 +      xprintf("Format: %s\n", tFmtp);
598  
599        RSA *rsa = loadKey();
600        // Decrypt the binary aes key
601 @@ -803,11 +829,11 @@
602        if(RSA_private_decrypt(tKeySize, (unsigned char *)tDecodedAesKey, 
603        (unsigned char*) tDecryptedKey, rsa, RSA_PKCS1_OAEP_PADDING) >= 0)
604        {
605 -        slog(LOG_DEBUG, "Decrypted AES key from RSA Successfully\n");
606 +        xprintf("Decrypted AES key from RSA Successfully\n");
607        }
608        else
609        {
610 -        slog(LOG_INFO, "Error Decrypting AES key from RSA\n");
611 +        xprintf("Error Decrypting AES key from RSA\n");
612        }
613        free(tDecodedAesKey);
614        RSA_free(rsa);
615 @@ -823,13 +849,13 @@
616  //    struct comms *tComms = pConn->hairtunes;
617  //   if (! (pipe(tComms->in) == 0 && pipe(tComms->out) == 0))
618  //    {
619 -//      slog(LOG_INFO, "Error setting up hairtunes communications...some things probably wont work very well.\n");
620 +//      xprintf("Error setting up hairtunes communications...some things probably wont work very well.\n");
621  //    }
622      
623      // Setup fork
624      char tPort[8] = "6000";  // get this from dup()'d stdout of child pid
625  
626 -    printf("******** SETUP!!!!!\n");
627 +    xprintf("******** SETUP!!!!!\n",NULL);
628  #ifndef XBMC
629      int tPid = fork();
630      if(tPid == 0)
631 @@ -845,11 +871,11 @@
632        tFound = getFromSetup(pConn->recv.data, "timing_port", &tSize);
633        getTrimmed(tFound, tSize, 1, 0, tTPortStr);
634  
635 -      slog(LOG_DEBUG_VV, "converting %s and %s from str->int\n", tCPortStr, tTPortStr);
636 +      xprintf("converting %s and %s from str->int\n", tCPortStr, tTPortStr);
637        int tControlport = atoi(tCPortStr);
638        int tTimingport = atoi(tTPortStr);
639  
640 -      slog(LOG_DEBUG_V, "Got %d for CPort and %d for TPort\n", tControlport, tTimingport);
641 +      xprintf("Got %d for CPort and %d for TPort\n", tControlport, tTimingport);
642        char *tRtp = NULL;
643        char *tPipe = NULL;
644        char *tAoDriver = NULL;
645 @@ -884,7 +910,7 @@
646                        tDataport, tRtp, tPipe, tAoDriver, tAoDeviceName, tAoDeviceId);
647  #ifndef XBMC
648        // Quit when finished.
649 -      slog(LOG_DEBUG, "Returned from hairtunes init....returning -1, should close out this whole side of the fork\n");
650 +      xprintf("Returned from hairtunes init....returning -1, should close out this whole side of the fork\n");
651        return -1;
652      }
653      else if(tPid >0)
654 @@ -897,7 +923,7 @@
655        int tRead = read(tComms->out[0], tFromHairtunes, 80);
656        if(tRead <= 0)
657        {
658 -        slog(LOG_INFO, "Error reading port from hairtunes function, assuming default port: %d\n", tPort);
659 +        xprintf("Error reading port from hairtunes function, assuming default port: %d\n", tPort);
660        }
661        else
662        {
663 @@ -909,7 +935,7 @@
664          }
665          else
666          {
667 -          slog(LOG_INFO, "Read %d bytes, Error translating %s into a port\n", tRead, tFromHairtunes);
668 +          xprintf("Read %d bytes, Error translating %s into a port\n", tRead, tFromHairtunes);
669          }
670        }
671  
672 @@ -930,7 +956,7 @@
673      }
674      else
675      {
676 -      slog(LOG_INFO, "Error forking process....dere' be errors round here.\n");
677 +      xprintf("Error forking process....dere' be errors round here.\n");
678        return -1;
679      }
680  #endif
681 @@ -942,7 +968,7 @@
682      propogateCSeq(pConn);
683  #ifndef XBMC
684      close(pConn->hairtunes->in[1]);
685 -    slog(LOG_DEBUG, "Tearing down connection, closing pipes\n");
686 +    xprintf("Tearing down connection, closing pipes\n");
687  #else
688      hairtunes_cleanup();
689  #endif
690 @@ -964,7 +990,7 @@
691      propogateCSeq(pConn);
692      int tSize = 0;
693      char *tVol = getFromHeader(pConn->recv.data, "volume", &tSize);
694 -    slog(LOG_DEBUG_VV, "About to write [vol: %.*s] data to hairtunes\n", tSize, tVol);
695 +    xprintf("About to write [vol: %.*s] data to hairtunes\n", tSize, tVol);
696      // TBD VOLUME
697  #ifndef XBMC
698      write(pConn->hairtunes->in[1], "vol: ", 5);
699 @@ -973,11 +999,11 @@
700  #else
701      hairtunes_setvolume(atof(tVol));
702  #endif
703 -    slog(LOG_DEBUG_VV, "Finished writing data write data to hairtunes\n");
704 +    xprintf("Finished writing data write data to hairtunes\n");
705    }
706    else
707    {
708 -    slog(LOG_DEBUG, "\n\nUn-Handled recv: %s\n", pConn->recv.data);
709 +    xprintf("\n\nUn-Handled recv: %s\n", pConn->recv.data);
710      propogateCSeq(pConn);
711    }
712    addToShairBuffer(&(pConn->resp), "\r\n");
713 @@ -1056,7 +1082,7 @@
714      char tName[100 + HWID_SIZE + 3];
715      if(strlen(pServerName) > tMaxServerName)
716      {
717 -      slog(LOG_INFO,"Hey dog, we see you like long server names, "
718 +      xprintf("Hey dog, we see you like long server names, "
719                "so we put a strncat in our command so we don't buffer overflow, while you listen to your flow.\n"
720                "We just used the first %d characters.  Pick something shorter if you want\n", tMaxServerName);
721      }
722 @@ -1067,7 +1093,7 @@
723      strcat(tName, pHWStr);
724      strcat(tName, "@");
725      strncat(tName, pServerName, tMaxServerName);
726 -    slog(AVAHI_LOG_LEVEL, "Avahi/DNS-SD Name: %s\n", tName);
727 +    xprintf("Avahi/DNS-SD Name: %s\n", tName);
728      
729      execlp("avahi-publish-service", "avahi-publish-service", tName,
730           "_raop._tcp", tPort, "tp=UDP","sm=false","sv=false","ek=1","et=0,1",
731 @@ -1079,12 +1105,12 @@
732              perror("error");
733      }
734  
735 -    slog(LOG_INFO, "Bad error... couldn't find or failed to run: avahi-publish-service OR dns-sd\n");
736 -    exit(1);
737 +    xprintf("Bad error... couldn't find or failed to run: avahi-publish-service OR dns-sd\n");
738 +    //exit(1);
739    }
740    else
741    {
742 -    slog(LOG_DEBUG_VV, "Avahi/DNS-SD started on PID: %d\n", tPid);
743 +    xprintf("Avahi/DNS-SD started on PID: %d\n", tPid);
744    }
745    return tPid;
746  }
747 @@ -1092,7 +1118,7 @@
748  
749  void printBufferInfo(struct shairbuffer *pBuf, int pLevel)
750  {
751 -  slog(pLevel, "Buffer: [%s]  size: %d  maxchars:%d\n", pBuf->data, pBuf->current, pBuf->maxsize/sizeof(char));
752 +  xprintf("Buffer: [%s]  size: %d  maxchars:%d\n", pBuf->data, pBuf->current, pBuf->maxsize/sizeof(char));
753  }
754  
755  int getAvailChars(struct shairbuffer *pBuf)
756 @@ -1173,7 +1199,8 @@
757    {
758      va_list argp;
759      va_start(argp, pFormat);
760 -    vprintf(pFormat, argp);
761 +    xprintf(pFormat, argp);
762 +    //vprintf(pFormat, argp);
763      va_end(argp);
764    }
765    //#endif
766 @@ -1227,9 +1254,9 @@
767  {
768    if(pBuf->data != NULL)
769    {
770 -    slog(LOG_DEBUG_VV, "Hrm, buffer wasn't cleaned up....trying to free\n");
771 +    xprintf("Hrm, buffer wasn't cleaned up....trying to free\n");
772      free(pBuf->data);
773 -    slog(LOG_DEBUG_VV, "Free didn't seem to seg fault....huzzah\n");
774 +    xprintf("Free didn't seem to seg fault....huzzah\n");
775    }
776    pBuf->current = 0;
777    pBuf->marker = 0;
778 @@ -1287,6 +1314,6 @@
779    BIO *tBio = BIO_new_mem_buf(AIRPORT_PRIVATE_KEY, -1);
780    RSA *rsa = PEM_read_bio_RSAPrivateKey(tBio, NULL, NULL, NULL); //NULL, NULL, NULL);
781    BIO_free(tBio);
782 -  slog(RSA_LOG_LEVEL, "RSA Key: %d\n", RSA_check_key(rsa));
783 +  xprintf("RSA Key: %d\n", RSA_check_key(rsa));
784    return rsa;
785  }
786 --- src/shairport.h     2011-10-01 17:45:08.000000000 +0200
787 +++ src/shairport.h     2011-10-01 17:19:43.000000000 +0200
788 @@ -59,11 +59,17 @@
789  {
790  #endif /* __cplusplus */
791  
792 +struct printfPtr
793 +{
794 +  int (*extprintf)(const char* msg, size_t msgSize);
795 +};
796 +
797  int shairport_main(int argc, char **argv);
798  void shairport_exit(void);
799  int shairport_loop(void);
800  int shairport_is_running(void);
801  void shairport_set_ao(struct AudioOutput *ao);
802 +void shairport_set_printf(struct printfPtr *funcPtr);
803  
804  #ifdef __cplusplus
805  }
806 --- src/socketlib.c     2011-09-23 22:00:48.000000000 +0200
807 +++ src/socketlib.c     2011-10-01 17:42:39.000000000 +0200
808 @@ -82,7 +82,7 @@
809        delay(RETRY_DELAY, &tRes);
810      }
811    }
812 -  printf("%d Retry attempts exceeded\n", RETRY_COUNT);
813 +  xprintf("%d Retry attempts exceeded\n", RETRY_COUNT);
814    return ERROR;
815  }
816  
817 @@ -102,7 +102,7 @@
818    tError = getaddrinfo(pHostname, pService, &hints, pAddrInfo);
819    if(tError != 0)
820    {
821 -    printf("Error getting address info\n");
822 +    xprintf("Error getting address info\n");
823    }
824    return tError;
825  }
826 @@ -200,7 +200,7 @@
827    else
828    {
829      // Invalid encoded data, no other cases are possible.
830 -    printf("Unrecoverable error....base64 values are incorrectly encoded\n");
831 +    xprintf("Unrecoverable error....base64 values are incorrectly encoded\n");
832      return pSize;
833    }
834  }
835 @@ -226,7 +226,7 @@
836      memset(input, 0, length);
837      memcpy(input, pInput, pLength);
838      memset(input+pLength, '=', length-pLength);
839 -    printf("Fixed value: [%.*s]\n", length, input);
840 +    xprintf("Fixed value: [%.*s]\n", length, input);
841    }
842    char *buffer = (char *)malloc(length);
843    memset(buffer, 0, length);