MCPcopy Create free account
hub / github.com/OpenPrinting/cups / _cupsCreateDest

Function _cupsCreateDest

cups/dest.c:871–941  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

869 */
870
871char * /* O - Printer URI or @code NULL@ on error */
872_cupsCreateDest(const char *name, /* I - Printer name */
873 const char *info, /* I - Printer description of @code NULL@ */
874 const char *device_id, /* I - 1284 Device ID or @code NULL@ */
875 const char *device_uri, /* I - Device URI */
876 char *uri, /* I - Printer URI buffer */
877 size_t urisize) /* I - Size of URI buffer */
878{
879 http_t *http; /* Connection to server */
880 ipp_t *request, /* CUPS-Create-Local-Printer request */
881 *response; /* CUPS-Create-Local-Printer response */
882 ipp_attribute_t *attr; /* printer-uri-supported attribute */
883 ipp_pstate_t state = IPP_PSTATE_STOPPED;
884 /* printer-state value */
885
886
887 if (!name || !device_uri || !uri || urisize < 32)
888 return (NULL);
889
890 if ((http = httpConnect2(cupsServer(), ippPort(), NULL, AF_UNSPEC, HTTP_ENCRYPTION_IF_REQUESTED, 1, 30000, NULL)) == NULL)
891 return (NULL);
892
893 request = ippNewRequest(IPP_OP_CUPS_CREATE_LOCAL_PRINTER);
894
895 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, "ipp://localhost/");
896 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name", NULL, cupsUser());
897
898 ippAddString(request, IPP_TAG_PRINTER, IPP_TAG_URI, "device-uri", NULL, device_uri);
899 ippAddString(request, IPP_TAG_PRINTER, IPP_TAG_NAME, "printer-name", NULL, name);
900 if (info)
901 ippAddString(request, IPP_TAG_PRINTER, IPP_TAG_TEXT, "printer-info", NULL, info);
902 if (device_id)
903 ippAddString(request, IPP_TAG_PRINTER, IPP_TAG_TEXT, "printer-device-id", NULL, device_id);
904
905 response = cupsDoRequest(http, request, "/");
906
907 if ((attr = ippFindAttribute(response, "printer-uri-supported", IPP_TAG_URI)) != NULL)
908 strlcpy(uri, ippGetString(attr, 0, NULL), urisize);
909 else
910 {
911 ippDelete(response);
912 httpClose(http);
913 return (NULL);
914 }
915
916 if ((attr = ippFindAttribute(response, "printer-state", IPP_TAG_ENUM)) != NULL)
917 state = (ipp_pstate_t)ippGetInteger(attr, 0);
918
919 while (state == IPP_PSTATE_STOPPED && cupsLastError() == IPP_STATUS_OK)
920 {
921 sleep(1);
922 ippDelete(response);
923
924 request = ippNewRequest(IPP_OP_GET_PRINTER_ATTRIBUTES);
925
926 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, uri);
927 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name", NULL, cupsUser());
928 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, "requested-attributes", NULL, "printer-state");

Callers 3

cupsConnectDestFunction · 0.85
_cupsGetDestResourceFunction · 0.85
cupsSetDests2Function · 0.85

Calls 13

httpConnect2Function · 0.85
cupsServerFunction · 0.85
ippPortFunction · 0.85
ippNewRequestFunction · 0.85
ippAddStringFunction · 0.85
cupsUserFunction · 0.85
cupsDoRequestFunction · 0.85
ippFindAttributeFunction · 0.85
ippGetStringFunction · 0.85
ippDeleteFunction · 0.85
httpCloseFunction · 0.85
ippGetIntegerFunction · 0.85

Tested by

no test coverage detected