papi_status_t service_connect(service_t *svc, char *service_name) { papi_status_t result = PAPI_OK; int port = 631; if (svc == NULL) return (PAPI_BAD_ARGUMENT); if (svc->connection != NULL) /* alread connected ? */ return (PAPI_OK); if (svc->uri == NULL) uri_from_string(service_name, &svc->uri); if ((service_name != NULL) && (svc->uri == NULL)) { /* * a name was supplied and it's not in URI form, we will * try to use a "default" IPP service under the assumption * that this is most likely a short-form printer name from * from a papiPrinter*() or papiJob*() call and not from a * papiServiceCreate() call. */ if ((service_name = getenv("PAPI_SERVICE_URI")) == NULL) { char *cups; if ((cups = getenv("CUPS_SERVER")) != NULL) { char buf[BUFSIZ]; snprintf(buf, sizeof (buf), "ipp://%s/printers/", cups); service_name = strdup(buf); } } if (service_name == NULL) service_name = DEFAULT_IPP_SERVICE_URI; uri_from_string(service_name, &svc->uri); } if (svc->uri == NULL) return (PAPI_NOT_POSSIBLE); if (svc->uri->port != NULL) port = strtol(svc->uri->port, NULL, 10); svc->connection = httpConnectEncrypt(svc->uri->host, port, http_encryption_type(svc->encryption)); if (svc->connection == NULL) { if (svc->uri != NULL) { uri_free(svc->uri); svc->uri = NULL; } result = PAPI_SERVICE_UNAVAILABLE; } else if (service_name != NULL) svc->name = strdup(service_name); return (result); }
/// Adds a P-Asserted-Identity header to the message. void PJUtils::add_asserted_identity(pjsip_tx_data* tdata, const std::string& aid) { LOG_DEBUG("Adding P-Asserted-Identity header: %s", aid.c_str()); pjsip_routing_hdr* p_asserted_id = identity_hdr_create(tdata->pool, STR_P_ASSERTED_IDENTITY); pjsip_name_addr* temp = (pjsip_name_addr*)uri_from_string(aid, tdata->pool, true); memcpy(&p_asserted_id->name_addr, temp, sizeof(pjsip_name_addr)); pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*)p_asserted_id); }
/* ARGSUSED2 */ static int report_device(papi_service_t svc, char *name, papi_printer_t printer, int verbose, int description) { papi_status_t status; papi_attribute_t **attrs = papiPrinterGetAttributeList(printer); char *uri = NULL; char *device = NULL; uri_t *u = NULL; if (name == NULL) { status = papiAttributeListGetString(attrs, NULL, "printer-name", &name); if (status != PAPI_OK) status = papiAttributeListGetString(attrs, NULL, "printer-uri-supported", &name); } if (name == NULL) return (-1); (void) papiAttributeListGetString(attrs, NULL, "printer-uri-supported", &uri); if ((uri != NULL) && (uri_from_string(uri, &u) == 0)) { char *nodename = localhostname(); if ((u->host == NULL) || (strcasecmp(u->host, "localhost") == 0) || (strcasecmp(u->host, nodename) == 0)) device = get_device_uri(svc, name); if (device != NULL) { printf(gettext("device for %s: %s\n"), name, device); return (0); } else if (uri != NULL) { printf(gettext("system for %s: %s (as %s)\n"), name, u->host, uri); return (0); } uri_free(u); } return (0); }