⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gtkcupsutils.c

📁 This GTK+ version 2.12.3. GTK+ is a multi-platform toolkit for creating graphical user interfaces.
💻 C
📖 第 1 页 / 共 3 页
字号:
      if (strcasecmp (value, "true") == 0 ||          strcasecmp (value, "false") == 0)        {          option_tag = IPP_TAG_BOOLEAN;        }    }          switch (option_tag)    {      case IPP_TAG_INTEGER:      case IPP_TAG_ENUM:        ippAddInteger (request->ipp_request,                       IPP_TAG_JOB,                       option_tag,                       option,                       strtol (value, NULL, 0));        break;      case IPP_TAG_BOOLEAN:        {          char b;                    if (strcasecmp (value, "true") == 0 ||	      strcasecmp (value, "on") == 0 ||	      strcasecmp (value, "yes") == 0) 	    b = 1;	  else            b = 0;          ippAddBoolean (request->ipp_request,                         IPP_TAG_JOB,                         option,                         b);                  break;        }              case IPP_TAG_RANGE:        {          char	*s;          int lower;          int upper;                    if (*value == '-')	    {	      lower = 1;	      s = (char *)value;	    }	  else	    lower = strtol (value, &s, 0);	  if (*s == '-')	    {	      if (s[1])		upper = strtol (s + 1, NULL, 0);	      else		upper = 2147483647;            }	  else	    upper = lower;                   ippAddRange (request->ipp_request,                       IPP_TAG_JOB,                       option,                       lower,                       upper);          break;        }      case IPP_TAG_RESOLUTION:        {          char *s;          int xres;          int yres;          ipp_res_t units;                    xres = strtol (value, &s, 0);	  if (*s == 'x')	    yres = strtol (s + 1, &s, 0);	  else	    yres = xres;	  if (strcasecmp (s, "dpc") == 0)            units = IPP_RES_PER_CM;          else            units = IPP_RES_PER_INCH;                    ippAddResolution (request->ipp_request,                            IPP_TAG_JOB,                            option,                            units,                            xres,                            yres);          break;        }      default:        {          char *values;          char *s;          int in_quotes;          char *next;          GPtrArray *strings;                    values = g_strdup (value);          strings = NULL;	  in_quotes = 0;          for (s = values, next = s; *s != '\0'; s++)            {              if (in_quotes != 2 && *s == '\'')                {                  /* skip quoted value */                  if (in_quotes == 0)                    in_quotes = 1;                  else                    in_quotes = 0;                }              else if (in_quotes != 1 && *s == '\"')                {                  /* skip quoted value */                  if (in_quotes == 0)                    in_quotes = 2;                  else                    in_quotes = 0;                }              else if (in_quotes == 0 && *s == ',')                {                  /* found delimiter, add to value array */                  *s = '\0';                  if (strings == NULL)                    strings = g_ptr_array_new ();                  g_ptr_array_add (strings, next);                  next = s + 1;                }              else if (in_quotes == 0 && *s == '\\' && s[1] != '\0')                {                  /* skip escaped character */                  s++;                }            }                    if (strings == NULL)            {              /* single value */              ippAddString (request->ipp_request,                            IPP_TAG_JOB,                            option_tag,                            option,                            NULL,                            value);            }          else            {              /* multiple values */                            /* add last value */              g_ptr_array_add (strings, next);                            ippAddStrings (request->ipp_request,                             IPP_TAG_JOB,                             option_tag,                             option,                             strings->len,                             NULL,                             (const char **) strings->pdata);              g_ptr_array_free (strings, TRUE);            }          g_free (values);        }        break;    }}				static void_connect (GtkCupsRequest *request){  request->poll_state = GTK_CUPS_HTTP_IDLE;  if (request->http == NULL)    {      request->http = httpConnectEncrypt (request->server,                                           ippPort (),                                           cupsEncryption ());      if (request->http == NULL)        request->attempts++;      if (request->http)        httpBlocking (request->http, 0);              request->own_http = TRUE;    }  else    {      request->attempts = 0;      request->state++;      /* we always write to the socket after we get         the connection */      request->poll_state = GTK_CUPS_HTTP_WRITE;    }}static void _post_send (GtkCupsRequest *request){  gchar length[255];  struct stat data_info;  GTK_NOTE (PRINTING,            g_print ("CUPS Backend: %s\n", G_STRFUNC));  request->poll_state = GTK_CUPS_HTTP_WRITE;  if (request->data_io != NULL)    {      fstat (g_io_channel_unix_get_fd (request->data_io), &data_info);      sprintf (length, "%lu", (unsigned long) (ippLength (request->ipp_request) + data_info.st_size));    }  else    sprintf (length, "%lu", (unsigned long) ippLength (request->ipp_request));	  httpClearFields (request->http);  httpSetField (request->http, HTTP_FIELD_CONTENT_LENGTH, length);  httpSetField (request->http, HTTP_FIELD_CONTENT_TYPE, "application/ipp");#ifdef HAVE_HTTPGETAUTHSTRING  httpSetField (request->http, HTTP_FIELD_AUTHORIZATION, httpGetAuthString (request->http));#else#ifdef HAVE_HTTP_AUTHSTRING  httpSetField (request->http, HTTP_FIELD_AUTHORIZATION, request->http->authstring);#endif#endif  if (httpPost (request->http, request->resource))    {      if (httpReconnect (request->http))        {          request->state = GTK_CUPS_POST_DONE;          request->poll_state = GTK_CUPS_HTTP_IDLE;          /* TODO: should add a status or error code for failed post */          gtk_cups_result_set_error (request->result,                                     GTK_CUPS_ERROR_GENERAL,                                     0,                                     0,                                     "Failed Post");        }      request->attempts++;      return;        }            request->attempts = 0;    request->state = GTK_CUPS_POST_WRITE_REQUEST;    request->ipp_request->state = IPP_IDLE;}static void _post_write_request (GtkCupsRequest *request){  ipp_state_t ipp_status;  GTK_NOTE (PRINTING,            g_print ("CUPS Backend: %s\n", G_STRFUNC));  request->poll_state = GTK_CUPS_HTTP_WRITE;    ipp_status = ippWrite (request->http, request->ipp_request);  if (ipp_status == IPP_ERROR)    {      int cups_error = cupsLastError ();      request->state = GTK_CUPS_POST_DONE;      request->poll_state = GTK_CUPS_HTTP_IDLE;       gtk_cups_result_set_error (request->result,                                  GTK_CUPS_ERROR_IPP,                                 ipp_status,                                 cups_error,                                 "%s",                                  ippErrorString (cups_error));      return;    }  if (ipp_status == IPP_DATA)    {      if (request->data_io != NULL)        request->state = GTK_CUPS_POST_WRITE_DATA;      else        {          request->state = GTK_CUPS_POST_CHECK;          request->poll_state = GTK_CUPS_HTTP_READ;	}    }}static void _post_write_data (GtkCupsRequest *request){  gsize bytes;  char buffer[_GTK_CUPS_MAX_CHUNK_SIZE];  http_status_t http_status;  GTK_NOTE (PRINTING,            g_print ("CUPS Backend: %s\n", G_STRFUNC));  request->poll_state = GTK_CUPS_HTTP_WRITE;    if (httpCheck (request->http))    http_status = httpUpdate (request->http);  else    http_status = request->last_status;  request->last_status = http_status;  if (http_status == HTTP_CONTINUE || http_status == HTTP_OK)    {      GIOStatus io_status;      GError *error;      error = NULL;      /* send data */      io_status =        g_io_channel_read_chars (request->data_io, 	                         buffer, 				 _GTK_CUPS_MAX_CHUNK_SIZE,				 &bytes,				 &error);      if (io_status == G_IO_STATUS_ERROR)        {          request->state = GTK_CUPS_POST_DONE;	  request->poll_state = GTK_CUPS_HTTP_IDLE;               gtk_cups_result_set_error (request->result,                                     GTK_CUPS_ERROR_IO,                                     io_status,                                     error->code,                                      "Error reading from cache file: %s",                                     error->message);	  g_error_free (error);          return;	}      else if (bytes == 0 && io_status == G_IO_STATUS_EOF)        {          request->state = GTK_CUPS_POST_CHECK;	  request->poll_state = GTK_CUPS_HTTP_READ;          request->attempts = 0;          return;        }#if HAVE_CUPS_API_1_2      if (httpWrite2 (request->http, buffer, bytes) < bytes)#else      if (httpWrite (request->http, buffer, (int) bytes) < bytes)#endif /* HAVE_CUPS_API_1_2 */        {          int http_errno;          http_errno = httpError (request->http);          request->state = GTK_CUPS_POST_DONE;	  request->poll_state = GTK_CUPS_HTTP_IDLE;               gtk_cups_result_set_error (request->result,                                     GTK_CUPS_ERROR_HTTP,                                     http_status,                                     http_errno,                                      "Error writing to socket in Post %s",                                      g_strerror (http_errno));          return;        }    }   else    {      request->attempts++;    }}static void _post_check (GtkCupsRequest *request){  http_status_t http_status;  http_status = request->last_status;  GTK_NOTE (PRINTING,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -