summaryrefslogtreecommitdiff
path: root/testing/cups/cups-avahi-5-services.patch
blob: 820b3c32b9d52270ed1a5dcb6358b9c5dd7f9037 (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
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
diff -up cups-1.5.2/cgi-bin/admin.c.avahi-5-services cups-1.5.2/cgi-bin/admin.c
--- cups-1.5.2/cgi-bin/admin.c.avahi-5-services	2011-08-17 22:01:53.000000000 +0100
+++ cups-1.5.2/cgi-bin/admin.c	2012-03-14 15:08:25.701611799 +0000
@@ -1643,7 +1643,7 @@ do_config_server(http_t *http)		/* I - H
       else
 	local_protocols[0] = '\0';
 
-#ifdef HAVE_DNSSD
+#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
       if (cgiGetVariable("BROWSE_LOCAL_DNSSD"))
       {
 	if (local_protocols[0])
@@ -1651,7 +1651,7 @@ do_config_server(http_t *http)		/* I - H
 	else
 	  strcat(local_protocols, "dnssd");
       }
-#endif /* HAVE_DNSSD */
+#endif /* defined(HAVE_DNSSD) || defined(HAVE_AVAHI) */
 
 #ifdef HAVE_LDAP
       if (cgiGetVariable("BROWSE_LOCAL_LDAP"))
@@ -2718,9 +2718,9 @@ do_menu(http_t *http)			/* I - HTTP conn
 #endif /* HAVE_GSSAPI */
   cgiSetVariable("KERBEROS", "");
 
-#ifdef HAVE_DNSSD
+#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
   cgiSetVariable("HAVE_DNSSD", "1");
-#endif /* HAVE_DNSSD */
+#endif /* defined(HAVE_DNSSD) || defined(HAVE_AVAHI) */
 
 #ifdef HAVE_LDAP
   cgiSetVariable("HAVE_LDAP", "1");
diff -up cups-1.5.2/scheduler/avahi.h.avahi-5-services cups-1.5.2/scheduler/avahi.h
--- cups-1.5.2/scheduler/avahi.h.avahi-5-services	2012-03-14 15:07:29.477542381 +0000
+++ cups-1.5.2/scheduler/avahi.h	2012-03-14 15:08:25.701611799 +0000
@@ -3,7 +3,7 @@
  *
  *   Avahi poll implementation for the CUPS scheduler.
  *
- *   Copyright (C) 2010, 2011 Red Hat, Inc.
+ *   Copyright (C) 2010, 2011, 2012 Red Hat, Inc.
  *   Authors:
  *    Tim Waugh <twaugh@redhat.com>
  *
@@ -32,37 +32,40 @@
  *   OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <config.h>
+#ifndef _CUPS_AVAHI_H_
+#  define _CUPS_AVAHI_H_
 
-#ifdef HAVE_AVAHI
-#  include <avahi-client/client.h>
-#  include <avahi-client/publish.h>
-#endif /* HAVE_AVAHI */
+/*
+ * Include necessary headers...
+ */
 
-#ifdef HAVE_AUTHORIZATION_H
-#  include <Security/Authorization.h>
-#endif /* HAVE_AUTHORIZATION_H */
+#  include <config.h>
 
+#  ifdef HAVE_AVAHI
+#    include <avahi-client/client.h>
+#    include <avahi-client/publish.h>
+#  endif /* HAVE_AVAHI */
 
-#ifdef HAVE_AVAHI
+#  ifdef HAVE_AVAHI
 typedef struct
 {
     AvahiPoll api;
     cups_array_t *watched_fds;
     cups_array_t *timeouts;
 } AvahiCupsPoll;
-#endif /* HAVE_AVAHI */
+#  endif /* HAVE_AVAHI */
 
 /*
  * Prototypes...
  */
 
-#ifdef HAVE_AVAHI
+#  ifdef HAVE_AVAHI
 extern AvahiCupsPoll *	avahi_cups_poll_new(void);
 extern void		avahi_cups_poll_free(AvahiCupsPoll *cups_poll);
 extern const AvahiPoll *avahi_cups_poll_get(AvahiCupsPoll *cups_poll);
-#endif /* HAVE_AVAHI */
+#  endif /* HAVE_AVAHI */
 
+#endif /* !_CUPS_AVAHI_H_ */
 
 /*
  * End of "$Id$".
diff -up cups-1.5.2/scheduler/client.c.avahi-5-services cups-1.5.2/scheduler/client.c
--- cups-1.5.2/scheduler/client.c.avahi-5-services	2012-01-13 23:00:22.000000000 +0000
+++ cups-1.5.2/scheduler/client.c	2012-03-14 15:08:25.703611797 +0000
@@ -4989,7 +4989,7 @@ valid_host(cupsd_client_t *con)		/* I -
 	    !strncmp(host, "[::1]:", 6));
   }
 
-#ifdef HAVE_DNSSD
+#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
  /*
   * Check if the hostname is something.local (Bonjour); if so, allow it.
   */
@@ -4998,7 +4998,7 @@ valid_host(cupsd_client_t *con)		/* I -
       (!_cups_strcasecmp(end, ".local") || !_cups_strncasecmp(end, ".local:", 7) ||
        !_cups_strcasecmp(end, ".local.") || !_cups_strncasecmp(end, ".local.:", 8)))
     return (1);
-#endif /* HAVE_DNSSD */
+#endif /* defined(HAVE_DNSSD) || defined(HAVE_AVAHI) */
 
  /*
   * Check if the hostname is an IP address...
diff -up cups-1.5.2/scheduler/conf.c.avahi-5-services cups-1.5.2/scheduler/conf.c
--- cups-1.5.2/scheduler/conf.c.avahi-5-services	2012-03-14 15:04:17.636305526 +0000
+++ cups-1.5.2/scheduler/conf.c	2012-03-14 15:08:25.706611803 +0000
@@ -652,7 +652,7 @@ cupsdReadConfiguration(void)
   Browsing                 = CUPS_DEFAULT_BROWSING;
   DefaultShared            = CUPS_DEFAULT_DEFAULT_SHARED;
 
-#ifdef HAVE_DNSSD
+#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
   cupsdSetString(&DNSSDRegType, "_ipp._tcp,_cups");
 #endif /* HAVE_DNSSD */
 
diff -up cups-1.5.2/scheduler/dirsvc.c.avahi-5-services cups-1.5.2/scheduler/dirsvc.c
--- cups-1.5.2/scheduler/dirsvc.c.avahi-5-services	2012-03-14 15:04:17.674305572 +0000
+++ cups-1.5.2/scheduler/dirsvc.c	2012-03-14 15:08:25.709611806 +0000
@@ -27,6 +27,7 @@
  *   ldap_connect()             - Start new LDAP connection
  *   ldap_reconnect()           - Reconnect to LDAP Server
  *   ldap_disconnect()          - Disconnect from LDAP Server
+ *   cupsdStartAvahiClient()    - Start an Avahi client if needed
  *   cupsdStartBrowsing()       - Start sending and receiving broadcast
  *                                information.
  *   cupsdStartPolling()        - Start polling servers as needed.
@@ -40,11 +41,12 @@
  *   dequote()                  - Remote quotes from a string.
  *   dnssdAddAlias()            - Add a DNS-SD alias name.
  *   dnssdBuildTxtRecord()      - Build a TXT record from printer info.
- *   dnssdComparePrinters()     - Compare the registered names of two printers.
  *   dnssdDeregisterPrinter()   - Stop sending broadcast information for a
  *                                printer.
  *   dnssdPackTxtRecord()       - Pack an array of key/value pairs into the TXT
  *                                record format.
+ *   avahiPackTxtRecord()       - Pack an array of key/value pairs into an
+ *                                AvahiStringList.
  *   dnssdRegisterCallback()    - DNSServiceRegister callback.
  *   dnssdRegisterPrinter()     - Start sending broadcast information for a
  *                                printer or update the broadcast contents.
@@ -83,6 +85,7 @@
  */
 
 #include "cupsd.h"
+#include <assert.h>
 #include <grp.h>
 
 #ifdef HAVE_DNSSD
@@ -97,6 +100,17 @@
 #    endif /* HAVE_SYSTEMCONFIGURATION */
 #  endif /* __APPLE__ */
 #endif /* HAVE_DNSSD */
+#ifdef HAVE_AVAHI
+#  include <avahi-common/domain.h>
+#endif /* HAVE_AVAHI */
+
+
+#ifdef HAVE_DNSSD
+typedef char *cupsd_txt_record_t;
+#endif /* HAVE_DNSSD */
+#ifdef HAVE_AVAHI
+typedef AvahiStringList *cupsd_txt_record_t;
+#endif /* HAVE_AVAHI */
 
 
 /*
@@ -159,27 +173,38 @@ static void	update_polling(void);
 static void	update_smb(int onoff);
 
 
+#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
+static cupsd_txt_record_t dnssdBuildTxtRecord(int *txt_len, cupsd_printer_t *p,
+					      int for_lpd);
+static void	dnssdDeregisterPrinter(cupsd_printer_t *p);
+static void	dnssdRegisterPrinter(cupsd_printer_t *p);
+static void	dnssdStop(void);
+#endif /* defined(HAVE_DNSSD) || defined(HAVE_AVAHI) */
+
 #ifdef HAVE_DNSSD
 #  ifdef HAVE_COREFOUNDATION
 static void	dnssdAddAlias(const void *key, const void *value,
 		              void *context);
 #  endif /* HAVE_COREFOUNDATION */
-static char	*dnssdBuildTxtRecord(int *txt_len, cupsd_printer_t *p,
-		                     int for_lpd);
-static int	dnssdComparePrinters(cupsd_printer_t *a, cupsd_printer_t *b);
-static void	dnssdDeregisterPrinter(cupsd_printer_t *p);
-static char	*dnssdPackTxtRecord(int *txt_len, char *keyvalue[][2],
-		                    int count);
 static void	dnssdRegisterCallback(DNSServiceRef sdRef,
 		                      DNSServiceFlags flags,
 				      DNSServiceErrorType errorCode,
 				      const char *name, const char *regtype,
 				      const char *domain, void *context);
-static void	dnssdRegisterPrinter(cupsd_printer_t *p);
-static void	dnssdStop(void);
 static void	dnssdUpdate(void);
 #endif /* HAVE_DNSSD */
 
+#ifdef HAVE_AVAHI
+static AvahiStringList *avahiPackTxtRecord(char *keyvalue[][2],
+					   int count);
+static void	avahi_entry_group_cb (AvahiEntryGroup *group,
+				      AvahiEntryGroupState state,
+				      void *userdata);
+static void	avahi_client_cb (AvahiClient *client,
+				 AvahiClientState state,
+				 void *userdata);
+#endif /* HAVE_AVAHI */
+
 #ifdef HAVE_LDAP
 static const char * const ldap_attrs[] =/* CUPS LDAP attributes */
 		{
@@ -283,10 +308,10 @@ cupsdDeregisterPrinter(
     ldap_dereg_printer(p);
 #endif /* HAVE_LDAP */
 
-#ifdef HAVE_DNSSD
-  if (removeit && (BrowseLocalProtocols & BROWSE_DNSSD) && DNSSDRef)
+#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
+  if (removeit && (BrowseLocalProtocols & BROWSE_DNSSD))
     dnssdDeregisterPrinter(p);
-#endif /* HAVE_DNSSD */
+#endif /* defined(HAVE_DNSSD) || defined(HAVE_AVAHI) */
 }
 
 
@@ -702,10 +727,10 @@ cupsdRegisterPrinter(cupsd_printer_t *p)
     slpRegisterPrinter(p); */
 #endif /* HAVE_LIBSLP */
 
-#ifdef HAVE_DNSSD
-  if ((BrowseLocalProtocols & BROWSE_DNSSD) && DNSSDRef)
+#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
+  if ((BrowseLocalProtocols & BROWSE_DNSSD))
     dnssdRegisterPrinter(p);
-#endif /* HAVE_DNSSD */
+#endif /* defined(HAVE_DNSSD) || defined(HAVE_AVAHI) */
 }
 
 
@@ -1419,6 +1444,36 @@ ldap_disconnect(LDAP *ld)		/* I - LDAP h
 #endif /* HAVE_LDAP */
 
 
+#ifdef HAVE_AVAHI
+/*
+ * 'cupsdStartAvahiClient()' - Start an Avahi client if needed
+ */
+
+void
+cupsdStartAvahiClient(void)
+{
+  int error = 0;
+
+  if (!AvahiCupsClient && !AvahiCupsClientConnecting)
+  {
+    if (!AvahiCupsPollHandle)
+      AvahiCupsPollHandle = avahi_cups_poll_new ();
+
+    if (AvahiCupsPollHandle)
+    {
+      if (avahi_client_new (avahi_cups_poll_get (AvahiCupsPollHandle),
+			    AVAHI_CLIENT_NO_FAIL,
+			    avahi_client_cb, NULL,
+			    &error) != NULL)
+	AvahiCupsClientConnecting = 1;
+      else
+	cupsdLogMessage (CUPSD_LOG_WARN, "Avahi client failed: %d", error);
+    }
+  }
+}
+#endif /* HAVE_AVAHI */
+
+  
 /*
  * 'cupsdStartBrowsing()' - Start sending and receiving broadcast information.
  */
@@ -1542,13 +1597,16 @@ cupsdStartBrowsing(void)
   else
     BrowseSocket = -1;
 
-#ifdef HAVE_DNSSD
+#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
   if ((BrowseLocalProtocols | BrowseRemoteProtocols) & BROWSE_DNSSD)
   {
+#ifdef HAVE_DNSSD
     DNSServiceErrorType error;		/* Error from service creation */
+#endif /* HAVE_DNSSD */
     cupsd_listener_t	*lis;		/* Current listening socket */
 
 
+#ifdef HAVE_DNSSD
    /*
     * First create a "master" connection for all registrations...
     */
@@ -1573,6 +1631,7 @@ cupsdStartBrowsing(void)
       fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);
 
       cupsdAddSelect(fd, (cupsd_selfunc_t)dnssdUpdate, NULL, NULL);
+#endif /* HAVE_DNSSD */
 
      /*
       * Then get the port we use for registrations.  If we are not listening
@@ -1598,17 +1657,23 @@ cupsdStartBrowsing(void)
       */
 
       if (BrowseRemoteProtocols & BROWSE_DNSSD)
-        DNSSDPrinters = cupsArrayNew((cups_array_func_t)dnssdComparePrinters,
-	                             NULL);
+	  DNSSDPrinters = cupsArrayNew(NULL, NULL);
 
      /*
       * Set the computer name and register the web interface...
       */
 
       cupsdUpdateDNSSDName();
+
+#ifdef HAVE_AVAHI
+      cupsdStartAvahiClient ();
+#endif /* HAVE_AVAHI */
+
+#ifdef HAVE_DNSSD
     }
