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