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

📄 lpq_parse.c

📁 samba-3.0.22.tar.gz 编译smb服务器的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
here is an example of "lpstat -o dcslw" output under sysvdcslw-896               tridge            4712   Dec 20 10:30:30 on dcslwdcslw-897               tridge            4712   Dec 20 10:30:30 being held****************************************************************************/static BOOL parse_lpq_sysv(char *line,print_queue_struct *buf,BOOL first){  fstring tok[9];  int count=0;  char *p;  const char *cline = line;  /*    * Handle the dash in the job id, but make sure that we skip over   * the printer name in case we have a dash in that.   * Patch from Dom.Mitchell@palmerharvey.co.uk.   */  /*   * Move to the first space.   */  for (p = line ; !isspace(*p) && *p; p++)    ;  /*   * Back up until the last '-' character or   * start of line.   */  for (; (p >= line) && (*p != '-'); p--)    ;  if((p >= line) && (*p == '-'))    *p = ' ';  for (count=0; count<9 && next_token(&cline,tok[count],NULL,sizeof(tok[count])); count++)    ;  /* we must get 7 tokens */  if (count < 7)    return(False);  /* the 2nd and 4th, 6th columns must be integer */  if (!isdigit((int)*tok[1]) || !isdigit((int)*tok[3]))    return(False);  if (!isdigit((int)*tok[5]))    return(False);  /* if the user contains a ! then trim the first part of it */    if ((p=strchr_m(tok[2],'!'))) {      fstring tmp;      fstrcpy(tmp,p+1);      fstrcpy(tok[2],tmp);  }  buf->job = atoi(tok[1]);  buf->size = atoi(tok[3]);  if (count > 7 && strequal(tok[7],"on"))    buf->status = LPQ_PRINTING;  else if (count > 8 && strequal(tok[7],"being") && strequal(tok[8],"held"))    buf->status = LPQ_PAUSED;  else    buf->status = LPQ_QUEUED;  buf->priority = 0;  buf->time = EntryTime(tok, 4, count, 7);  fstrcpy(buf->fs_user,tok[2]);  fstrcpy(buf->fs_file,tok[2]);  return(True);}/****************************************************************************parse a lpq linehere is an example of lpq output under qnxSpooler: /qnx/spooler, on node 1Printer: txt        (ready) 0000:     root	[job #1    ]   active 1146 bytes	/etc/profile0001:     root	[job #2    ]    ready 2378 bytes	/etc/install0002:     root	[job #3    ]    ready 1146 bytes	-- standard input --****************************************************************************/static BOOL parse_lpq_qnx(char *line,print_queue_struct *buf,BOOL first){  fstring tok[7];  int count=0;  const char *cline = line;  DEBUG(4,("antes [%s]\n", line));  /* handle the case of "-- standard input --" as a filename */  string_sub(line,"standard input","STDIN",0);  DEBUG(4,("despues [%s]\n", line));  all_string_sub(line,"-- ","\"",0);  all_string_sub(line," --","\"",0);  DEBUG(4,("despues 1 [%s]\n", line));  string_sub(line,"[job #","",0);  string_sub(line,"]","",0);  DEBUG(4,("despues 2 [%s]\n", line));  for (count=0; count<7 && next_token(&cline,tok[count],NULL,sizeof(tok[count])); count++) ;  /* we must get 7 tokens */  if (count < 7)    return(False);  /* the 3rd and 5th columns must be integer */  if (!isdigit((int)*tok[2]) || !isdigit((int)*tok[4])) return(False);  /* only take the last part of the filename */  {    fstring tmp;    char *p = strrchr_m(tok[6],'/');    if (p)      {	fstrcpy(tmp,p+1);	fstrcpy(tok[6],tmp);      }  }	  buf->job = atoi(tok[2]);  buf->size = atoi(tok[4]);  buf->status = strequal(tok[3],"active")?LPQ_PRINTING:LPQ_QUEUED;  buf->priority = 0;  buf->time = time(NULL);  fstrcpy(buf->fs_user,tok[1]);  fstrcpy(buf->fs_file,tok[6]);  return(True);}/****************************************************************************  parse a lpq line for the plp printing system  Bertrand Wallrich <Bertrand.Wallrich@loria.fr>redone by tridge. Here is a sample queue:Local  Printer 'lp2' (fjall):  Printing (started at Jun 15 13:33:58, attempt 1).    Rank Owner       Pr Opt  Job Host        Files           Size     Date  active tridge      X  -    6   fjall       /etc/hosts      739      Jun 15 13:33     3rd tridge      X  -    7   fjall       /etc/hosts      739      Jun 15 13:33****************************************************************************/static BOOL parse_lpq_plp(char *line,print_queue_struct *buf,BOOL first){  fstring tok[11];  int count=0;  const char *cline = line;  /* handle the case of "(standard input)" as a filename */  string_sub(line,"stdin","STDIN",0);  all_string_sub(line,"(","\"",0);  all_string_sub(line,")","\"",0);    for (count=0; count<11 && next_token(&cline,tok[count],NULL,sizeof(tok[count])); count++) ;  /* we must get 11 tokens */  if (count < 11)    return(False);  /* the first must be "active" or begin with an integer */  if (strcmp(tok[0],"active") && !isdigit((int)tok[0][0]))    return(False);  /* the 5th and 8th must be integer */  if (!isdigit((int)*tok[4]) || !isdigit((int)*tok[7]))     return(False);  /* if the fname contains a space then use STDIN */  if (strchr_m(tok[6],' '))    fstrcpy(tok[6],"STDIN");  /* only take the last part of the filename */  {    fstring tmp;    char *p = strrchr_m(tok[6],'/');    if (p)      {        fstrcpy(tmp,p+1);        fstrcpy(tok[6],tmp);      }  }  buf->job = atoi(tok[4]);  buf->size = atoi(tok[7]);  if (strchr_m(tok[7],'K'))    buf->size *= 1024;  if (strchr_m(tok[7],'M'))    buf->size *= 1024*1024;  buf->status = strequal(tok[0],"active")?LPQ_PRINTING:LPQ_QUEUED;  buf->priority = 0;  buf->time = time(NULL);  fstrcpy(buf->fs_user,tok[1]);  fstrcpy(buf->fs_file,tok[6]);  return(True);}/*******************************************************************parse lpq on an NT system                         Windows 2000 LPD Server                              Printer \\10.0.0.2\NP17PCL (Paused)Owner       Status         Jobname          Job-Id    Size   Pages  Priority----------------------------------------------------------------------------root (9.99. Printing  /usr/lib/rhs/rhs-pr      3       625      0      1root (9.99. Paused    /usr/lib/rhs/rhs-pr      4       625      0      1jmcd        Waiting   Re: Samba Open Sour     26     32476      1      1********************************************************************/static BOOL parse_lpq_nt(char *line,print_queue_struct *buf,BOOL first){#define LPRNT_OWNSIZ 11#define LPRNT_STATSIZ 9#define LPRNT_JOBSIZ 19#define LPRNT_IDSIZ 6#define LPRNT_SIZSIZ 9  typedef struct   {    char owner[LPRNT_OWNSIZ];    char space1;    char status[LPRNT_STATSIZ];    char space2;    char jobname[LPRNT_JOBSIZ];    char space3;    char jobid[LPRNT_IDSIZ];    char space4;    char size[LPRNT_SIZSIZ];    char terminator;  } nt_lpq_line;  nt_lpq_line parse_line;#define LPRNT_PRINTING "Printing"#define LPRNT_WAITING "Waiting"#define LPRNT_PAUSED "Paused"  memset(&parse_line, '\0', sizeof(parse_line));  strncpy((char *) &parse_line, line, sizeof(parse_line) -1);  if (strlen((char *) &parse_line) != sizeof(parse_line) - 1)    return(False);  /* Just want the first word in the owner field - the username */  if (strchr_m(parse_line.owner, ' '))    *(strchr_m(parse_line.owner, ' ')) = '\0';  else    parse_line.space1 = '\0';  /* Make sure we have an owner */  if (!strlen(parse_line.owner))    return(False);  /* Make sure the status is valid */  parse_line.space2 = '\0';  trim_char(parse_line.status, '\0', ' ');  if (!strequal(parse_line.status, LPRNT_PRINTING) &&      !strequal(parse_line.status, LPRNT_PAUSED) &&      !strequal(parse_line.status, LPRNT_WAITING))    return(False);    parse_line.space3 = '\0';  trim_char(parse_line.jobname, '\0', ' ');  buf->job = atoi(parse_line.jobid);  buf->priority = 0;  buf->size = atoi(parse_line.size);  buf->time = time(NULL);  fstrcpy(buf->fs_user, parse_line.owner);  fstrcpy(buf->fs_file, parse_line.jobname);  if (strequal(parse_line.status, LPRNT_PRINTING))    buf->status = LPQ_PRINTING;  else if (strequal(parse_line.status, LPRNT_PAUSED))    buf->status = LPQ_PAUSED;  else    buf->status = LPQ_QUEUED;  return(True);}/*******************************************************************parse lpq on an OS2 systemJobID  File Name          Rank      Size        Status          Comment       -----  ---------------    ------    --------    ------------    ------------      3  Control                 1          68    Queued          root@psflinu      4  /etc/motd               2       11666    Queued          root@psflinu  ********************************************************************/static BOOL parse_lpq_os2(char *line,print_queue_struct *buf,BOOL first){#define LPROS2_IDSIZ 5#define LPROS2_JOBSIZ 15#define LPROS2_SIZSIZ 8#define LPROS2_STATSIZ 12#define LPROS2_OWNSIZ 12  typedef struct   {    char jobid[LPROS2_IDSIZ];    char space1[2];    char jobname[LPROS2_JOBSIZ];    char space2[14];    char size[LPROS2_SIZSIZ];    char space3[4];    char status[LPROS2_STATSIZ];    char space4[4];    char owner[LPROS2_OWNSIZ];    char terminator;  } os2_lpq_line;  os2_lpq_line parse_line;#define LPROS2_PRINTING "Printing"#define LPROS2_WAITING "Queued"#define LPROS2_PAUSED "Paused"  memset(&parse_line, '\0', sizeof(parse_line));  strncpy((char *) &parse_line, line, sizeof(parse_line) -1);  if (strlen((char *) &parse_line) != sizeof(parse_line) - 1)    return(False);  /* Get the jobid */  buf->job = atoi(parse_line.jobid);  /* Get the job name */  parse_line.space2[0] = '\0';  trim_char(parse_line.jobname, '\0', ' ');  fstrcpy(buf->fs_file, parse_line.jobname);  buf->priority = 0;  buf->size = atoi(parse_line.size);  buf->time = time(NULL);  /* Make sure we have an owner */  if (!strlen(parse_line.owner))    return(False);  /* Make sure we have a valid status */  parse_line.space4[0] = '\0';  trim_char(parse_line.status, '\0', ' ');  if (!strequal(parse_line.status, LPROS2_PRINTING) &&      !strequal(parse_line.status, LPROS2_PAUSED) &&      !strequal(parse_line.status, LPROS2_WAITING))    return(False);  fstrcpy(buf->fs_user, parse_line.owner);  if (strequal(parse_line.status, LPROS2_PRINTING))    buf->status = LPQ_PRINTING;  else if (strequal(parse_line.status, LPROS2_PAUSED))    buf->status = LPQ_PAUSED;  else    buf->status = LPQ_QUEUED;  return(True);}static const char *stat0_strings[] = { "enabled", "online", "idle", "no entries", "free", "ready", NULL };static const char *stat1_strings[] = { "offline", "disabled", "down", "off", "waiting", "no daemon", NULL };static const char *stat2_strings[] = { "jam", "paper", "error", "responding", "not accepting", "not running", "turned off", NULL };#ifdef DEVELOPER/****************************************************************************parse a vlp line****************************************************************************/static BOOL parse_lpq_vlp(char *line,print_queue_struct *buf,BOOL first){	int toknum = 0;	fstring tok;	const char *cline = line;	/* First line is printer status */	if (!isdigit(line[0])) return False;	/* Parse a print job entry */	while(next_token(&cline, tok, NULL, sizeof(fstring))) {		switch (toknum) {		case 0:			buf->job = atoi(tok);			break;		case 1:			buf->size = atoi(tok);			break;		case 2:			buf->status = atoi(tok);			break;		case 3:			buf->time = atoi(tok);			break;		case 4:			fstrcpy(buf->fs_user, tok);			break;		case 5:			fstrcpy(buf->fs_file, tok);			break;		}		toknum++;	}	return True;}#endif /* DEVELOPER *//****************************************************************************parse a lpq line. Choose printing style****************************************************************************/BOOL parse_lpq_entry(enum printing_types printing_type,char *line,		     print_queue_struct *buf,		     print_status_struct *status,BOOL first){  BOOL ret;  switch (printing_type)    {    case PRINT_SYSV:      ret = parse_lpq_sysv(line,buf,first);      break;    case PRINT_AIX:            ret = parse_lpq_aix(line,buf,first);      break;    case PRINT_HPUX:      ret = parse_lpq_hpux(line,buf,first);      break;    case PRINT_QNX:      ret = parse_lpq_qnx(line,buf,first);      break;    case PRINT_LPRNG:      ret = parse_lpq_lprng(line,buf,first);      break;    case PRINT_PLP:      ret = parse_lpq_plp(line,buf,first);      break;    case PRINT_LPRNT:      ret = parse_lpq_nt(line,buf,first);      break;    case PRINT_LPROS2:      ret = parse_lpq_os2(line,buf,first);      break;#ifdef DEVELOPER    case PRINT_VLP:    case PRINT_TEST:	    ret = parse_lpq_vlp(line,buf,first);	    break;#endif /* DEVELOPER */    default:      ret = parse_lpq_bsd(line,buf,first);      break;    }  /* We don't want the newline in the status message. */  {    char *p = strchr_m(line,'\n');    if (p) *p = 0;  }  /* in the LPRNG case, we skip lines starting by a space.*/  if (line && !ret && (printing_type==PRINT_LPRNG) )  {  	if (line[0]==' ')		return ret;  }  if (status && !ret)    {      /* a few simple checks to see if the line might be a         printer status line: 	 handle them so that most severe condition is shown */      int i;      strlower_m(line);            switch (status->status) {      case LPSTAT_OK:	for (i=0; stat0_strings[i]; i++)	  if (strstr_m(line,stat0_strings[i])) {		  fstrcpy(status->message,line);		  status->status=LPSTAT_OK;		  return ret;	  }      case LPSTAT_STOPPED:	for (i=0; stat1_strings[i]; i++)	  if (strstr_m(line,stat1_strings[i])) {		  fstrcpy(status->message,line);		  status->status=LPSTAT_STOPPED;		  return ret;	  }      case LPSTAT_ERROR:	for (i=0; stat2_strings[i]; i++)	  if (strstr_m(line,stat2_strings[i])) {		  fstrcpy(status->message,line);		  status->status=LPSTAT_ERROR;		  return ret;	  }	break;      }    }  return(ret);}

⌨️ 快捷键说明

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