-  }
 #endif /* HAVE_DNSSD */
+  }
+#endif /* defined(HAVE_DNSSD) || defined(HAVE_AVAHI) */
 
 #ifdef HAVE_LIBSLP
   if ((BrowseLocalProtocols | BrowseRemoteProtocols) & BROWSE_SLP)
@@ -1834,10 +1899,10 @@ cupsdStopBrowsing(void)
     BrowseSocket = -1;
   }
 
-#ifdef HAVE_DNSSD
-  if ((BrowseLocalProtocols & BROWSE_DNSSD) && DNSSDRef)
+#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
+  if ((BrowseLocalProtocols & BROWSE_DNSSD))
     dnssdStop();
-#endif /* HAVE_DNSSD */
+#endif /* defined(HAVE_DNSSD) || defined(HAVE_AVAHI) */
 
 #ifdef HAVE_LIBSLP
   if (((BrowseLocalProtocols | BrowseRemoteProtocols) & BROWSE_SLP) &&
@@ -1902,7 +1967,7 @@ cupsdStopPolling(void)
 }
 
 
-#ifdef HAVE_DNSSD
+#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
 /*
  * 'cupsdUpdateDNSSDName()' - Update the computer name we use for browsing...
  */
@@ -1910,8 +1975,14 @@ cupsdStopPolling(void)
 void
 cupsdUpdateDNSSDName(void)
 {
+#ifdef HAVE_DNSSD
   DNSServiceErrorType error;		/* Error from service creation */
   char		webif[1024];		/* Web interface share name */
+#endif /* HAVE_DNSSD */
+#ifdef HAVE_AVAHI
+  int		ret;			/* Error from service creation */
+  char		webif[AVAHI_LABEL_MAX];	/* Web interface share name */
+#endif /* HAVE_AVAHI */
 #  ifdef HAVE_SYSTEMCONFIGURATION
   SCDynamicStoreRef sc;			/* Context for dynamic store */
   CFDictionaryRef btmm;			/* Back-to-My-Mac domains */
@@ -2042,6 +2113,7 @@ cupsdUpdateDNSSDName(void)
     else
       strlcpy(webif, "CUPS Web Interface", sizeof(webif));
 
+#ifdef HAVE_DNSSD
     if (WebIFRef)
       DNSServiceRefDeallocate(WebIFRef);
 
@@ -2054,9 +2126,45 @@ cupsdUpdateDNSSDName(void)
 				    NULL)) != kDNSServiceErr_NoError)
       cupsdLogMessage(CUPSD_LOG_ERROR,
 		      "DNS-SD web interface registration failed: %d", error);
