bool sysv_cache_reload(struct pcap_cache **_pcache) { char **lines; int i; struct pcap_cache *pcache = NULL; #if defined(HPUX) DEBUG(5, ("reloading hpux printcap cache\n")); #else DEBUG(5, ("reloading sysv printcap cache\n")); #endif if ((lines = file_lines_pload("/usr/bin/lpstat -v", NULL)) == NULL) { #if defined(HPUX) /* * if "lpstat -v" is NULL then we check if schedular is running if it is * that means no printers are added on the HP-UX system, if schedular is not * running we display reload error. */ char **scheduler; scheduler = file_lines_pload("/usr/bin/lpstat -r", NULL); if(!strcmp(*scheduler,"scheduler is running")){ DEBUG(3,("No Printers found!!!\n")); TALLOC_FREE(scheduler); return True; } else{ DEBUG(3,("Scheduler is not running!!!\n")); TALLOC_FREE(scheduler); return False; } #else DEBUG(3,("No Printers found!!!\n")); return False; #endif } for (i = 0; lines[i]; i++) { char *name, *tmp; char *buf = lines[i]; /* eat "system/device for " */ if (((tmp = strchr_m(buf, ' ')) == NULL) || ((tmp = strchr_m(++tmp, ' ')) == NULL)) continue; /* * In case we're only at the "for ". */ if(!strncmp("for ", ++tmp, 4)) { tmp=strchr_m(tmp, ' '); tmp++; } /* Eat whitespace. */ while(*tmp == ' ') ++tmp; /* * On HPUX there is an extra line that can be ignored. * d.thibadeau 2001/08/09 */ if(!strncmp("remote to", tmp, 9)) continue; name = tmp; /* truncate the ": ..." */ if ((tmp = strchr_m(name, ':')) != NULL) *tmp = '\0'; /* add it to the cache */ if (!pcap_cache_add_specific(&pcache, name, NULL, NULL)) { TALLOC_FREE(lines); pcap_cache_destroy_specific(&pcache); return false; } } TALLOC_FREE(lines); *_pcache = pcache; return true; }
/* handle standard printcap - moved from pcap_printer_fn() */ bool std_pcap_cache_reload(const char *pcap_name, struct pcap_cache **_pcache) { XFILE *pcap_file; char *pcap_line; struct pcap_cache *pcache = NULL; if ((pcap_file = x_fopen(pcap_name, O_RDONLY, 0)) == NULL) { DEBUG(0, ("Unable to open printcap file %s for read!\n", pcap_name)); return false; } for (; (pcap_line = fgets_slash(NULL, 1024, pcap_file)) != NULL; free(pcap_line)) { char name[MAXPRINTERLEN+1]; char comment[62]; char *p, *q; if (*pcap_line == '#' || *pcap_line == 0) continue; /* now we have a real printer line - cut at the first : */ if ((p = strchr_m(pcap_line, ':')) != NULL) *p = 0; /* * now find the most likely printer name and comment * this is pure guesswork, but it's better than nothing */ for (*name = *comment = 0, p = pcap_line; p != NULL; p = q) { bool has_punctuation; if ((q = strchr_m(p, '|')) != NULL) *q++ = 0; has_punctuation = (strchr_m(p, ' ') || strchr_m(p, '\t') || strchr_m(p, '"') || strchr_m(p, '\'') || strchr_m(p, ';') || strchr_m(p, ',') || strchr_m(p, '(') || strchr_m(p, ')')); if (strlen(p) > strlen(comment) && has_punctuation) { strlcpy(comment, p, sizeof(comment)); continue; } if (strlen(p) <= MAXPRINTERLEN && *name == '\0' && !has_punctuation) { strlcpy(name, p, sizeof(name)); continue; } if (!strchr_m(comment, ' ') && strlen(p) > strlen(comment)) { strlcpy(comment, p, sizeof(comment)); continue; } } if ((*name != '\0') && !pcap_cache_add_specific(&pcache, name, comment, NULL)) { x_fclose(pcap_file); pcap_cache_destroy_specific(&pcache); return false; } } x_fclose(pcap_file); *_pcache = pcache; return true; }
static bool cups_cache_reload_async(int fd) { TALLOC_CTX *frame = talloc_stackframe(); struct pcap_cache *tmp_pcap_cache = NULL; http_t *http = NULL; /* HTTP connection to server */ ipp_t *request = NULL, /* IPP Request */ *response = NULL; /* IPP Response */ ipp_attribute_t *attr; /* Current attribute */ cups_lang_t *language = NULL; /* Default language */ char *name, /* printer-name attribute */ *info; /* printer-info attribute */ static const char *requested[] =/* Requested attributes */ { "printer-name", "printer-info" }; bool ret = False; size_t size; DEBUG(5, ("reloading cups printcap cache\n")); /* * Make sure we don't ask for passwords... */ cupsSetPasswordCB(cups_passwd_cb); /* * Try to connect to the server... */ if ((http = cups_connect(frame)) == NULL) { goto out; } /* * Build a CUPS_GET_PRINTERS request, which requires the following * attributes: * * attributes-charset * attributes-natural-language * requested-attributes */ request = ippNew(); request->request.op.operation_id = CUPS_GET_PRINTERS; request->request.op.request_id = 1; language = cupsLangDefault(); ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET, "attributes-charset", NULL, "utf-8"); ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE, "attributes-natural-language", NULL, language->language); ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requested-attributes", (sizeof(requested) / sizeof(requested[0])), NULL, requested); /* * Do the request and get back a response... */ if ((response = cupsDoRequest(http, request, "/")) == NULL) { DEBUG(0,("Unable to get printer list - %s\n", ippErrorString(cupsLastError()))); goto out; } for (attr = response->attrs; attr != NULL;) { /* * Skip leading attributes until we hit a printer... */ while (attr != NULL && attr->group_tag != IPP_TAG_PRINTER) attr = attr->next; if (attr == NULL) break; /* * Pull the needed attributes from this printer... */ name = NULL; info = NULL; while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER) { if (strcmp(attr->name, "printer-name") == 0 && attr->value_tag == IPP_TAG_NAME) { if (!pull_utf8_talloc(frame, &name, attr->values[0].string.text, &size)) { goto out; } } if (strcmp(attr->name, "printer-info") == 0 && attr->value_tag == IPP_TAG_TEXT) { if (!pull_utf8_talloc(frame, &info, attr->values[0].string.text, &size)) { goto out; } } attr = attr->next; } /* * See if we have everything needed... */ if (name == NULL) break; if (!pcap_cache_add_specific(&tmp_pcap_cache, name, info)) { goto out; } } ippDelete(response); response = NULL; /* * Build a CUPS_GET_CLASSES request, which requires the following * attributes: * * attributes-charset * attributes-natural-language * requested-attributes */ request = ippNew(); request->request.op.operation_id = CUPS_GET_CLASSES; request->request.op.request_id = 1; ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET, "attributes-charset", NULL, "utf-8"); ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE, "attributes-natural-language", NULL, language->language); ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requested-attributes", (sizeof(requested) / sizeof(requested[0])), NULL, requested); /* * Do the request and get back a response... */ if ((response = cupsDoRequest(http, request, "/")) == NULL) { DEBUG(0,("Unable to get printer list - %s\n", ippErrorString(cupsLastError()))); goto out; } for (attr = response->attrs; attr != NULL;) { /* * Skip leading attributes until we hit a printer... */ while (attr != NULL && attr->group_tag != IPP_TAG_PRINTER) attr = attr->next; if (attr == NULL) break; /* * Pull the needed attributes from this printer... */ name = NULL; info = NULL; while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER) { if (strcmp(attr->name, "printer-name") == 0 && attr->value_tag == IPP_TAG_NAME) { if (!pull_utf8_talloc(frame, &name, attr->values[0].string.text, &size)) { goto out; } } if (strcmp(attr->name, "printer-info") == 0 && attr->value_tag == IPP_TAG_TEXT) { if (!pull_utf8_talloc(frame, &info, attr->values[0].string.text, &size)) { goto out; } } attr = attr->next; } /* * See if we have everything needed... */ if (name == NULL) break; if (!pcap_cache_add_specific(&tmp_pcap_cache, name, info)) { goto out; } } ret = True; out: if (response) ippDelete(response); if (language) cupsLangFree(language); if (http) httpClose(http); /* Send all the entries up the pipe. */ if (tmp_pcap_cache) { pcap_printer_fn_specific(tmp_pcap_cache, send_pcap_info, (void *)&fd); pcap_cache_destroy_specific(&tmp_pcap_cache); } TALLOC_FREE(frame); return ret; }