Skip to content

Commit 28c75c5

Browse files
Merge pull request #123 from deepak0405/master
cups-browsed: Recreate cluster's PPD file on addition/deletion of printers
2 parents 7d4666d + aed4871 commit 28c75c5

File tree

1 file changed

+82
-20
lines changed

1 file changed

+82
-20
lines changed

utils/cups-browsed.c

+82-20
Original file line numberDiff line numberDiff line change
@@ -1255,6 +1255,9 @@ void add_mimetype_attributes(char* cluster_name, ipp_t **merged_attributes)
12551255
p; p = (remote_printer_t *)cupsArrayNext(remote_printers)) {
12561256
if (strcmp(cluster_name,p->queue_name))
12571257
continue;
1258+
if(p->status == STATUS_DISAPPEARED || p->status == STATUS_UNCONFIRMED ||
1259+
p->status == STATUS_TO_BE_RELEASED )
1260+
continue;
12581261
if ((attr = ippFindAttribute(p->prattrs,attributes[attr_no], IPP_TAG_MIMETYPE)) != NULL) {
12591262
count = ippGetCount(attr);
12601263
for (i = 0; i < count; i ++) {
@@ -1314,6 +1317,9 @@ void add_tagzero_attributes(char* cluster_name,ipp_t **merged_attributes)
13141317
p; p = (remote_printer_t *)cupsArrayNext(remote_printers)) {
13151318
if (strcmp(cluster_name,p->queue_name))
13161319
continue;
1320+
if(p->status == STATUS_DISAPPEARED || p->status == STATUS_UNCONFIRMED ||
1321+
p->status == STATUS_TO_BE_RELEASED )
1322+
continue;
13171323
if ((attr = ippFindAttribute(p->prattrs,attributes[attr_no], IPP_TAG_ZERO)) != NULL) {
13181324
count = ippGetCount(attr);
13191325
for(i = 0; i < count; i ++) {
@@ -1375,6 +1381,9 @@ void add_keyword_attributes(char* cluster_name,ipp_t **merged_attributes)
13751381
p; p = (remote_printer_t *)cupsArrayNext(remote_printers)) {
13761382
if (strcmp(cluster_name,p->queue_name))
13771383
continue;
1384+
if(p->status == STATUS_DISAPPEARED || p->status == STATUS_UNCONFIRMED ||
1385+
p->status == STATUS_TO_BE_RELEASED )
1386+
continue;
13781387
if ((attr = ippFindAttribute(p->prattrs,attributes[attr_no], IPP_TAG_KEYWORD)) != NULL) {
13791388
count = ippGetCount(attr);
13801389
for (i = 0; i < count; i++) {
@@ -1431,6 +1440,9 @@ void add_enum_attributes(char* cluster_name,ipp_t **merged_attributes)
14311440
p; p = (remote_printer_t *)cupsArrayNext(remote_printers)) {
14321441
if (strcmp(cluster_name,p->queue_name))
14331442
continue;
1443+
if(p->status == STATUS_DISAPPEARED || p->status == STATUS_UNCONFIRMED ||
1444+
p->status == STATUS_TO_BE_RELEASED )
1445+
continue;
14341446
if ((attr = ippFindAttribute(p->prattrs,attributes[attr_no], IPP_TAG_ENUM)) != NULL) {
14351447
count = ippGetCount(attr);
14361448
for (i = 0; i < count; i ++) {
@@ -1485,6 +1497,9 @@ void add_margin_attributes(char* cluster_name,ipp_t **merged_attributes)
14851497
p; p = (remote_printer_t *)cupsArrayNext(remote_printers)) {
14861498
if (strcmp(cluster_name,p->queue_name))
14871499
continue;
1500+
if(p->status == STATUS_DISAPPEARED || p->status == STATUS_UNCONFIRMED ||
1501+
p->status == STATUS_TO_BE_RELEASED )
1502+
continue;
14881503
if ((attr = ippFindAttribute(p->prattrs,attributes[attr_no], IPP_TAG_INTEGER)) != NULL) {
14891504
count = ippGetCount(attr);
14901505
for (i = 0; i < count; i++) {
@@ -1535,6 +1550,9 @@ void add_resolution_attributes(char* cluster_name, ipp_t **merged_attributes)
15351550
p; p = (remote_printer_t *)cupsArrayNext(remote_printers)) {
15361551
if (strcmp(cluster_name,p->queue_name))
15371552
continue;
1553+
if(p->status == STATUS_DISAPPEARED || p->status == STATUS_UNCONFIRMED ||
1554+
p->status == STATUS_TO_BE_RELEASED )
1555+
continue;
15381556
if ((attr = ippFindAttribute(p->prattrs,attributes[attr_no], IPP_TAG_RESOLUTION)) != NULL){
15391557
for (i = 0, count = ippGetCount(attr); i < count; i ++) {
15401558
if ((res = ippResolutionToRes(attr, i)) != NULL &&
@@ -1590,6 +1608,9 @@ void add_mediasize_attributes(char* cluster_name, ipp_t **merged_attributes)
15901608
p; p = (remote_printer_t *)cupsArrayNext(remote_printers)) {
15911609
if (strcmp(cluster_name,p->queue_name))
15921610
continue;
1611+
if(p->status == STATUS_DISAPPEARED || p->status == STATUS_UNCONFIRMED ||
1612+
p->status == STATUS_TO_BE_RELEASED )
1613+
continue;
15931614
if ((attr = ippFindAttribute(p->prattrs, attributes[attr_no],
15941615
IPP_TAG_BEGIN_COLLECTION)) != NULL) {
15951616
for (i = 0, count = ippGetCount(attr); i < count; i ++) {
@@ -1682,6 +1703,9 @@ add_mediadatabase_attributes(char* cluster_name, ipp_t **merged_attributes)
16821703
p; p = (remote_printer_t *)cupsArrayNext(remote_printers)) {
16831704
if (strcmp(cluster_name,p->queue_name))
16841705
continue;
1706+
if(p->status == STATUS_DISAPPEARED || p->status == STATUS_UNCONFIRMED ||
1707+
p->status == STATUS_TO_BE_RELEASED )
1708+
continue;
16851709
if ((attr = ippFindAttribute(p->prattrs,attributes[attr_no],
16861710
IPP_TAG_BEGIN_COLLECTION)) != NULL){
16871711
for (i = 0, count = ippGetCount(attr); i < count; i ++) {
@@ -1794,6 +1818,9 @@ void add_jobpresets_attribute(char* cluster_name, ipp_t ** merged_attributes)
17941818
p; p = (remote_printer_t *)cupsArrayNext(remote_printers)) {
17951819
if (strcmp(cluster_name,p->queue_name))
17961820
continue;
1821+
if(p->status == STATUS_DISAPPEARED || p->status == STATUS_UNCONFIRMED ||
1822+
p->status == STATUS_TO_BE_RELEASED )
1823+
continue;
17971824
if ((attr = ippFindAttribute(p->prattrs, "job-presets-supported",
17981825
IPP_TAG_BEGIN_COLLECTION)) != NULL) {
17991826
for (i = 0, count = ippGetCount(attr); i < count; i ++) {
@@ -2447,6 +2474,9 @@ cups_array_t* get_cluster_sizes(char* cluster_name)
24472474
for (p = (remote_printer_t *)cupsArrayFirst(remote_printers);
24482475
p; p = (remote_printer_t *)cupsArrayNext(remote_printers)) {
24492476
if (!strcmp(p->queue_name,cluster_name)) {
2477+
if(p->status == STATUS_DISAPPEARED || p->status == STATUS_UNCONFIRMED ||
2478+
p->status == STATUS_TO_BE_RELEASED )
2479+
continue;
24502480
defattr = NULL;
24512481
min_length = INT_MAX;
24522482
min_width = INT_MAX;
@@ -2539,6 +2569,9 @@ cups_array_t* generate_cluster_conflicts(char* cluster_name,
25392569
p = (remote_printer_t *)cupsArrayIndex(remote_printers, j);
25402570
if (strcmp(cluster_name,p->queue_name))
25412571
continue;
2572+
if(p->status == STATUS_DISAPPEARED || p->status == STATUS_UNCONFIRMED ||
2573+
p->status == STATUS_TO_BE_RELEASED )
2574+
continue;
25422575
for (i = 0; i < no_of_ppd_keywords; i ++) {
25432576
printer_first_options =
25442577
get_supported_options(p->prattrs, ppd_keywords[i]);
@@ -2589,15 +2622,18 @@ ipp_t* get_cluster_attributes(char* cluster_name)
25892622
{
25902623
remote_printer_t *p;
25912624
ipp_t *merged_attributes = NULL;
2592-
char printer_make_and_model[256], buffer[1024*30];
2625+
char printer_make_and_model[256];
25932626
ipp_attribute_t *attr;
2594-
int color_supported=0,make_model_done = 0;
2595-
2627+
int color_supported=0,make_model_done = 0,i;
2628+
char valuebuffer[65536];
25962629
merged_attributes = ippNew();
25972630
for (p = (remote_printer_t *)cupsArrayFirst(remote_printers);
25982631
p; p = (remote_printer_t *)cupsArrayNext(remote_printers)) {
25992632
if (strcmp(cluster_name,p->queue_name))
26002633
continue;
2634+
if(p->status == STATUS_DISAPPEARED || p->status == STATUS_UNCONFIRMED ||
2635+
p->status == STATUS_TO_BE_RELEASED )
2636+
continue;
26012637
if (!make_model_done) {
26022638
strcpy(printer_make_and_model, "Cluster ");
26032639
strcat(printer_make_and_model, cluster_name);
@@ -2626,12 +2662,18 @@ ipp_t* get_cluster_attributes(char* cluster_name)
26262662
add_jobpresets_attribute(cluster_name, &merged_attributes);
26272663
attr = ippFirstAttribute(merged_attributes);
26282664
/* Printing merged attributes*/
2629-
debug_printf("Merged attributes for the cluster %s", cluster_name);
2630-
while(attr) {
2631-
ippAttributeString(attr, buffer, sizeof(buffer));
2632-
debug_printf("%s,%s\n", ippGetName(attr), buffer);
2633-
attr = ippNextAttribute(merged_attributes);
2634-
}
2665+
debug_printf("Merged attributes for the cluster %s : \n", cluster_name);
2666+
while (attr) {
2667+
debug_printf(" Attr: %s\n",
2668+
ippGetName(attr));
2669+
ippAttributeString(attr, valuebuffer, sizeof(valuebuffer));
2670+
debug_printf(" Value: %s\n", valuebuffer);
2671+
const char *kw;
2672+
for (i = 0; i < ippGetCount(attr); i ++)
2673+
if ((kw = ippGetString(attr, i, NULL)) != NULL)
2674+
debug_printf(" Keyword: %s\n", kw);
2675+
attr = ippNextAttribute(merged_attributes);
2676+
}
26352677
return merged_attributes;
26362678
}
26372679

@@ -2646,6 +2688,9 @@ int cluster_supports_given_attribute(char* cluster_name,ipp_tag_t tag,
26462688
p; p = (remote_printer_t *)cupsArrayNext(remote_printers)) {
26472689
if (strcmp(cluster_name, p->queue_name))
26482690
continue;
2691+
if(p->status == STATUS_DISAPPEARED || p->status == STATUS_UNCONFIRMED ||
2692+
p->status == STATUS_TO_BE_RELEASED )
2693+
continue;
26492694
if ((attr = ippFindAttribute(p->prattrs, attribute, tag)) != NULL &&
26502695
(count = ippGetCount(attr)) > 1)
26512696
return 1;
@@ -2683,6 +2728,9 @@ void get_cluster_default_attributes(ipp_t** merged_attributes,
26832728
p; p = (remote_printer_t *)cupsArrayNext(remote_printers)) {
26842729
if (strcmp(p->queue_name, cluster_name))
26852730
continue;
2731+
if(p->status == STATUS_DISAPPEARED || p->status == STATUS_UNCONFIRMED ||
2732+
p->status == STATUS_TO_BE_RELEASED )
2733+
continue;
26862734
if ((attr = ippFindAttribute (p->prattrs, "pages-per-minute",
26872735
IPP_TAG_INTEGER)) != NULL) {
26882736
pages_per_min = ippGetInteger (attr, 0);
@@ -2808,7 +2856,6 @@ void get_cluster_default_attributes(ipp_t** merged_attributes,
28082856

28092857
if (attr && ippGetCount(attr) > 0) {
28102858
*default_color = NULL;
2811-
debug_printf("ColorModel\n");
28122859
for (i = 0, count = ippGetCount(attr); i < count; i ++) {
28132860
keyword = ippGetString(attr, i, NULL);
28142861
if ((!strcasecmp(keyword, "black_1") ||
@@ -2939,7 +2986,7 @@ int supports_job_attributes_requested(const gchar* printer, int printer_index,
29392986
ipp_attribute_t *attr,*attr1;
29402987
ipp_t *request, *response = NULL;
29412988
const char *str,*side,*resource;
2942-
cups_array_t *formats_supported,*job_sheet_supported,
2989+
cups_array_t *job_sheet_supported,
29432990
*multiple_doc_supported,*print_qualities,
29442991
*media_type_supported,*staplelocation_supported,
29452992
*foldtype_supported,*punchmedia_supported,
@@ -2976,7 +3023,7 @@ int supports_job_attributes_requested(const gchar* printer, int printer_index,
29763023
attr = ippFirstAttribute(response);
29773024

29783025
/* Document Format */
2979-
if ((attr = ippFindAttribute(response, "document-format-detected",
3026+
/* if ((attr = ippFindAttribute(response, "document-format-detected",
29803027
IPP_TAG_MIMETYPE)) != NULL &&
29813028
ippGetCount(attr) > 0) {
29823029
str = ippGetString(attr,0, NULL);
@@ -2987,7 +3034,7 @@ int supports_job_attributes_requested(const gchar* printer, int printer_index,
29873034
printer, str);
29883035
return 0;
29893036
}
2990-
}
3037+
}*/
29913038

29923039
/* Job Sheets*/
29933040
if ((attr = ippFindAttribute(response, "job-sheets",
@@ -5851,8 +5898,12 @@ on_job_state (CupsNotifier *object,
58515898
num_of_printers = 0;
58525899
for (r = (remote_printer_t *)cupsArrayFirst(remote_printers);
58535900
r; r = (remote_printer_t *)cupsArrayNext(remote_printers)) {
5854-
if(!strcmp(r->queue_name, q->queue_name))
5855-
num_of_printers++;
5901+
if(!strcmp(r->queue_name, q->queue_name)){
5902+
if(r->status == STATUS_DISAPPEARED || r->status == STATUS_UNCONFIRMED ||
5903+
r->status == STATUS_TO_BE_RELEASED )
5904+
continue;
5905+
num_of_printers++;
5906+
}
58565907
}
58575908

58585909
/* If we are in a cluster, see whether the printer supports the
@@ -7129,7 +7180,7 @@ remove_printer_entry(remote_printer_t *p) {
71297180
}
71307181

71317182
gboolean update_cups_queues(gpointer unused) {
7132-
remote_printer_t *p, *q, *r, *s;
7183+
remote_printer_t *p, *q, *r, *s, *master;
71337184
http_t *http;
71347185
char uri[HTTP_MAX_URI], device_uri[HTTP_MAX_URI], buf[1024],
71357186
line[1024];
@@ -7399,6 +7450,9 @@ gboolean update_cups_queues(gpointer unused) {
73997450
/* Do not create a queue for slaves */
74007451
if (p->slave_of) {
74017452
p->status = STATUS_CONFIRMED;
7453+
master = p->slave_of;
7454+
master->status = STATUS_TO_BE_CREATED;
7455+
master->timeout = time(NULL) + TIMEOUT_IMMEDIATELY;
74027456
if (p->is_legacy) {
74037457
p->timeout = time(NULL) + BrowseTimeout;
74047458
debug_printf("starting BrowseTimeout timer for %s (%ds)\n",
@@ -7606,8 +7660,12 @@ gboolean update_cups_queues(gpointer unused) {
76067660
num_cluster_printers = 0;
76077661
for (s = (remote_printer_t *)cupsArrayFirst(remote_printers);
76087662
s; s = (remote_printer_t *)cupsArrayNext(remote_printers)){
7609-
if(!strcmp(s->queue_name,p->queue_name))
7610-
num_cluster_printers++;
7663+
if(!strcmp(s->queue_name,p->queue_name)) {
7664+
if(s->status == STATUS_DISAPPEARED || s->status == STATUS_UNCONFIRMED ||
7665+
s->status == STATUS_TO_BE_RELEASED )
7666+
continue;
7667+
num_cluster_printers++;
7668+
}
76117669
}
76127670

76137671
if (num_cluster_printers == 1) {
@@ -7918,8 +7976,12 @@ gboolean update_cups_queues(gpointer unused) {
79187976
num_cluster_printers = 0;
79197977
for (s = (remote_printer_t *)cupsArrayFirst(remote_printers);
79207978
s; s = (remote_printer_t *)cupsArrayNext(remote_printers)) {
7921-
if(!strcmp(s->queue_name,p->queue_name))
7922-
num_cluster_printers++;
7979+
if(!strcmp(s->queue_name,p->queue_name)) {
7980+
if(s->status == STATUS_DISAPPEARED || s->status == STATUS_UNCONFIRMED ||
7981+
s->status == STATUS_TO_BE_RELEASED )
7982+
continue;
7983+
num_cluster_printers++;
7984+
}
79237985
}
79247986
if (num_cluster_printers == 1) {
79257987
printer_attributes = p->prattrs;

0 commit comments

Comments
 (0)