+#endif /* HAVE_DNSSD */
+
+#ifdef HAVE_AVAHI
+    if (!AvahiCupsClient)
+     /*
+      * Client not yet running.
+      */
+      return;
+
+    if (AvahiWebIFGroup)
+      avahi_entry_group_reset (AvahiWebIFGroup);
+    else
+      AvahiWebIFGroup = avahi_entry_group_new (AvahiCupsClient,
+					       avahi_entry_group_cb,
+					       NULL);
+
+    if (AvahiWebIFGroup)
+    {
+      ret = avahi_entry_group_add_service (AvahiWebIFGroup,
+					   AVAHI_IF_UNSPEC,
+					   AVAHI_PROTO_UNSPEC,
+					   0, /* flags */
+					   webif, /* name */
+					   "_http._tcp", /* type */
+					   NULL, /* domain */
+					   NULL, /* host */
+					   DNSSDPort, /* port */
+					   "path=/", NULL);
+      if (ret == 0)
+	ret = avahi_entry_group_commit (AvahiWebIFGroup);
+
+      if (ret != 0)
+	cupsdLogMessage (CUPSD_LOG_ERROR,
+			 "Avahi web interface registration failed: %d", ret);
+    }
+#endif /* HAVE_AVAHI */
   }
 }
-#endif /* HAVE_DNSSD */
+#endif /* defined(HAVE_DNSSD) || defined(HAVE_AVAHI) */
 
 
 #ifdef HAVE_LDAP
