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

📄 nxcups.c.ori

📁 linux下的终端管理工具源码
💻 ORI
字号:
/***************************************************************************//*                                                                         *//* Copyright (c) 2005, 2006 2X Software Ltd, http://www.2X.com., NoMachine *//*                                                                         *//* NXCLIENT, NX protocol compression and NX extensions to this software    *//* are copyright of Nomachine. Redistribution and use of the present       *//* software is allowed according to terms specified in the file LICENSE    *//* which comes in the source distribution.                                 *//*                                                                         *//* NX and NoMachine are trademarks of Medialogic S.p.A.                    *//*                                                                         *//* 2X is a trademark of 2X Software Ltd.                                   *//*                                                                         *//* All rights reserved.                                                    *//*                                                                         *//***************************************************************************/#include <stdio.h>#include <stdlib.h>#include <cups/cups.h>#include <cups/language.h>#include "nxcups.h"void freePrinterDriversInfo(CupsPrinterDriverInfo_t *driver){  CupsPrinterDriverInfo_t *driver_info = NULL;  CupsPrinterDriverInfo_t *temp_driver_info = NULL;  if(driver == NULL) return;  for (driver_info = driver; driver_info != NULL; driver_info = temp_driver_info)  {    temp_driver_info = driver_info->next;    free(driver_info->name);    free(driver_info->driver);    free(driver_info);  }}CupsPrinterDriverInfo_t* getPrinterDrivers(){  http_t *http = NULL;  ipp_t  *req = NULL; /* ipp request */  ipp_t  *response = NULL; /* ipp answer */  ipp_attribute_t *attr = NULL; /* current attribute */  cups_lang_t *language = NULL;  char   *ppd_make     = NULL;  char   *ppd_name     = NULL;  CupsPrinterDriverInfo_t *drivers = NULL;  CupsPrinterDriverInfo_t *first_driver = NULL;  http = httpConnect(cupsServer(), ippPort());    //first we create new ipp request;  req = ippNew();  req->request.op.operation_id = CUPS_GET_PPDS;  req->request.op.request_id   = 1;    language = cupsLangDefault();    ippAddString(req,IPP_TAG_OPERATION, IPP_TAG_CHARSET,     "attributes-charset",NULL, cupsLangEncoding(language));    ippAddString(req, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,    "attributes-natural-language", NULL, language->language);    ippAddString(req, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",    NULL,"ipp://localhost/printers/");    if ((response = cupsDoRequest(http,req,"/")) != NULL)  {    /*      * Loop through the device list and display them ...     */        if (response->request.status.status_code > IPP_OK_CONFLICT)    {      //fprintf(stderr,"lpinfo: cups-get-ppds failed: %s\n",      //      ippErrorString(response->request.status.status_code));      ippDelete(response);      return NULL;    }    for (attr = response->attrs; attr != NULL; attr = attr->next)    {      /*       * Skip leading attributes until we hit a PPD...       */            /* check what is there in the ... */      while (attr != NULL && attr->group_tag != IPP_TAG_PRINTER)        attr = attr->next;            if (attr == NULL)        break;            ppd_make     = NULL;      ppd_name     = NULL;            while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER)      {        if (strcmp(attr->name, "ppd-make-and-model") == 0 &&          attr->value_tag == IPP_TAG_TEXT)        {          ppd_make = attr->values[0].string.text;        }        if(strcmp(attr->name, "ppd-name") == 0 &&          attr->value_tag == IPP_TAG_NAME)        {          ppd_name = attr->values[0].string.text;          attr = attr->next;        }            /*       * see if we have everything needed        */              if (ppd_make == NULL || ppd_name == NULL)        {          if (attr == NULL)            break;          else            continue;        }      #ifdef NX_DEBUG      printf("name = %s\t model= %s \n",ppd_name,ppd_make);#endif                 if(drivers == NULL){	drivers = (CupsPrinterDriverInfo_t *)malloc(sizeof(CupsPrinterDriverInfo_t));	first_driver = drivers;      }else{	drivers->next = (CupsPrinterDriverInfo_t *)malloc(sizeof(CupsPrinterDriverInfo_t));	drivers = drivers->next;      }	      drivers->next = NULL;      drivers->driver = strdup(ppd_name);      drivers->name   = strdup(ppd_make);            if( attr == NULL)	break;    }    if(drivers) drivers->next = NULL; /* stop no more drivers */    ippDelete(response);      }  else  {    printf("cups-get-ppds failed: %s\n",ippErrorString(cupsLastError()));  }    return(first_driver);  }

⌨️ 快捷键说明

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