@@ -2334,13 +2442,15 @@ dnssdAddAlias(const void *key,		/* I - K
                     "Bad Back to My Mac domain in dynamic store!");
 }
 #  endif /* HAVE_COREFOUNDATION */
+#endif /* HAVE_DNSSD */
 
 
+#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
 /*
  * 'dnssdBuildTxtRecord()' - Build a TXT record from printer info.
  */
 
-static char *				/* O - TXT record */
+static cupsd_txt_record_t		/* O - TXT record */
 dnssdBuildTxtRecord(
     int             *txt_len,		/* O - TXT record length */
     cupsd_printer_t *p,			/* I - Printer information */
@@ -2379,7 +2489,12 @@ dnssdBuildTxtRecord(
   keyvalue[i  ][0] = "ty";
   keyvalue[i++][1] = p->make_model ? p->make_model : "Unknown";
 
-  snprintf(admin_hostname, sizeof(admin_hostname), "%s.local.", DNSSDHostName);
+  snprintf(admin_hostname, sizeof(admin_hostname),
+	   "%s.local"
+#ifdef HAVE_DNSSD
+	   "." /* terminating dot no good for Avahi */
+#endif /* HAVE_DNSSD */
+	   , DNSSDHostName);
   httpAssembleURIf(HTTP_URI_CODING_ALL, adminurl_str, sizeof(adminurl_str),
                    "http", NULL, admin_hostname, DNSSDPort, "/%s/%s",
 		   (p->type & CUPS_PRINTER_CLASS) ? "classes" : "printers",
@@ -2462,19 +2577,12 @@ dnssdBuildTxtRecord(
   * Then pack them into a proper txt record...
   */
 
+#ifdef HAVE_DNSSD
   return (dnssdPackTxtRecord(txt_len, keyvalue, i));
-}
-
-
-/*
- * 'dnssdComparePrinters()' - Compare the registered names of two printers.
- */
-
-static int				/* O - Result of comparison */
-dnssdComparePrinters(cupsd_printer_t *a,/* I - First printer */
-                     cupsd_printer_t *b)/* I - Second printer */
-{
-  return (_cups_strcasecmp(a->reg_name, b->reg_name));
+#endif /* HAVE_DNSSD */
+#ifdef HAVE_AVAHI
+  return (avahiPackTxtRecord(keyvalue, i));
+#endif /* HAVE_AVAHI */
 }
 
 
@@ -2489,6 +2597,10 @@ dnssdDeregisterPrinter(
 {
   cupsdLogMessage(CUPSD_LOG_DEBUG2, "dnssdDeregisterPrinter(%s)", p->name);
 
+#ifdef HAVE_DNSSD
+  if (!DNSSDRef)
+    return;
+
  /*
   * Closing the socket deregisters the service
   */
@@ -2524,6 +2636,24 @@ dnssdDeregisterPrinter(
     free(p->printer_txt);
     p->printer_txt = NULL;
   }
+#endif /* HAVE_DNSSD */
+
+#ifdef HAVE_AVAHI
+  if (p->avahi_group)
+    {
+      avahi_entry_group_reset (p->avahi_group);
+      avahi_entry_group_free (p->avahi_group);
+      p->avahi_group = NULL;
+
+      if (p->ipp_txt)
+	avahi_string_list_free (p->ipp_txt);
+
+      if (p->printer_txt)
+	avahi_string_list_free (p->printer_txt);
+
+      p->ipp_txt = p->printer_txt = NULL;
+    }
+#endif /* HAVE_AVAHI */
 
  /*
   * Remove the printer from the array of DNS-SD printers, then clear the
@@ -2533,8 +2663,10 @@ dnssdDeregisterPrinter(
   cupsArrayRemove(DNSSDPrinters, p);
   cupsdClearString(&p->reg_name);
 }
+#endif /* defined(HAVE_DNSSD) || defined(HAVE_AVAHI) */
 
 
+#ifdef HAVE_DNSSD
 /*
  * 'dnssdPackTxtRecord()' - Pack an array of key/value pairs into the
  *                          TXT record format.
@@ -2644,8 +2776,10 @@ dnssdRegisterCallback(
     LastEvent |= CUPSD_EVENT_PRINTER_MODIFIED;
   }
 }
+#endif /* HAVE_DNSSD */
 
 
+#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
 /*
  * 'dnssdRegisterPrinter()' - Start sending broadcast information for a printer
  *		              or update the broadcast contents.
@@ -2654,20 +2788,40 @@ dnssdRegisterCallback(
 static void
 dnssdRegisterPrinter(cupsd_printer_t *p)/* I - Printer */
 {
+#ifdef HAVE_DNSSD
   DNSServiceErrorType	se;		/* dnssd errors */
   char			*ipp_txt,	/* IPP TXT record buffer */
 			*printer_txt,	/* LPD TXT record buffer */
-			name[1024],	/* Service name */
-			*nameptr;	/* Pointer into name */
+			name[1024];	/* Service name */
   int			ipp_len,	/* IPP TXT record length */
 			printer_len,	/* LPD TXT record length */
 			printer_port;	/* LPD port number */
+#endif /* HAVE_DNSSD */
+#ifdef HAVE_AVAHI
+  int			ret;		/* Error code */
+  AvahiStringList	*ipp_txt,	/* IPP TXT record */
+			*printer_txt;	/* LPD TXT record */
+  char			name[AVAHI_LABEL_MAX],	/* Service name */
+			fullsubtype[AVAHI_LABEL_MAX]; /* Full subtype */
+  char			*regtype_copy,	/* Writeable copy of reg type */
+			*subtype,	/* Current service sub type */
+			*nextsubtype;	/* Next service sub type */
+#endif /* HAVE_AVAHI */
+  char			*nameptr;	/* Pointer into name */
   const char		*regtype;	/* Registration type */
 
 
+#ifdef HAVE_DNSSD
+  if (!DNSSDRef)
+    return;
+
   cupsdLogMessage(CUPSD_LOG_DEBUG2, "dnssdRegisterPrinter(%s) %s", p->name,
                   !p->ipp_ref ? "new" : "update");
-
+#endif /* HAVE_DNSSD */
+#ifdef HAVE_AVAHI
+  cupsdLogMessage(CUPSD_LOG_DEBUG2, "dnssdRegisterPrinter(%s) %s", p->name,
+		  !p->avahi_group ? "new" : "update");
+#endif /* HAVE_AVAHI */
  /*
   * If per-printer sharing was just disabled make sure we're not
   * registered before returning.
@@ -2686,12 +2840,36 @@ dnssdRegisterPrinter(cupsd_printer_t *p)
   if (p->info && strlen(p->info) > 0)
   {
     if (DNSSDComputerName)
-      snprintf(name, sizeof(name), "%s @ %s", p->info, DNSSDComputerName);
+    {
+     /*
+      * Make sure there is room for at least 15 characters of
+      * DNSSDComputerName.
+      */
+
+      assert(sizeof(name) >= 15 + 4);
+      nameptr = name + strlcpy(name, p->info,
+			       sizeof(name) - 4 -
+			       strnlen(DNSSDComputerName, 15));
+      nameptr += strlcpy(nameptr, " @ ", sizeof(name) - (nameptr - name));
+      strlcpy(nameptr, DNSSDComputerName, sizeof(name) - (nameptr - name));
+    }
     else
       strlcpy(name, p->info, sizeof(name));
   }
   else if (DNSSDComputerName)
-    snprintf(name, sizeof(name), "%s @ %s", p->name, DNSSDComputerName);
+  {
+   /*
+    * Make sure there is room for at least 15 characters of
+    * DNSSDComputerName.
+    */
+
+    assert(sizeof(name) >= 15 + 4);
+    nameptr = name + strlcpy(name, p->info,
+			     sizeof(name) - 4 -
+			     strnlen(DNSSDComputerName, 15));
+    nameptr += strlcpy(nameptr, " @ ", sizeof(name) - (nameptr - name));
+    strlcpy(nameptr, DNSSDComputerName, sizeof(name) - (nameptr - name));
+  }
   else
     strlcpy(name, p->name, sizeof(name));
 
@@ -2712,6 +2890,7 @@ dnssdRegisterPrinter(cupsd_printer_t *p)
   * Register IPP and (optionally) LPD...
   */
 
+#ifdef HAVE_DNSSD
   ipp_len = 0;				/* anti-compiler-warning-code */
   ipp_txt = dnssdBuildTxtRecord(&ipp_len, p, 0);
 
@@ -2884,6 +3063,209 @@ dnssdRegisterPrinter(cupsd_printer_t *p)
 
   if (printer_txt)
     free(printer_txt);
+#endif /* HAVE_DNSSD */
+#ifdef HAVE_AVAHI
+  if (!AvahiCupsClient)
+   /*
+    * Client not running yet.  The client callback will call us again later.
+    */
+    return;
+
+  ipp_txt = dnssdBuildTxtRecord(NULL, p, 0);
+  printer_txt = dnssdBuildTxtRecord(NULL, p, 1);
+  regtype = (p->type & CUPS_PRINTER_FAX) ? "_fax-ipp._tcp" : DNSSDRegType;
+
+  if (p->avahi_group && p->ipp_txt && ipp_txt &&
+      !avahi_string_list_equal (p->ipp_txt, ipp_txt))
+  {
+   /*
+    * Update the existing registration...
+    */
+
+    avahi_string_list_free (p->ipp_txt);
+
+    if (p->printer_txt)
+      avahi_string_list_free (p->printer_txt);
+
+   /*
+    * Update the service group entry.
+    */
+
+    regtype_copy = strdup (regtype);
+    subtype = strchr (regtype_copy, ',');
+    if (subtype)
+      *subtype = '\0';
+
+    cupsdLogMessage (CUPSD_LOG_DEBUG,
+		     "Updating TXT record for %s (%s)", name, regtype_copy);
+    ret = avahi_entry_group_update_service_txt_strlst (p->avahi_group,
+						       AVAHI_IF_UNSPEC,
+						       AVAHI_PROTO_UNSPEC,
+						       0, name,
+						       regtype_copy,
+						       NULL, ipp_txt);
+    free (regtype_copy);
+
+    if (ret < 0)
+      goto update_failed;
+
+    p->ipp_txt = ipp_txt;
+    ipp_txt = NULL;
+
+    if (BrowseLocalProtocols & BROWSE_LPD)
+    {
+      ret = avahi_entry_group_update_service_txt_strlst (p->avahi_group,
+							 AVAHI_IF_UNSPEC,
+							 AVAHI_PROTO_UNSPEC,
+							 0, name,
+							 "_printer._tcp", NULL,
+							 printer_txt);
+      if (ret < 0)
+	goto update_failed;
+
+      p->printer_txt = printer_txt;
+      printer_txt = NULL;
+    }
+
+    ret = avahi_entry_group_commit (p->avahi_group);
+    if (ret < 0)
+    {
+    update_failed:
+      cupsdLogMessage (CUPSD_LOG_ERROR,
+		       "Failed to update TXT record for %s: %d",
+		       name, ret);
+      avahi_entry_group_reset (p->avahi_group);
+      avahi_entry_group_free (p->avahi_group);
+      p->avahi_group = NULL;
+      ipp_txt = p->ipp_txt;
+      p->ipp_txt = NULL;
+    }
+  }
+
+  if (!p->avahi_group)
+  {
+   /*
+    * Initial registration.  Use the _fax subtype for fax queues...
+    */
+
+    p->avahi_group = avahi_entry_group_new (AvahiCupsClient,
+					    avahi_entry_group_cb,
+					    p);
+
+    cupsdLogMessage(CUPSD_LOG_DEBUG,
+		    "Registering Avahi printer %s with name \"%s\" and "
+		    "type \"%s\"", p->name, name, regtype);
+
+    if (!p->avahi_group)
+    {
+      ret = 0;
+      goto add_failed;
+    }
+
+   /*
+    * Add each service type (DNSSDRegType may contain several,
+    * separated by commas).
+    */
+
+    subtype = regtype_copy = strdup (regtype);
+    while (subtype && *subtype)
+    {
+      nextsubtype = strchr (subtype, ',');
+      if (nextsubtype)
+	*nextsubtype++ = '\0';
+
+      if (subtype == regtype_copy)
+      {
+       /*
+	* Main type entry.
+	*/
+
+	cupsdLogMessage (CUPSD_LOG_DEBUG,
+			 "Adding TXT record for %s (%s)", name, regtype_copy);
+	ret = avahi_entry_group_add_service_strlst (p->avahi_group,
+						    AVAHI_IF_UNSPEC,
+						    AVAHI_PROTO_UNSPEC,
+						    0, name, regtype_copy,
+						    NULL, NULL,
+						    DNSSDPort,
+						    ipp_txt);
+      }
+      else
+      {
+       /*
+	* Sub-type entry.
+	*/
+
+	snprintf (fullsubtype, sizeof(fullsubtype),
+		  "%s._sub.%s", subtype, regtype_copy);
+	cupsdLogMessage (CUPSD_LOG_DEBUG,
+			 "Adding TXT record for %s (%s)", name, fullsubtype);
+	ret = avahi_entry_group_add_service_subtype (p->avahi_group,
+						     AVAHI_IF_UNSPEC,
+						     AVAHI_PROTO_UNSPEC,
+						     0, name,
+						     regtype_copy,
+						     NULL, fullsubtype);
+      }
+
+      if (ret < 0)
+      {
+	free (regtype_copy);
+	goto add_failed;
+      }
+
+      subtype = nextsubtype;
+    }
+
+    free (regtype_copy);
+    p->ipp_txt = ipp_txt;
+    ipp_txt = NULL;
+
+    if (BrowseLocalProtocols & BROWSE_LPD)
+    {
+      cupsdLogMessage(CUPSD_LOG_DEBUG,
+		      "Registering Avahi printer %s with name \"%s\" and "
+		      "type \"_printer._tcp\"", p->name, name);
+
+      ret = avahi_entry_group_add_service_strlst (p->avahi_group,
+						  AVAHI_IF_UNSPEC,
+						  AVAHI_PROTO_UNSPEC,
+						  0, name,
+						  "_printer._tcp", NULL, NULL,
+						  515,
+						  printer_txt);
+      if (ret < 0)
+	goto add_failed;
+
+      p->printer_txt = printer_txt;
+      printer_txt = NULL;
+    }
+
+    ret = avahi_entry_group_commit (p->avahi_group);
+
+    if (ret < 0)
+    {
+    add_failed:
+      cupsdLogMessage (CUPSD_LOG_ERROR,
+		       "Failed to add Avahi entry for %s: %d",
+		       name, ret);
+      if (p->avahi_group)
+      {
+	avahi_entry_group_reset (p->avahi_group);
+	avahi_entry_group_free (p->avahi_group);
+	p->avahi_group = NULL;
+      }
+      ipp_txt = p->ipp_txt;
+      p->ipp_txt = NULL;
+    }
+  }
+
+  if (ipp_txt)
+    avahi_string_list_free (ipp_txt);
+
+  if (printer_txt)
+    avahi_string_list_free (printer_txt);
+#endif /* HAVE_AVAHI */
 }
 
 
@@ -2896,6 +3278,10 @@ dnssdStop(void)
 {
   cupsd_printer_t	*p;		/* Current printer */
 
+#ifdef HAVE_DNSSD
+  if (!DNSSDRef)
+    return;
+#endif /* HAVE_DNSSD */
 
  /*
   * De-register the individual printers
@@ -2910,12 +3296,23 @@ dnssdStop(void)
   * Shutdown the rest of the service refs...
   */
 
+#ifdef HAVE_DNSSD
   if (WebIFRef)
   {
     DNSServiceRefDeallocate(WebIFRef);
     WebIFRef = NULL;
   }
+#endif /* HAVE_DNSSD */
+#ifdef HAVE_AVAHI
+  if (AvahiWebIFGroup)
+  {
+    avahi_entry_group_reset (AvahiWebIFGroup);
+    avahi_entry_group_free (AvahiWebIFGroup);
+    AvahiWebIFGroup = NULL;
+  }
+#endif /* HAVE_AVAHI */
 
+#ifdef HAVE_DNSSD
   if (RemoteRef)
   {
     DNSServiceRefDeallocate(RemoteRef);
@@ -2926,14 +3323,17 @@ dnssdStop(void)
 
   DNSServiceRefDeallocate(DNSSDRef);
   DNSSDRef = NULL;
+#endif /* HAVE_DNSSD */
 
   cupsArrayDelete(DNSSDPrinters);
   DNSSDPrinters = NULL;
 
   DNSSDPort = 0;
 }
+#endif /* defined(HAVE_DNSSD) || defined(HAVE_AVAHI) */
 
 
+#ifdef HAVE_DNSSD
 /*
  * 'dnssdUpdate()' - Handle DNS-SD queries.
  */
@@ -2955,6 +3355,153 @@ dnssdUpdate(void)
 #endif /* HAVE_DNSSD */
 
 
+#ifdef HAVE_AVAHI
+/*
+ * 'avahiPackTxtRecord()' - Pack an array of key/value pairs into an
+ *                          AvahiStringList.
+ */
+
+static AvahiStringList *		/* O - new string list */
+avahiPackTxtRecord(char *keyvalue[][2],	/* I - Table of key value pairs */
+		   int count)		/* I - Number of items in table */
+{
+  AvahiStringList *strlst = NULL;
+  char **elements;
+  size_t len;
+  int i = 0;
+
+  elements = malloc ((1 + count) * sizeof (char *));
+  if (!elements)
+    goto cleanup;
+
+  for (i = 0; i < count; i++)
+    {
+      len = (1 + strlen (keyvalue[i][0]) +
+	     (keyvalue[i][1] ? 1 + strlen (keyvalue[i][1]) : 1));
+      elements[i] = malloc (len * sizeof (char));
+      if (!elements[i])
+	goto cleanup;
+
+      snprintf (elements[i], len, "%s=%s", keyvalue[i][0], keyvalue[i][1]);
+    }
+
+  strlst = avahi_string_list_new_from_array ((const char **) elements, count);
+
+cleanup:
+  while (--i >= 0)
+    free (elements[i]);
+
+  free (elements);
+  return (strlst);
+}
+
+
+/*
+ * 'avahi_entry_group_cb()' - Avahi entry group callback function.
+ */
+static void
+avahi_entry_group_cb (AvahiEntryGroup *group,
+		      AvahiEntryGroupState state,
+		      void *userdata)
+{
+  char *name;
+
+  if (userdata)
+    name = ((cupsd_printer_t *) userdata)->reg_name;
+  else
+    name = "CUPS web interface";
+
+  switch (state)
+  {
+  case AVAHI_ENTRY_GROUP_UNCOMMITED:
+  case AVAHI_ENTRY_GROUP_REGISTERING:
+    break;
+
+  case AVAHI_ENTRY_GROUP_ESTABLISHED:
+    cupsdLogMessage (CUPSD_LOG_DEBUG,
+		     "Avahi entry group established for %s", name);
+    break;
+
+  default:
+    cupsdLogMessage (CUPSD_LOG_DEBUG,
+		     "Avahi entry group %s has state %d",
+		     name, state);
+    break;
+  }
+}
+
+
+/*
+ * 'avahi_client_cb()' - Avahi client callback function.
+ */
+static void
+avahi_client_cb (AvahiClient *client,
+		 AvahiClientState state,
+		 void *userdata)
+{
+  cupsd_printer_t *printer;
+  switch (state)
+  {
+  case AVAHI_CLIENT_S_RUNNING:
+   /*
+    * Avahi client started successfully.
+    */
+    AvahiCupsClient = client;
+    AvahiCupsClientConnecting = 0;
+    cupsdLogMessage (CUPSD_LOG_DEBUG, "Avahi client started");
+
+    cupsdUpdateDNSSDName ();
+
+    for (printer = (cupsd_printer_t *)cupsArrayFirst(Printers);
+	 printer;
+	 printer = (cupsd_printer_t *)cupsArrayNext(Printers))
+      if (Browsing && (BrowseLocalProtocols & BROWSE_DNSSD) &&
+	  (!(printer->type & (CUPS_PRINTER_REMOTE | CUPS_PRINTER_IMPLICIT |
+			      CUPS_PRINTER_SCANNER))) && printer->shared)
+	dnssdRegisterPrinter (printer);
+
+    break;
+
+  case AVAHI_CLIENT_CONNECTING:
+   /*
+    * No Avahi daemon, client is waiting.
+    */
+    cupsdLogMessage (CUPSD_LOG_DEBUG, "Avahi client connecting");
+    break;
+
+  case AVAHI_CLIENT_S_REGISTERING:
+    /*
+     * Not yet registered.
+     */
+    cupsdLogMessage (CUPSD_LOG_DEBUG, "Avahi client registering");
+    break;
+
+  case AVAHI_CLIENT_FAILURE:
+   /*
+    * Avahi client failed, close it to allow a clean restart.
+    */
+    cupsdLogMessage (CUPSD_LOG_ERROR,
+		     "Avahi client failed, "
+		     "closing client to allow a clean restart");
+
+    for (printer = (cupsd_printer_t *)cupsArrayFirst(Printers);
+	 printer;
+	 printer = (cupsd_printer_t *)cupsArrayNext(Printers))
+      dnssdDeregisterPrinter (printer);
+
+    avahi_client_free(client);
+    AvahiCupsClientConnecting = 0;
+    AvahiCupsClient = NULL;
+
+    break;
+
+  default:
+    cupsdLogMessage (CUPSD_LOG_DEBUG, "Avahi client state: %d", state);
+  }
+}
+#endif /* HAVE_AVAHI */
+
+
 /*
  * 'get_auth_info_required()' - Get the auth-info-required value to advertise.
  */
diff -up cups-1.5.2/scheduler/dirsvc.h.avahi-5-services cups-1.5.2/scheduler/dirsvc.h
--- cups-1.5.2/scheduler/dirsvc.h.avahi-5-services	2011-03-21 02:12:14.000000000 +0000
+++ cups-1.5.2/scheduler/dirsvc.h	2012-03-14 15:08:25.711611808 +0000
@@ -31,6 +31,10 @@
 #  endif /* HAVE_LDAP_SSL_H */
 #endif /* HAVE_LDAP */
 
+#ifdef HAVE_AVAHI
+#  include <avahi-client/publish.h>
+#endif /* HAVE_AVAHI */
+
 /*
  * Browse protocols...
  */
@@ -131,19 +135,22 @@ VAR int			PollPipe	VALUE(0);
 VAR cupsd_statbuf_t	*PollStatusBuffer VALUE(NULL);
 					/* Status buffer for pollers */
 
-#ifdef HAVE_DNSSD
+#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
 VAR char		*DNSSDComputerName VALUE(NULL),
 					/* Computer/server name */
 			*DNSSDHostName	VALUE(NULL),
 					/* Hostname */
 			*DNSSDRegType VALUE(NULL);
 					/* Bonjour registration type */
-VAR cups_array_t	*DNSSDAlias	VALUE(NULL);
-					/* List of dynamic ServerAlias's */
 VAR int			DNSSDPort	VALUE(0);
 					/* Port number to register */
 VAR cups_array_t	*DNSSDPrinters	VALUE(NULL);
 					/* Printers we have registered */
+#endif /* defined(HAVE_DNSSD) || defined(HAVE_AVAHI) */
+
+#ifdef HAVE_DNSSD
+VAR cups_array_t	*DNSSDAlias	VALUE(NULL);
+					/* List of dynamic ServerAlias's */
 VAR DNSServiceRef	DNSSDRef	VALUE(NULL),
 					/* Master DNS-SD service reference */
 			WebIFRef	VALUE(NULL),
@@ -152,6 +159,17 @@ VAR DNSServiceRef	DNSSDRef	VALUE(NULL),
 					/* Remote printer browse reference */
 #endif /* HAVE_DNSSD */
 
+#ifdef HAVE_AVAHI
+VAR AvahiCupsPoll	*AvahiCupsPollHandle	VALUE(NULL);
+					/* AvahiCupsPoll object */
+VAR AvahiClient		*AvahiCupsClient	VALUE(NULL);
+					/* AvahiClient object */
+VAR int			AvahiCupsClientConnecting	VALUE(0);
+					/* Is AvahiClient object connecting? */
+VAR AvahiEntryGroup	*AvahiWebIFGroup	VALUE(NULL);
+					/* Web interface entry group */
+#endif /* HAVE_AVAHI */
+
 #ifdef HAVE_LIBSLP
 VAR SLPHandle		BrowseSLPHandle	VALUE(NULL);
 					/* SLP API handle */
@@ -195,13 +213,14 @@ extern void	cupsdRegisterPrinter(cupsd_p
 extern void	cupsdRestartPolling(void);
 extern void	cupsdSaveRemoteCache(void);
 extern void	cupsdSendBrowseList(void);
+extern void	cupsdStartAvahiClient(void);
 extern void	cupsdStartBrowsing(void);
 extern void	cupsdStartPolling(void);
 extern void	cupsdStopBrowsing(void);
 extern void	cupsdStopPolling(void);
-#ifdef HAVE_DNSSD
+#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
 extern void	cupsdUpdateDNSSDName(void);
-#endif /* HAVE_DNSSD */
+#endif /* defined(HAVE_DNSSD) || defined(HAVE_AVAHI) */
 #ifdef HAVE_LDAP
 extern void	cupsdUpdateLDAPBrowse(void);
 #endif /* HAVE_LDAP */
diff -up cups-1.5.2/scheduler/ipp.c.avahi-5-services cups-1.5.2/scheduler/ipp.c
--- cups-1.5.2/scheduler/ipp.c.avahi-5-services	2012-03-14 15:04:17.665305560 +0000
+++ cups-1.5.2/scheduler/ipp.c	2012-03-14 15:08:25.715611813 +0000
@@ -6099,7 +6099,7 @@ copy_printer_attrs(
     ippAddDate(con->response, IPP_TAG_PRINTER, "printer-current-time",
                ippTimeToDate(curtime));
 
-#ifdef HAVE_DNSSD
+#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
   if (!ra || cupsArrayFind(ra, "printer-dns-sd-name"))
   {
     if (printer->reg_name)
@@ -6109,7 +6109,7 @@ copy_printer_attrs(
       ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_NOVALUE,
                    "printer-dns-sd-name", 0);
   }
-#endif /* HAVE_DNSSD */
+#endif /* defined(HAVE_DNSSD) || defined(HAVE_AVAHI) */
 
   if (!ra || cupsArrayFind(ra, "printer-error-policy"))
     ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_NAME,
diff -up cups-1.5.2/scheduler/main.c.avahi-5-services cups-1.5.2/scheduler/main.c
--- cups-1.5.2/scheduler/main.c.avahi-5-services	2012-03-14 15:06:36.511476986 +0000
+++ cups-1.5.2/scheduler/main.c	2012-03-14 15:08:25.718611817 +0000
@@ -120,6 +120,10 @@ main(int  argc,				/* I - Number of comm
   cupsd_listener_t	*lis;		/* Current listener */
   time_t		current_time,	/* Current time */
 			activity,	/* Client activity timer */
+#ifdef HAVE_AVAHI
+			avahi_client_time, /* Time for next Avahi client
+					      check */
+#endif /* HAVE_AVAHI */
 			browse_time,	/* Next browse send time */
 			senddoc_time,	/* Send-Document time */
 			expire_time,	/* Subscription expire time */
@@ -672,6 +676,9 @@ main(int  argc,				/* I - Number of comm
   */
 
   current_time  = time(NULL);
+#ifdef HAVE_AVAHI
+  avahi_client_time = current_time;
+#endif /* HAVE_AVAHI */
   browse_time   = current_time;
   event_time    = current_time;
   expire_time   = current_time;
@@ -894,6 +901,16 @@ main(int  argc,				/* I - Number of comm
     tmo = cupsdNextTimeout (&tmo_delay);
     if (tmo && tmo_delay == 0)
       cupsdRunTimeout (tmo);
+
+   /*
+    * Try to restart the Avahi client every 10 seconds if needed...
+    */
+
+    if ((current_time - avahi_client_time) >= 10)
+    {
+      avahi_client_time = current_time;
+      cupsdStartAvahiClient();
+    }
 #endif /* HAVE_AVAHI */
 
 #ifndef __APPLE__
diff -up cups-1.5.2/scheduler/printers.c.avahi-5-services cups-1.5.2/scheduler/printers.c
--- cups-1.5.2/scheduler/printers.c.avahi-5-services	2012-03-14 15:04:17.646305537 +0000
+++ cups-1.5.2/scheduler/printers.c	2012-03-14 15:08:25.720611819 +0000
@@ -883,9 +883,9 @@ cupsdDeletePrinter(
   cupsdClearString(&p->alert);
   cupsdClearString(&p->alert_description);
 
-#ifdef HAVE_DNSSD
+#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
   cupsdClearString(&p->pdl);
-#endif /* HAVE_DNSSD */
+#endif /* defined(HAVE_DNSSD) || defined(HAVE_AVAHI) */
 
   cupsArrayDelete(p->filetypes);
 
@@ -3787,7 +3787,7 @@ add_printer_formats(cupsd_printer_t *p)
     attr->values[i].string.text = _cupsStrAlloc(mimetype);
   }
 
-#ifdef HAVE_DNSSD
+#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
   {
     char		pdl[1024];	/* Buffer to build pdl list */
     mime_filter_t	*filter;	/* MIME filter looping var */
@@ -3843,7 +3843,7 @@ add_printer_formats(cupsd_printer_t *p)
 
     cupsdSetString(&p->pdl, pdl);
   }
-#endif /* HAVE_DNSSD */
+#endif /* defined(HAVE_DNSSD) || defined(HAVE_AVAHI) */
 }
 
 
diff -up cups-1.5.2/scheduler/printers.h.avahi-5-services cups-1.5.2/scheduler/printers.h
--- cups-1.5.2/scheduler/printers.h.avahi-5-services	2011-03-18 18:42:46.000000000 +0000
+++ cups-1.5.2/scheduler/printers.h	2012-03-14 15:08:25.721611820 +0000
@@ -16,6 +16,9 @@
 #ifdef HAVE_DNSSD
 #  include <dns_sd.h>
 #endif /* HAVE_DNSSD */
+#ifdef HAVE_AVAHI
+#  include "avahi.h"
+#endif /* HAVE_AVAHI */
 #include <cups/pwg-private.h>
 
 
@@ -95,16 +98,23 @@ struct cupsd_printer_s
   time_t	marker_time;		/* Last time marker attributes were updated */
   _ppd_cache_t	*pc;			/* PPD cache and mapping data */
 
-#ifdef HAVE_DNSSD
+#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
   char		*reg_name,		/* Name used for service registration */
-		*pdl,			/* pdl value for TXT record */
-		*ipp_txt,		/* IPP TXT record contents */
+		*pdl;			/* pdl value for TXT record */
+#endif /* defined(HAVE_DNSSD) || defined(HAVE_AVAHI) */
+#ifdef HAVE_DNSSD
+  char		*ipp_txt,		/* IPP TXT record contents */
 		*printer_txt;		/* LPD TXT record contents */
   int		ipp_len,		/* IPP TXT record length */
 		printer_len;		/* LPD TXT record length */
   DNSServiceRef	ipp_ref,		/* Reference for _ipp._tcp,_cups */
 		printer_ref;		/* Reference for _printer._tcp */
 #endif /* HAVE_DNSSD */
+#ifdef HAVE_AVAHI
+  AvahiStringList *ipp_txt,		/* IPP TXT record */
+		*printer_txt;		/* LPD TXT record */
+  AvahiEntryGroup *avahi_group;		/* Avahi entry group */
+#endif /* HAVE_AVAHI */
 };