]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Added IPP client read/write code.
authormike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Fri, 5 Feb 1999 17:40:58 +0000 (17:40 +0000)
committermike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Fri, 5 Feb 1999 17:40:58 +0000 (17:40 +0000)
Added string functions missing from some UNIXs.

Added option parsing functions.

Added IPP convenience functions (not implemented yet).

Updated source files to use local string.h as needed (for
missing string functions)

git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@122 7a7537e8-13f0-0310-91df-b6672ffda945

22 files changed:
cups/Makefile
cups/cups.h
cups/emit.c
cups/filter.c
cups/http.c
cups/http.h
cups/ipp.c
cups/ipp.h
cups/mark.c
cups/mime.c
cups/mime.h
cups/options.c [new file with mode: 0644]
cups/page.c
cups/ppd.c
cups/ppd.h
cups/string.c [new file with mode: 0644]
cups/string.h [new file with mode: 0644]
cups/testhttp.c
cups/testmime.c
cups/testppd.c
cups/type.c
cups/util.c [new file with mode: 0644]

index 94bc2835a285f263d54f5a1c984f17247fdde98d..e1029233c998ba88e86bee15efea8372647f052e 100644 (file)
@@ -1,5 +1,5 @@
 #
-# "$Id: Makefile,v 1.2 1999/01/28 22:00:43 mike Exp $"
+# "$Id: Makefile,v 1.3 1999/02/05 17:40:50 mike Exp $"
 #
 #   Support library Makefile for the Common UNIX Printing System (CUPS).
 #
@@ -28,7 +28,8 @@ include ../Makedefs
 # libcups.a object files...
 #
 
-OBJS   =       emit.o filter.o http.o ipp.o mark.o mime.o page.o ppd.o type.o
+OBJS   =       emit.o filter.o http.o ipp.o mark.o mime.o options.o page.o \
+               ppd.o type.o util.o
 
 #
 # Header files to install...
@@ -76,13 +77,15 @@ libcups.a:  $(OBJS)
 
 emit.o:                ppd.h ../config.h ../Makedefs
 filter.o:      mime.h ../config.h ../Makedefs
-http.o:                http.h ../config.h ../Makedefs
+http.o:                http.h string.h ../config.h ../Makedefs
 ipp.o:         http.h ipp.h ../config.h ../Makedefs
 mark.o:                ppd.h ../config.h ../Makedefs
 mime.o:                mime.h ../config.h ../Makedefs
+options.o:     cups.h ../config.h ../Makedefs
 page.o:                ppd.h ../config.h ../Makedefs
 ppd.o:         ppd.h ../config.h ../Makedefs
 type.o:                mime.h ../config.h ../Makedefs
+util.o:                cups.h http.h ipp.h ../config.h ../Makedefs
 
 #
 # testhttp
@@ -114,5 +117,5 @@ testppd:    testppd.o libcups.a
 testppd.o:     ppd.h ../Makedefs
 
 #
-# End of "$Id: Makefile,v 1.2 1999/01/28 22:00:43 mike Exp $".
+# End of "$Id: Makefile,v 1.3 1999/02/05 17:40:50 mike Exp $".
 #
index c4331246c194f2fd829da3525185a8fa115c11a2..e662ba70e674883310e1fc878e2db6df3bba95e3 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: cups.h,v 1.3 1999/01/28 22:00:44 mike Exp $"
+ * "$Id: cups.h,v 1.4 1999/02/05 17:40:50 mike Exp $"
  *
  *   API definitions for the Common UNIX Printing System (CUPS).
  *
  * Include necessary headers...
  */
 
-#  include <stdio.h>
-#  include <stdlib.h>
-#  include <string.h>
-#  include <time.h>
-
 #  include <cups/ipp.h>
 #  include <cups/mime.h>
 #  include <cups/ppd.h>
@@ -60,16 +55,6 @@ extern "C" {
  * Types and structures...
  */
 
-typedef enum                           /**** Printer Status Bits ****/
-{
-  CUPS_PRINTER_IDLE = 0x00,            /* Printer is idle */
-  CUPS_PRINTER_BUSY = 0x01,            /* Printer is busy */
-  CUPS_PRINTER_FAULTED = 0x02,         /* Printer is faulted */
-  CUPS_PRINTER_UNAVAILABLE = 0x03,     /* Printer is unavailable */
-  CUPS_PRINTER_DISABLED = 0x04,                /* Printer is disabled */
-  CUPS_PRINTER_REJECTING = 0x08                /* Printer is rejecting jobs */
-} cups_pstatus_t;
-
 typedef enum                           /**** Printer Type/Capability Bits ****/
 {
   CUPS_PRINTER_CLASS = 0x0001,         /* Printer class */
@@ -90,47 +75,6 @@ typedef enum                         /**** Printer Type/Capability Bits ****/
   CUPS_PRINTER_VARIABLE = 0x8000       /* Can do variable sizes */
 } cups_ptype_t;
 
-typedef enum                           /**** Job Priorities ****/
-{
-  CUPS_PRIORITY_ANY = -1,              /* Use the default priority */
-  CUPS_PRIORITY_LOW,                   /* Lowest priority */
-  CUPS_PRIORITY_NORMAL = 50,           /* Default priority */
-  CUPS_PRIORITY_HIGH = 100             /* Highest priority */
-} cups_jpriority_t;
-
-typedef enum                           /**** Job Status ****/
-{
-  CUPS_JOB_PRINTING,
-  CUPS_JOB_PENDING,
-  CUPS_JOB_STOPPED
-} cups_jstatus_t;
-
-/*
- * Error codes...
- */
-
-#  define CUPS_ERROR_NONE              0x00
-#  define CUPS_ERROR_ACCESS            0x01
-#  define CUPS_ERROR_NOT_AVAILABLE     0x02
-#  define CUPS_ERROR_NOT_PRIVILEDGED   0x03
-
-#  define CUPS_ERROR_BAD_PRINTER       0x10
-#  define CUPS_ERROR_BAD_CLASS         0x11
-#  define CUPS_ERROR_BAD_URI           0x12
-#  define CUPS_ERROR_BAD_INTERFACE     0x13
-#  define CUPS_ERROR_BAD_PPD           0x14
-#  define CUPS_ERROR_BAD_LOCATION_CODE 0x15
-#  define CUPS_ERROR_BAD_STATUS_CODE   0x16
-#  define CUPS_ERROR_BAD_ACL           0x17
-#  define CUPS_ERROR_BAD_JOB           0x18
-#  define CUPS_ERROR_BAD_USER          0x19
-#  define CUPS_ERROR_BAD_FILENAME      0x1a
-#  define CUPS_ERROR_BAD_ID            0x1b
-#  define CUPS_ERROR_BAD_COPIES                0x1c
-#  define CUPS_ERROR_BAD_PRIORITY      0x1d
-#  define CUPS_ERROR_BAD_OPTIONS       0x1e
-#  define CUPS_ERROR_BAD_DATE          0x1f
-
 
 /*
  * Types & structures...
@@ -138,56 +82,19 @@ typedef enum                               /**** Job Status ****/
 
 typedef struct                         /**** Printer Information ****/
 {
-  char         printer_or_class[128],  /* Printer or class name */
-               device_uri[128],        /* Universal resource identifier */
-               description[64],        /* Printer or class description */
-               location_code[32],      /* Location code */
-               location_text[96],      /* Location text */
-  short                type_code,              /* Printer type code */
-               status_code;            /* Status code */
-  unsigned char        status_text[60];        /* Status text */
-} cups_printer_t;
-
-typedef struct                         /**** Job Information ****/
-{
-  char         printer_or_class[128],  /* Printer or class name */
-               user[64],               /* Username (user@host) */
-               super[MIME_MAX_SUPER],  /* Super-type of job file */
-               type[MIME_MAX_TYPE],    /* Type of job file */
-               description[128],       /* Job title or filename */
-  int          id;                     /* Job identifier */
-  unsigned     size;                   /* Size of file in bytes */
-  int          status_code,            /* Status code */
-               priority,               /* Job priority */
-               num_copies,             /* Number of copies */
-               num_options;            /* Number of job options */
-  char         **options;              /* Job options (name=value) */
-} cups_job_t;
-
-typedef struct                         /**** Page Information ****/
-{
-  char         printer_or_class[128],  /* Printer or class name */
-               user[64];               /* Username (user@host) */
-  unsigned char        description[128];       /* Job title or filename */
-  int          id;                     /* Job identifier */
-  time_t       secs;                   /* Time stamp */
-  int          num_copies,             /* Number of copies */
-               num_options;            /* Number of job options */
-  char         **options;              /* Job options (name=value) */
-} cups_page_t;
-
-typedef struct                         /**** Message Header ****/
+  char         name[IPP_MAX_NAME],     /* Printer or class name */
+               uri[HTTP_MAX_URI];      /* Universal resource identifier */
+  unsigned char        info[IPP_MAX_NAME],     /* Printer or class info/description */
+               location[IPP_MAX_NAME]; /* Location text */
+  ipp_pstate_t state;                  /* Printer state */
+  unsigned char        message[IPP_MAX_NAME];  /* State text */
+  cups_ptype_t type;                   /* Printer type/capability codes */
+} cups_browse_t;
+
+typedef struct                         /**** Printer Options ****/
 {
-  short                type,                   /* Message type (see above) */
-               count;                  /* Number of records in message */
-  unsigned     length;                 /* Length of message in bytes */
-} cups_header_t;
-
-
-typedef struct                         /**** Option Structure ****/
-{
-  char         *name;                  /* Option name */
-  char         *value;                 /* Option value */
+  char         *name;                  /* Name of option */
+  char         *value;                 /* Value of option */
 } cups_option_t;
 
 
@@ -195,47 +102,19 @@ typedef struct                            /**** Option Structure ****/
  * Functions...
  */
 
-extern int             cupsOpen(void);
-extern int             cupsClose(int fd);
-
-extern unsigned char   *cupsErrorString(int code);
-extern unsigned char   *cupsJobStatusString(int code);
-extern unsigned char   *cupsPrinterStatusString(int code);
-
-extern int             cupsPrinterUpdate(int fd, char *name, short status_code,
-                                         unsigned char *status_text);
-extern cups_msg_t      *cupsPrinterQuery(char *name);
-extern cups_msg_t      *cupsPrinterFind(char *name, char *classes,
-                                        unsigned char *location_code,
-                                        unsigned char *location_text);
-
-extern cups_msg_t      *cupsJobAdd(unsigned char *name, char *queue_name,
-                                   char *filename, int copies, int priority,
-                                   int copy_file, cups_array_t *options);
-extern cups_msg_t      *cupsJobRemove(int id, char *queue_name);
-extern cups_msg_t      *cupsJobUpdate(int id, char *queue_name,
-                                      int copies, int priority,
-                                      cups_array_t *options);
-extern cups_msg_t      *cupsJobQuery(int id);
-extern cups_msg_t      *cupsJobFind(int id, char *queue_name, int priority);
-
-extern cups_msg_t      *cupsPageAdd(unsigned char *job_name,
-                                    char *printer_name, char *user,
-                                    char *filename, int copies, int priority,
-                                    time_t start_date, time_t end_date,
-                                    cups_array_t *options);
-extern cups_msg_t      *cupsPageQuery(char *printer_name, char *user,
-                                      int copies);
-extern cups_msg_t      *cupsPageFind(unsigned char *job_name,
-                                     char *printer_name, char *user,
-                                     char *filename, int priority,
-                                     time_t start_date, time_t end_date);
-extern cups_msg_t      *cupsPageClear(unsigned char *job_name,
-                                      char *printer_name, char *user,
-                                      char *filename, int priority,
-                                      time_t start_date, time_t end_date);
-
-extern int             *cupsParseOptions(char *arg, cups_option_t **options);
+extern int             cupsCancelJob(char *printer, int job);
+extern int             cupsGetClasses(char ***classes);
+extern char            *cupsGetPPD(char *printer);
+extern int             cupsGetPrinters(char ***printers);
+extern int             cupsPrintFile(char *printer, char *filename,
+                                     int num_options, cups_option_t *options);
+
+extern int             cupsAddOption(char *name, char *value, int num_options,
+                                     cups_option_t **options);
+extern void            cupsFreeOptions(int num_options, cups_option_t *options);
+extern char            *cupsGetOption(char *name, int num_options,
+                                      cups_option_t *options);
+extern int             cupsParseOptions(char *arg, cups_option_t **options);
 
 #  ifdef _cplusplus
 }
@@ -244,5 +123,5 @@ extern int          *cupsParseOptions(char *arg, cups_option_t **options);
 #endif /* !_CUPS_CUPS_H_ */
 
 /*
- * End of "$Id: cups.h,v 1.3 1999/01/28 22:00:44 mike Exp $".
+ * End of "$Id: cups.h,v 1.4 1999/02/05 17:40:50 mike Exp $".
  */
index c96a2e704315fe1cac0497fd5755f4245caa5d5f..19293102d634e6f942586a5839231c3b33b19087 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: emit.c,v 1.6 1999/01/30 13:25:54 mike Exp $"
+ * "$Id: emit.c,v 1.7 1999/02/05 17:40:50 mike Exp $"
  *
  *   PPD code emission routines for the Common UNIX Printing System (CUPS).
  *
  */
 
 #include "ppd.h"
-#ifdef WIN32
+#include <stdlib.h>
+
+#if defined(WIN32) || defined(__EMX__)
 #  include <io.h>
 #else
 #  include <unistd.h>
-#endif /* WIN32 */
+#endif /* WIN32 || __EMX__ */
 
 
 /*
@@ -213,47 +215,52 @@ ppd_collect(ppd_file_t    *ppd,           /* I - PPD file data */
   */
 
   for (i = ppd->num_jcls, o = ppd->jcls; i > 0; i --, o ++)
-    for (j = o->num_choices, c = o->choices; j > 0; j --, c ++)
-      if (c->marked && count < 1000)
-      {
-        collect[count] = c;
-       count ++;
-      }
+    if (o->section == section)
+      for (j = o->num_choices, c = o->choices; j > 0; j --, c ++)
+       if (c->marked && count < 1000)
+       {
+          collect[count] = c;
+         count ++;
+       }
 
   for (i = ppd->num_options, o = ppd->options; i > 0; i --, o ++)
-    for (j = o->num_choices, c = o->choices; j > 0; j --, c ++)
-      if (c->marked && count < 1000)
-      {
-        collect[count] = c;
-       count ++;
-      }
+    if (o->section == section)
+      for (j = o->num_choices, c = o->choices; j > 0; j --, c ++)
+       if (c->marked && count < 1000)
+       {
+          collect[count] = c;
+         count ++;
+       }
 
   for (i = ppd->num_nonuis, o = ppd->nonuis; i > 0; i --, o ++)
-    for (j = o->num_choices, c = o->choices; j > 0; j --, c ++)
-      if (c->marked && count < 1000)
-      {
-        collect[count] = c;
-       count ++;
-      }
-
-  for (i = ppd->num_groups, g = ppd->groups; i > 0; i --, g ++)
-  {
-    for (j = g->num_options, o = g->options; j > 0; j --, o ++)
-      for (k = o->num_choices, c = o->choices; k > 0; k --, c ++)
+    if (o->section == section)
+      for (j = o->num_choices, c = o->choices; j > 0; j --, c ++)
        if (c->marked && count < 1000)
        {
           collect[count] = c;
          count ++;
        }
 
-    for (j = g->num_subgroups, sg = g->subgroups; j > 0; j --, sg ++)
-      for (k = sg->num_options, o = sg->options; k > 0; k --, o ++)
-       for (m = o->num_choices, c = o->choices; m > 0; m --, c ++)
+  for (i = ppd->num_groups, g = ppd->groups; i > 0; i --, g ++)
+  {
+    for (j = g->num_options, o = g->options; j > 0; j --, o ++)
+      if (o->section == section)
+       for (k = o->num_choices, c = o->choices; k > 0; k --, c ++)
          if (c->marked && count < 1000)
          {
             collect[count] = c;
            count ++;
          }
+
+    for (j = g->num_subgroups, sg = g->subgroups; j > 0; j --, sg ++)
+      for (k = sg->num_options, o = sg->options; k > 0; k --, o ++)
+       if (o->section == section)
+         for (m = o->num_choices, c = o->choices; m > 0; m --, c ++)
+           if (c->marked && count < 1000)
+           {
+              collect[count] = c;
+             count ++;
+           }
   }
 
  /*
@@ -284,5 +291,5 @@ ppd_collect(ppd_file_t    *ppd,             /* I - PPD file data */
 
 
 /*
- * End of "$Id: emit.c,v 1.6 1999/01/30 13:25:54 mike Exp $".
+ * End of "$Id: emit.c,v 1.7 1999/02/05 17:40:50 mike Exp $".
  */
index cf03d9c182a2c6e1294fa0d69589fa1dd293f7fc..0870970d2d4f8e0dfbf56843070bcb8a9c44f23c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: filter.c,v 1.3 1999/01/24 14:18:43 mike Exp $"
+ * "$Id: filter.c,v 1.4 1999/02/05 17:40:51 mike Exp $"
  *
  *   File type conversion routines for the Common UNIX Printing System (CUPS).
  *
  * Revision History:
  *
  *   $Log: filter.c,v $
+ *   Revision 1.4  1999/02/05 17:40:51  mike
+ *   Added IPP client read/write code.
+ *
+ *   Added string functions missing from some UNIXs.
+ *
+ *   Added option parsing functions.
+ *
+ *   Added IPP convenience functions (not implemented yet).
+ *
+ *   Updated source files to use local string.h as needed (for
+ *   missing string functions)
+ *
  *   Revision 1.3  1999/01/24 14:18:43  mike
  *   Check-in prior to CVS use.
  *
  * Include necessary headers...
  */
 
+#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
+
+#include "string.h"
 #include "mime.h"
 
 
@@ -273,5 +290,5 @@ lookup(mime_t      *mime,   /* I - MIME database */
 
 
 /*
- * End of "$Id: filter.c,v 1.3 1999/01/24 14:18:43 mike Exp $".
+ * End of "$Id: filter.c,v 1.4 1999/02/05 17:40:51 mike Exp $".
  */
index 85a112a361d7dded40396a79ea39f2a70ba51500..87abb026022f0d624a70e9b6123eefc3b5b25691 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: http.c,v 1.13 1999/02/01 22:06:36 mike Exp $"
+ * "$Id: http.c,v 1.14 1999/02/05 17:40:51 mike Exp $"
  *
  *   HTTP routines for the Common UNIX Printing System (CUPS) scheduler.
  *
  *                         content-length or transfer-encoding fields.
  *   http_send()         - Send a request with all fields and the trailing
  *                         blank line.
- *   http_sighandler()   - Handle broken pipe signals from lost network
- *                         clients.
  */
 
 /*
  * Include necessary headers...
  */
 
-#include "http.h"
+#include <stdio.h>
+#include <stdlib.h>
 #include <stdarg.h>
+#include <ctype.h>
+#include "string.h"
+#include <time.h>
+#include <fcntl.h>
 
-#ifdef WIN32
-#  define strcasecmp(s,t) stricmp(s,t)
-#endif /* WIN32 */
+#include "http.h"
 
 
 /*
@@ -77,7 +78,6 @@
 static http_field_t    http_field(char *name);
 static void            http_get_length(http_t *http);
 static int             http_send(http_t *http, http_state_t request, char *uri);
-static void            http_sighandler(int sig);
 
 
 /*
@@ -1331,17 +1331,5 @@ http_send(http_t       *http,    /* I - HTTP data */
 
 
 /*
- * 'http_sighandler()' - Handle 'broken pipe' signals from lost network
- *                       clients.
- */
-
-static void
-http_sighandler(int sig)       /* I - Signal number */
-{
-/* IGNORE */
-}
-
-
-/*
- * End of "$Id: http.c,v 1.13 1999/02/01 22:06:36 mike Exp $".
+ * End of "$Id: http.c,v 1.14 1999/02/05 17:40:51 mike Exp $".
  */
index 92a856b91c6017da427acee248a553bcc74a67ac..a5c657b1edf8cbe393b00d8b00166f350cd3a733 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: http.h,v 1.10 1999/02/01 22:06:37 mike Exp $"
+ * "$Id: http.h,v 1.11 1999/02/05 17:40:52 mike Exp $"
  *
  *   Hyper-Text Transport Protocol definitions for the Common UNIX Printing
  *   System (CUPS).
  * Include necessary headers...
  */
 
-#  include <stdio.h>
-#  include <stdlib.h>
 #  include <string.h>
-#  include <time.h>
-#  include <fcntl.h>
-
-#  ifdef WIN32
-#    include <winsock.h>
-#  else
-#    include <sys/time.h>
-#    include <sys/socket.h>
-#    include <netdb.h>
-#    include <netinet/in.h>
-#    include <netinet/in_systm.h>
-#    include <netinet/ip.h>
-#    include <netinet/tcp.h>
-#  endif /* WIN32 */
+
+#if defined(WIN32) || defined(__EMX__)
+#  include <winsock.h>
+#else
+#  include <unistd.h>
+#  include <sys/time.h>
+#  include <sys/socket.h>
+#  include <netdb.h>
+#  include <netinet/in.h>
+#  include <netinet/in_systm.h>
+#  include <netinet/ip.h>
+#  include <netinet/tcp.h>
+#endif /* WIN32 || __EMX__ */
+
 
 /*
  * C++ magic...
@@ -310,5 +308,5 @@ extern char         *httpDecode64(char *out, char *in);
 #endif /* !_CUPS_HTTP_H_ */
 
 /*
- * End of "$Id: http.h,v 1.10 1999/02/01 22:06:37 mike Exp $".
+ * End of "$Id: http.h,v 1.11 1999/02/05 17:40:52 mike Exp $".
  */
index 8f4f9990dfdb927f5d4655df54a8e6824151102b..7cb155e927f5e0bddeb9fc10fda85e2d66336905 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: ipp.c,v 1.3 1999/01/28 22:00:45 mike Exp $"
+ * "$Id: ipp.c,v 1.4 1999/02/05 17:40:52 mike Exp $"
  *
  *   Internet Printing Protocol support functions for the Common UNIX
  *   Printing System (CUPS).
@@ -40,7 +40,7 @@
  *   ippFindAttribute() - Find a named attribute in a request...
  *   ippLength()        - Compute the length of an IPP request.
  *   ippRead()          - Read data for an IPP request.
- *   ipp_TimeToDate()   - Convert from UNIX time to RFC 1903 format.
+ *   ippTimeToDate()    - Convert from UNIX time to RFC 1903 format.
  *   ippWrite()         - Write data for an IPP request.
  *   add_attr()         - Add a new attribute to the request.
  */
  * Include necessary headers...
  */
 
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+
 #include "ipp.h"
 
 
@@ -627,20 +632,252 @@ ippNew(void)
  * 'ippRead()' - Read data for an IPP request.
  */
 
-int
-ippRead(http_t *http,
-        ipp_t  *ipp)
+ipp_state_t                    /* O - Current state */
+ippRead(http_t *http,          /* I - HTTP data */
+        ipp_t  *ipp)           /* I - IPP data */
 {
-  return (1);
+  int                  n;              /* Length of data */
+  char                 buffer[8192];   /* Data buffer */
+  ipp_attribute_t      *attr;          /* Current attribute */
+  ipp_tag_t            tag;            /* Current tag */
+
+
+  if (http == NULL || ipp == NULL)
+    return (IPP_ERROR);
+
+  switch (ipp->state)
+  {
+    case IPP_IDLE :
+        break;
+
+    case IPP_HEADER :
+       /*
+        * Get the request header...
+       */
+
+        if (httpRead(http, buffer, 8) < 8)
+         return (IPP_ERROR);
+
+       /*
+        * Verify the major version number...
+       */
+
+       if (buffer[0] != 1)
+         return (IPP_ERROR);
+
+       /*
+        * Then copy the request header over...
+       */
+
+        ipp->request.any.version[0]  = buffer[0];
+        ipp->request.any.version[1]  = buffer[1];
+        ipp->request.any.op_status   = (buffer[2] << 8) | buffer[3];
+        ipp->request.any.request_id  = (((((buffer[4] << 8) | buffer[5]) << 8) |
+                                      buffer[6]) << 8) | buffer[7];
+
+        ipp->state   = IPP_ATTRIBUTE;
+       ipp->current = NULL;
+       ipp->curtag  = IPP_TAG_ZERO;
+
+       /*
+        * If blocking is disabled, stop here...
+       */
+
+        if (!http->blocking)
+         break;
+
+    case IPP_ATTRIBUTE :
+        while (httpRead(http, buffer, 1) > 0)
+       {
+        /*
+         * Read this attribute...
+         */
+
+          tag = (ipp_tag_t)buffer[0];
+
+         if (tag == IPP_TAG_END)
+         {
+          /*
+           * No more attributes left...
+           */
+
+           ipp->state = IPP_DATA;
+           break;
+         }
+          else if (tag < IPP_TAG_UNSUPPORTED)
+         {
+          /*
+           * Group tag...  Set the current group and continue...
+           */
+
+           ipp->curtag  = tag;
+           ipp->current = NULL;
+           continue;
+         }
+
+         /*
+         * Get the name...
+         */
+
+          if (httpRead(http, buffer, 2) < 2)
+           return (IPP_ERROR);
+
+          n = (buffer[0] << 8) | buffer[1];
+
+          if (n == 0)
+         {
+          /*
+           * More values for current attribute...
+           */
+
+            if (ipp->current == NULL)
+             return (IPP_ERROR);
+
+            attr = ipp->current;
+
+           if (attr->num_values >= IPP_MAX_VALUES)
+             return (IPP_ERROR);
+         }
+         else
+         {
+          /*
+           * New attribute; read the name and add it...
+           */
+
+           if (httpRead(http, buffer, n) < n)
+             return (IPP_ERROR);
+
+           buffer[n] = '\0';
+           attr = ipp->current = add_attr(ipp, IPP_MAX_VALUES);
+
+           attr->group_tag = ipp->curtag;
+           attr->value_tag = tag;
+           attr->name      = strdup(buffer);
+         }
+
+         switch (tag)
+         {
+           case IPP_TAG_INTEGER :
+           case IPP_TAG_ENUM :
+               if (httpRead(http, buffer, 4) < 4)
+                 return (IPP_ERROR);
+
+               n = (((((buffer[0] << 8) | buffer[1]) << 8) | buffer[2]) << 8) |
+                   buffer[3];
+
+                attr->values[attr->num_values].integer = n;
+               break;
+           case IPP_TAG_BOOLEAN :
+               if (httpRead(http, buffer, 1) < 4)
+                 return (IPP_ERROR);
+
+                attr->values[attr->num_values].boolean = buffer[0];
+               break;
+           case IPP_TAG_TEXT :
+           case IPP_TAG_NAME :
+           case IPP_TAG_KEYWORD :
+           case IPP_TAG_STRING :
+           case IPP_TAG_URI :
+           case IPP_TAG_URISCHEME :
+           case IPP_TAG_CHARSET :
+           case IPP_TAG_LANGUAGE :
+           case IPP_TAG_MIMETYPE :
+               if (httpRead(http, buffer, 2) < 2)
+                 return (IPP_ERROR);
+
+               n = (buffer[0] << 8) | buffer[1];
+
+               if (httpRead(http, buffer, n) < n)
+                 return (IPP_ERROR);
+
+                buffer[n] = '\0';
+
+                attr->values[attr->num_values].string = strdup(buffer);
+               break;
+           case IPP_TAG_DATE :
+               if (httpRead(http, buffer, 11) < 11)
+                 return (IPP_ERROR);
+
+                memcpy(attr->values[attr->num_values].date, buffer, 11);
+               break;
+           case IPP_TAG_RESOLUTION :
+               if (httpRead(http, buffer, 9) < 9)
+                 return (IPP_ERROR);
+
+                attr->values[attr->num_values].resolution.xres =
+                   (((((buffer[0] << 8) | buffer[1]) << 8) | buffer[2]) << 8) |
+                   buffer[3];
+                attr->values[attr->num_values].resolution.yres =
+                   (((((buffer[4] << 8) | buffer[5]) << 8) | buffer[6]) << 8) |
+                   buffer[7];
+                attr->values[attr->num_values].resolution.units =
+                   (ipp_res_t)buffer[8];
+               break;
+           case IPP_TAG_RANGE :
+               if (httpRead(http, buffer, 8) < 8)
+                 return (IPP_ERROR);
+
+                attr->values[attr->num_values].range.lower =
+                   (((((buffer[0] << 8) | buffer[1]) << 8) | buffer[2]) << 8) |
+                   buffer[3];
+                attr->values[attr->num_values].range.upper =
+                   (((((buffer[4] << 8) | buffer[5]) << 8) | buffer[6]) << 8) |
+                   buffer[7];
+               break;
+           case IPP_TAG_TEXTLANG :
+           case IPP_TAG_NAMELANG :
+               if (httpRead(http, buffer, 2) < 2)
+                 return (IPP_ERROR);
+
+               n = (buffer[0] << 8) | buffer[1];
+
+               if (httpRead(http, buffer, n) < n)
+                 return (IPP_ERROR);
+
+                buffer[n] = '\0';
+
+                attr->values[attr->num_values].lstring.charset = strdup(buffer);
+
+               if (httpRead(http, buffer, 2) < 2)
+                 return (IPP_ERROR);
+
+               n = (buffer[0] << 8) | buffer[1];
+
+               if (httpRead(http, buffer, n) < n)
+                 return (IPP_ERROR);
+
+                buffer[n] = '\0';
+
+                attr->values[attr->num_values].lstring.string =
+                   (unsigned char *)strdup(buffer);
+               break;
+         }
+
+          attr->num_values ++;
+
+        /*
+          * If blocking is disabled, stop here...
+         */
+
+          if (!http->blocking)
+           break;
+       }
+        break;
+
+    case IPP_DATA :
+        break;
+  }
+
+  return (ipp->state);
 }
 
 
 /*
- * 'ipp_TimeToDate()' - Convert from UNIX time to RFC 1903 format.
+ * 'ippTimeToDate()' - Convert from UNIX time to RFC 1903 format.
  */
 
 uchar *                                /* O - RFC-1903 date/time data */
-ipp_TimeToDate(time_t t)       /* I - UNIX time value */
+ippTimeToDate(time_t t)                /* I - UNIX time value */
 {
   struct tm    *unixdate;      /* UNIX unixdate/time info */
   static uchar date[11];       /* RFC-1903 date/time data */
@@ -686,11 +923,307 @@ ipp_TimeToDate(time_t t) /* I - UNIX time value */
  * 'ippWrite()' - Write data for an IPP request.
  */
 
-int
-ippWrite(http_t *http,
-         ipp_t  *ipp)
+ipp_state_t                    /* O - Current state */
+ippWrite(http_t *http,         /* I - HTTP data */
+         ipp_t  *ipp)          /* I - IPP data */
 {
-  return (1);
+  int                  i;      /* Looping var */
+  int                  n;      /* Length of data */
+  char                 buffer[8192],   /* Data buffer */
+                       *bufptr;/* Pointer into buffer */
+  ipp_attribute_t      *attr;  /* Current attribute */
+
+
+  if (http == NULL || ipp == NULL)
+    return (IPP_ERROR);
+
+  switch (ipp->state)
+  {
+    case IPP_IDLE :
+        break;
+
+    case IPP_HEADER :
+       /*
+        * Send the request header...
+       */
+
+        bufptr = buffer;
+
+       *bufptr++ = 1;
+       *bufptr++ = 0;
+       *bufptr++ = ipp->request.any.op_status >> 8;
+       *bufptr++ = ipp->request.any.op_status;
+       *bufptr++ = ipp->request.any.request_id >> 24;
+       *bufptr++ = ipp->request.any.request_id >> 16;
+       *bufptr++ = ipp->request.any.request_id >> 8;
+       *bufptr++ = ipp->request.any.request_id;
+
+        if (httpWrite(http, buffer, bufptr - buffer) < 0)
+         return (IPP_ERROR);
+
+        ipp->state   = IPP_ATTRIBUTE;
+       ipp->current = ipp->attrs;
+       ipp->curtag  = IPP_TAG_ZERO;
+
+       /*
+        * If blocking is disabled, stop here...
+       */
+
+        if (!http->blocking)
+         break;
+
+    case IPP_ATTRIBUTE :
+        while (ipp->current != NULL)
+       {
+        /*
+         * Write this attribute...
+         */
+
+         bufptr = buffer;
+         attr   = ipp->current;
+
+         ipp->current = ipp->current->next;
+
+          if (ipp->curtag != attr->group_tag)
+         {
+          /*
+           * Send a group operation tag...
+           */
+
+           *bufptr++   = attr->group_tag;
+           ipp->curtag = attr->group_tag;
+         }
+
+          n = strlen(attr->name);
+          *bufptr++ = attr->value_tag;
+         *bufptr++ = n >> 8;
+         *bufptr++ = n;
+         memcpy(bufptr, attr->name, n);
+         bufptr += n;
+
+         switch (attr->value_tag)
+         {
+           case IPP_TAG_INTEGER :
+           case IPP_TAG_ENUM :
+               for (i = 0; i < attr->num_values; i ++)
+               {
+                 if (i)
+                 {
+                  /*
+                   * Arrays and sets are done by sending additional
+                   * values with a zero-length name...
+                   */
+
+                    *bufptr++ = attr->value_tag;
+                   *bufptr++ = 0;
+                   *bufptr++ = 0;
+                 }
+
+                 *bufptr++ = 0;
+                 *bufptr++ = 4;
+                 *bufptr++ = attr->values[i].integer >> 24;
+                 *bufptr++ = attr->values[i].integer >> 16;
+                 *bufptr++ = attr->values[i].integer >> 8;
+                 *bufptr++ = attr->values[i].integer;
+               }
+               break;
+
+           case IPP_TAG_BOOLEAN :
+               for (i = 0; i < attr->num_values; i ++)
+               {
+                 if (i)
+                 {
+                  /*
+                   * Arrays and sets are done by sending additional
+                   * values with a zero-length name...
+                   */
+
+                    *bufptr++ = attr->value_tag;
+                   *bufptr++ = 0;
+                   *bufptr++ = 0;
+                 }
+
+                 *bufptr++ = 0;
+                 *bufptr++ = 1;
+                 *bufptr++ = attr->values[i].boolean;
+               }
+               break;
+
+           case IPP_TAG_TEXT :
+           case IPP_TAG_NAME :
+           case IPP_TAG_KEYWORD :
+           case IPP_TAG_STRING :
+           case IPP_TAG_URI :
+           case IPP_TAG_URISCHEME :
+           case IPP_TAG_CHARSET :
+           case IPP_TAG_LANGUAGE :
+           case IPP_TAG_MIMETYPE :
+               for (i = 0; i < attr->num_values; i ++)
+               {
+                 if (i)
+                 {
+                  /*
+                   * Arrays and sets are done by sending additional
+                   * values with a zero-length name...
+                   */
+
+                    *bufptr++ = attr->value_tag;
+                   *bufptr++ = 0;
+                   *bufptr++ = 0;
+                 }
+
+                  n = strlen(attr->values[i].string);
+                 *bufptr++ = n >> 8;
+                 *bufptr++ = n;
+                 memcpy(bufptr, attr->values[i].string, n);
+                 bufptr += n;
+               }
+               break;
+
+           case IPP_TAG_DATE :
+               for (i = 0; i < attr->num_values; i ++)
+               {
+                 if (i)
+                 {
+                  /*
+                   * Arrays and sets are done by sending additional
+                   * values with a zero-length name...
+                   */
+
+                    *bufptr++ = attr->value_tag;
+                   *bufptr++ = 0;
+                   *bufptr++ = 0;
+                 }
+
+                 *bufptr++ = 0;
+                 *bufptr++ = 11;
+                 memcpy(bufptr, attr->values[i].date, 11);
+                 bufptr += 11;
+               }
+               break;
+
+           case IPP_TAG_RESOLUTION :
+               for (i = 0; i < attr->num_values; i ++)
+               {
+                 if (i)
+                 {
+                  /*
+                   * Arrays and sets are done by sending additional
+                   * values with a zero-length name...
+                   */
+
+                    *bufptr++ = attr->value_tag;
+                   *bufptr++ = 0;
+                   *bufptr++ = 0;
+                 }
+
+                 *bufptr++ = 0;
+                 *bufptr++ = 9;
+                 *bufptr++ = attr->values[i].resolution.xres >> 24;
+                 *bufptr++ = attr->values[i].resolution.xres >> 16;
+                 *bufptr++ = attr->values[i].resolution.xres >> 8;
+                 *bufptr++ = attr->values[i].resolution.xres;
+                 *bufptr++ = attr->values[i].resolution.yres >> 24;
+                 *bufptr++ = attr->values[i].resolution.yres >> 16;
+                 *bufptr++ = attr->values[i].resolution.yres >> 8;
+                 *bufptr++ = attr->values[i].resolution.yres;
+                 *bufptr++ = attr->values[i].resolution.units;
+               }
+               break;
+
+           case IPP_TAG_RANGE :
+               for (i = 0; i < attr->num_values; i ++)
+               {
+                 if (i)
+                 {
+                  /*
+                   * Arrays and sets are done by sending additional
+                   * values with a zero-length name...
+                   */
+
+                    *bufptr++ = attr->value_tag;
+                   *bufptr++ = 0;
+                   *bufptr++ = 0;
+                 }
+
+                 *bufptr++ = 0;
+                 *bufptr++ = 8;
+                 *bufptr++ = attr->values[i].range.lower >> 24;
+                 *bufptr++ = attr->values[i].range.lower >> 16;
+                 *bufptr++ = attr->values[i].range.lower >> 8;
+                 *bufptr++ = attr->values[i].range.lower;
+                 *bufptr++ = attr->values[i].range.upper >> 24;
+                 *bufptr++ = attr->values[i].range.upper >> 16;
+                 *bufptr++ = attr->values[i].range.upper >> 8;
+                 *bufptr++ = attr->values[i].range.upper;
+               }
+               break;
+
+           case IPP_TAG_TEXTLANG :
+           case IPP_TAG_NAMELANG :
+               for (i = 0; i < attr->num_values; i ++)
+               {
+                 if (i)
+                 {
+                  /*
+                   * Arrays and sets are done by sending additional
+                   * values with a zero-length name...
+                   */
+
+                    *bufptr++ = attr->value_tag;
+                   *bufptr++ = 0;
+                   *bufptr++ = 0;
+                 }
+
+                  n = strlen(attr->values[i].lstring.charset);
+                 *bufptr++ = n >> 8;
+                 *bufptr++ = n;
+                 memcpy(bufptr, attr->values[i].lstring.charset, n);
+                 bufptr += n;
+
+                  n = strlen((char *)attr->values[i].lstring.string);
+                 *bufptr++ = n >> 8;
+                 *bufptr++ = n;
+                 memcpy(bufptr, attr->values[i].lstring.string, n);
+                 bufptr += n;
+               }
+               break;
+         }
+
+         /*
+         * Write the data out...
+         */
+
+          if (httpWrite(http, buffer, bufptr - buffer) < 0)
+           return (IPP_ERROR);
+
+        /*
+          * If blocking is disabled, stop here...
+         */
+
+          if (!http->blocking)
+           break;
+       }
+
+       if (ipp->current == NULL)
+       {
+         /*
+         * Done with all of the attributes; add the end-of-attributes tag...
+         */
+
+          buffer[0] = IPP_TAG_END;
+         if (httpWrite(http, buffer, 1) < 0)
+           return (IPP_ERROR);
+
+         ipp->state = IPP_DATA;
+       }
+        break;
+
+    case IPP_DATA :
+        break;
+  }
+
+  return (ipp->state);
 }
 
 
@@ -726,5 +1259,5 @@ add_attr(ipp_t *ipp,                       /* I - IPP request */
 
 
 /*
- * End of "$Id: ipp.c,v 1.3 1999/01/28 22:00:45 mike Exp $".
+ * End of "$Id: ipp.c,v 1.4 1999/02/05 17:40:52 mike Exp $".
  */
index 77841a80dd4d151d9ccef4b13faf5710c6ac2379..58e9dfadc56020bc88a971cbd3cfa72e68db6a83 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: ipp.h,v 1.3 1999/01/28 22:00:45 mike Exp $"
+ * "$Id: ipp.h,v 1.4 1999/02/05 17:40:52 mike Exp $"
  *
  *   Internet Printing Protocol definitions for the Common UNIX Printing
  *   System (CUPS).
@@ -49,6 +49,14 @@ extern "C" {
 #  define IPP_VERSION          "\001\000"
 
 
+/*
+ * Common limits...
+ */
+
+#  define IPP_MAX_NAME         128
+#  define IPP_MAX_VALUES       100
+
+
 /*
  * Types and structures...
  */
@@ -138,17 +146,22 @@ typedef enum                      /**** Job States.... */
   IPP_JOB_CANCELED,
   IPP_JOB_ABORTED,
   IPP_JOB_COMPLETED
-} ipp_jobstate_t;
+} ipp_jstate_t;
+
+typedef enum                   /**** Printer States.... */
+{
+  IPP_PRINTER_IDLE = 3,
+  IPP_PRINTER_PROCESSING,
+  IPP_PRINTER_STOPPED
+} ipp_pstate_t;
 
 typedef enum                   /**** IPP states... ****/
 {
-  IPP_IDLE,
-  IPP_REQUEST_HEADER,
-  IPP_REQUEST_ATTR,
-  IPP_REQUEST_DATA,
-  IPP_RESPONSE_HEADER,
-  IPP_RESPONSE_ATTR,
-  IPP_RESPONSE_DATA
+  IPP_ERROR = -1,              /* An error occurred */
+  IPP_IDLE,                    /* Nothing is happening/request completed */
+  IPP_HEADER,                  /* The request header needs to be sent/received */
+  IPP_ATTRIBUTE,               /* One or more attributes need to be sent/received */
+  IPP_DATA                     /* IPP request data needs to be sent/received */
 } ipp_state_t;
 
 typedef enum                   /**** IPP operations... ****/
@@ -163,7 +176,13 @@ typedef enum                       /**** IPP operations... ****/
   IPP_GET_JOB_ATTRIBUTES,
   IPP_GET_JOBS,
   IPP_GET_PRINTER_ATTRIBUTES,
-  IPP_PRIVATE = 0x4000
+  IPP_PRIVATE = 0x4000,
+  CUPS_GET_PRINTERS,
+  CUPS_ADD_PRINTER,
+  CUPS_DELETE_PRINTER,
+  CUPS_GET_CLASSES,
+  CUPS_ADD_CLASS,
+  CUPS_DELETE_CLASS
 } ipp_op_t;
 
 typedef enum                   /**** IPP status codes... ****/
@@ -202,6 +221,13 @@ typedef unsigned int uint; /**** Unsigned 32-bit integer ****/
 
 typedef union                  /**** Request Header ****/
 {
+  struct                       /* Any Header */
+  {
+    uchar      version[2];     /* Protocol version number */
+    int                op_status;      /* Operation ID or status code*/
+    int                request_id;     /* Request ID */
+  }            any;
+
   struct                       /* Operation Header */
   {
     uchar      version[2];     /* Protocol version number */
@@ -266,6 +292,7 @@ typedef struct                      /**** Request State ****/
   ipp_attribute_t *attrs,      /* Attributes */
                *last,          /* Last attribute in list */
                *current;       /* Current attribute (for read/write) */
+  ipp_tag_t    curtag;         /* Current attribute group tag */
 } ipp_t;
 
 
@@ -289,9 +316,9 @@ extern void         ippDelete(ipp_t *ipp);
 extern ipp_attribute_t *ippFindAttribute(ipp_t *ipp, char *name);
 extern size_t          ippLength(ipp_t *ipp);
 extern ipp_t           *ippNew(void);
-extern int             ippRead(http_t *http, ipp_t *ipp);
+extern ipp_state_t     ippRead(http_t *http, ipp_t *ipp);
 extern uchar           *ippTimeToDate(time_t t);
-extern int             ippWrite(http_t *http, ipp_t *ipp);
+extern ipp_state_t     ippWrite(http_t *http, ipp_t *ipp);
 
 /*
  * C++ magic...
@@ -303,5 +330,5 @@ extern int          ippWrite(http_t *http, ipp_t *ipp);
 #endif /* !_CUPS_IPP_H_ */
 
 /*
- * End of "$Id: ipp.h,v 1.3 1999/01/28 22:00:45 mike Exp $".
+ * End of "$Id: ipp.h,v 1.4 1999/02/05 17:40:52 mike Exp $".
  */
index d5018eaa8b7603396b0c651037cc3b2f353b84e3..9ee85c1522bbc1686e28048742c76cd2eb884952 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: mark.c,v 1.4 1999/01/27 18:31:56 mike Exp $"
+ * "$Id: mark.c,v 1.5 1999/02/05 17:40:53 mike Exp $"
  *
  *   Option marking routines for the Common UNIX Printing System (CUPS).
  *
@@ -40,6 +40,7 @@
  */
 
 #include "ppd.h"
+#include "string.h"
 
 
 /*
@@ -368,5 +369,5 @@ ppd_default(ppd_option_t *o)        /* I - Option to default */
 
 
 /*
- * End of "$Id: mark.c,v 1.4 1999/01/27 18:31:56 mike Exp $".
+ * End of "$Id: mark.c,v 1.5 1999/02/05 17:40:53 mike Exp $".
  */
index 37e65f933634d37201f93e939447a1f95a017599..27d929bf295f1134a82c2ba8e004faaa971260d4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: mime.c,v 1.6 1999/02/01 22:08:39 mike Exp $"
+ * "$Id: mime.c,v 1.7 1999/02/05 17:40:53 mike Exp $"
  *
  *   MIME database file routines for the Common UNIX Printing System (CUPS).
  *
  * Revision History:
  *
  *   $Log: mime.c,v $
+ *   Revision 1.7  1999/02/05 17:40:53  mike
+ *   Added IPP client read/write code.
+ *
+ *   Added string functions missing from some UNIXs.
+ *
+ *   Added option parsing functions.
+ *
+ *   Added IPP convenience functions (not implemented yet).
+ *
+ *   Updated source files to use local string.h as needed (for
+ *   missing string functions)
+ *
  *   Revision 1.6  1999/02/01 22:08:39  mike
  *   Restored original directory-scanning functionality of mimeLoad().
  *
  * Include necessary headers...
  */
 
+#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
+
+#include "string.h"
 #include "mime.h"
-#include <config.h>
 
 #ifdef HAVE_SYS_DIR_H
 #  include <sys/types.h>
@@ -431,7 +447,7 @@ load_convs(mime_t *mime,            /* I - MIME database */
     *temp = '\0';
 
    /*
-    * Add the filter to the MIME database; if "type" is "*" (as in "super/*")
+    * Add the filter to the MIME database; if "type" is "*" (as in "super / *")
     * then add a filter for each super type listed in the database.
     */
 
@@ -490,5 +506,5 @@ delete_rules(mime_magic_t *rules)   /* I - Rules to free */
 
 
 /*
- * End of "$Id: mime.c,v 1.6 1999/02/01 22:08:39 mike Exp $".
+ * End of "$Id: mime.c,v 1.7 1999/02/05 17:40:53 mike Exp $".
  */
index 654eb1360abaf70259eaf63bf633b844b58b8d43..6d43aeeeac02b85d178bae6d785c188b8190d051 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: mime.h,v 1.3 1999/01/24 14:18:43 mike Exp $"
+ * "$Id: mime.h,v 1.4 1999/02/05 17:40:53 mike Exp $"
  *
  *   MIME type/conversion database definitions for the Common UNIX Printing System (CUPS).
  *
 #ifndef _MIME_H_
 #  define _MIME_H_
 
-/*
- * Include necessary headers...
- */
-
-#  include <stdio.h>
-#  include <stdlib.h>
-#  include <string.h>
-#  include <ctype.h>
-
-
 /*
  * C++ magic...
  */
@@ -123,7 +113,7 @@ typedef struct                              /**** MIME Database ****/
  */
 
 extern void            mimeDelete(mime_t *mime);
-#define mimeLoad(pathname)     mimeMerge(NULL, (pathname));
+#define mimeLoad(pathname)     mimeMerge((mime_t *)0, (pathname));
 extern mime_t          *mimeMerge(mime_t *mime, char *pathname);
 extern mime_t          *mimeNew(void);
 
@@ -143,5 +133,5 @@ extern mime_filter_t        *mimeFilter(mime_t *mime, mime_type_t *src, mime_type_t *ds
 #endif /* !_MIME_H_ */
 
 /*
- * End of "$Id: mime.h,v 1.3 1999/01/24 14:18:43 mike Exp $".
+ * End of "$Id: mime.h,v 1.4 1999/02/05 17:40:53 mike Exp $".
  */
diff --git a/cups/options.c b/cups/options.c
new file mode 100644 (file)
index 0000000..b1ac5bc
--- /dev/null
@@ -0,0 +1,248 @@
+/*
+ * "$Id: options.c,v 1.1 1999/02/05 17:40:54 mike Exp $"
+ *
+ *   Option routines for the Common UNIX Printing System (CUPS).
+ *
+ *   Copyright 1997-1999 by Easy Software Products.
+ *
+ *   These coded instructions, statements, and computer programs are the
+ *   property of Easy Software Products and are protected by Federal
+ *   copyright law.  Distribution and use rights are outlined in the file
+ *   "LICENSE.txt" which should have been included with this file.  If this
+ *   file is missing or damaged please contact Easy Software Products
+ *   at:
+ *
+ *       Attn: CUPS Licensing Information
+ *       Easy Software Products
+ *       44145 Airport View Drive, Suite 204
+ *       Hollywood, Maryland 20636-3111 USA
+ *
+ *       Voice: (301) 373-9603
+ *       EMail: cups-info@cups.org
+ *         WWW: http://www.cups.org
+ *
+ * Contents:
+ *
+ *   cupsAddOption()    - Add an option to an option array.
+ *   cupsFreeOptions()  - Free all memory used by options.
+ *   cupsGetOption()    - Get an option value.
+ *   cupsParseOptions() - Parse options from a command-line argument.
+ */
+
+/*
+ * Include necessary headers...
+ */
+
+#include "cups.h"
+#include <stdlib.h>
+#include <ctype.h>
+#include "string.h"
+
+
+/*
+ * 'cupsAddOption()' - Add an option to an option array.
+ */
+
+int                                            /* O - Number of options */
+cupsAddOption(char          *name,             /* I - Name of option */
+              char          *value,            /* I - Value of option */
+             int           num_options,        /* I - Number of options */
+              cups_option_t **options)         /* IO - Pointer to options */
+{
+  cups_option_t        *temp;                          /* Pointer to new option */
+
+
+  if (name == NULL || value == NULL || options == NULL)
+    return (0);
+
+  if (num_options == 0)
+    temp = (cups_option_t *)malloc(sizeof(cups_option_t));
+  else
+    temp = (cups_option_t *)realloc(*options, sizeof(cups_option_t) *
+                                              (num_options + 1));
+
+  if (temp == NULL)
+    return (0);
+
+  *options = temp;
+  temp     += num_options;
+
+  temp->name  = strdup(name);
+  temp->value = strdup(value);
+
+  return (num_options + 1);
+}
+
+
+/*
+ * 'cupsFreeOptions()' - Free all memory used by options.
+ */
+
+void
+cupsFreeOptions(int           num_options,     /* I - Number of options */
+                cups_option_t *options)                /* I - Pointer to options */
+{
+  int  i;                                      /* Looping var */
+
+
+  if (num_options == 0 || options == NULL)
+    return;
+
+  for (i = 0; i < num_options; i ++)
+  {
+    free(options[i].name);
+    free(options[i].value);
+  }
+
+  free(options);
+}
+
+
+/*
+ * 'cupsGetOption()' - Get an option value.
+ */
+
+char *                                 /* O - Option value or NULL */
+cupsGetOption(char          *name,     /* I - Name of option */
+              int           num_options,/* I - Number of options */
+              cups_option_t *options)  /* I - Options */
+{
+  int  i;                              /* Looping var */
+
+
+  if (name == NULL || num_options == 0 || options == NULL)
+    return (NULL);
+
+  for (i = 0; i < num_options; i ++)
+    if (strcmp(options[i].name, name) == 0)
+      return (options[i].value);
+
+  return (NULL);
+}
+
+
+/*
+ * 'cupsParseOptions()' - Parse options from a command-line argument.
+ */
+
+int                                            /* O - Number of options found */
+cupsParseOptions(char          *arg,           /* I - Argument to parse */
+                 cups_option_t **options)      /* O - Options found */
+{
+  int  num_options;                            /* Number of options */
+  char *copyarg,                               /* Copy of input string */
+       *ptr,                                   /* Pointer into string */
+       *name,                                  /* Pointer to name */
+       *value;                                 /* Pointer to value */
+
+
+  if (arg == NULL || options == NULL)
+    return (0);
+
+ /*
+  * Make a copy of the argument string and then divide it up...
+  */
+
+  copyarg     = strdup(arg);
+  num_options = 0;
+  ptr         = copyarg;
+
+  while (*ptr != '\0')
+  {
+   /*
+    * Get the name up to a SPACE, =, or end-of-string...
+    */
+
+    name = ptr;
+    while (!isspace(*ptr) && *ptr != '=' && *ptr != '\0')
+      ptr ++;
+
+   /*
+    * Skip trailing spaces...
+    */
+
+    while (isspace(*ptr))
+      *ptr++ = '\0';
+
+    if (*ptr != '=')
+    {
+     /*
+      * Start of another option...
+      */
+
+      num_options = cupsAddOption(name, "", num_options, options);
+      continue;
+    }
+
+   /*
+    * Remove = and parse the value...
+    */
+
+    *ptr++ = '\0';
+
+    if (*ptr == '\'')
+    {
+     /*
+      * Quoted string constant...
+      */
+
+      ptr ++;
+      value = ptr;
+
+      while (*ptr != '\'' && *ptr != '\0')
+        ptr ++;
+
+      if (*ptr != '\0')
+        *ptr++ = '\0';
+    }
+    else if (*ptr == '\"')
+    {
+     /*
+      * Double-quoted string constant...
+      */
+
+      ptr ++;
+      value = ptr;
+
+      while (*ptr != '\"' && *ptr != '\0')
+        ptr ++;
+
+      if (*ptr != '\0')
+        *ptr++ = '\0';
+    }
+    else
+    {
+     /*
+      * Normal space-delimited string...
+      */
+
+      value = ptr;
+
+      while (!isspace(*ptr) && *ptr != '\0')
+       ptr ++;
+
+      while (isspace(*ptr))
+        *ptr++ = '\0';
+    }
+
+   /*
+    * Add the string value...
+    */
+
+    num_options = cupsAddOption(name, value, num_options, options);
+  }
+
+ /*
+  * Free the copy of the argument we made and return the number of options
+  * found.
+  */
+
+  free(copyarg);
+
+  return (num_options);
+}
+
+
+/*
+ * End of "$Id: options.c,v 1.1 1999/02/05 17:40:54 mike Exp $".
+ */
index 3967d5f41f6c5dfd99edee5fa40653aeafce3d10..468be5907da7ef23f943430ecd9956ce4604bff2 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: page.c,v 1.3 1999/01/24 14:18:43 mike Exp $"
+ * "$Id: page.c,v 1.4 1999/02/05 17:40:54 mike Exp $"
  *
  *   Page size functions for the Common UNIX Printing System (CUPS).
  *
@@ -35,6 +35,7 @@
  */
 
 #include "ppd.h"
+#include "string.h"
 
 
 /*
@@ -96,5 +97,5 @@ ppdPageLength(ppd_file_t *ppd,        /* I - Size name */
 
 
 /*
- * End of "$Id: page.c,v 1.3 1999/01/24 14:18:43 mike Exp $".
+ * End of "$Id: page.c,v 1.4 1999/02/05 17:40:54 mike Exp $".
  */
index f0bb6b07109573e44dad5fc1f42b32b5727a2db5..b544af4359345ed134bb9c28a36959acd113aa86 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: ppd.c,v 1.5 1999/01/30 13:25:57 mike Exp $"
+ * "$Id: ppd.c,v 1.6 1999/02/05 17:40:54 mike Exp $"
  *
  *   PPD file routines for the Common UNIX Printing System (CUPS).
  *
  */
 
 #include "ppd.h"
+#include <stdlib.h>
 #include <ctype.h>
-/*#define DEBUG*/
+#include "string.h"
 
 
 /*
  * Definitions...
  */
 
-#if defined(WIN32) || defined(OS2)
+#if defined(WIN32) || defined(__EMX__)
 #  define READ_BINARY  "rb"            /* Open a binary file for reading */
 #  define WRITE_BINARY "wb"            /* Open a binary file for writing */
 #else
 #  define READ_BINARY  "r"             /* Open a binary file for reading */
 #  define WRITE_BINARY "w"             /* Open a binary file for writing */
-#endif /* WIN32 || OS2 */
+#endif /* WIN32 || __EMX__ */
 
 #define PPD_KEYWORD    1               /* Line contained a keyword */
 #define PPD_OPTION     2               /* Line contained an option name */
@@ -1319,5 +1320,5 @@ ppd_decode(unsigned char *string) /* I - String to decode */
 
 
 /*
- * End of "$Id: ppd.c,v 1.5 1999/01/30 13:25:57 mike Exp $".
+ * End of "$Id: ppd.c,v 1.6 1999/02/05 17:40:54 mike Exp $".
  */
index f6653d64435a726e143710906a3444ee0436a11f..4270d4e4a2f3a006f76f80e7a1bffac29d309ac8 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: ppd.h,v 1.4 1999/01/27 18:31:57 mike Exp $"
+ * "$Id: ppd.h,v 1.5 1999/02/05 17:40:55 mike Exp $"
  *
  *   PostScript Printer Description definitions for the Common UNIX Printing
  *   System (CUPS).
@@ -33,8 +33,6 @@
  */
 
 #  include <stdio.h>
-#  include <stdlib.h>
-#  include <string.h>
 
 
 /*
@@ -215,5 +213,5 @@ extern float                ppdPageWidth(ppd_file_t *ppd, char *name);
 #endif /* !_CUPS_PPD_H_ */
 
 /*
- * End of "$Id: ppd.h,v 1.4 1999/01/27 18:31:57 mike Exp $".
+ * End of "$Id: ppd.h,v 1.5 1999/02/05 17:40:55 mike Exp $".
  */
diff --git a/cups/string.c b/cups/string.c
new file mode 100644 (file)
index 0000000..0cd5faf
--- /dev/null
@@ -0,0 +1,125 @@
+/*
+ * "$Id: string.c,v 1.1 1999/02/05 17:40:55 mike Exp $"
+ *
+ *   String functions for the Common UNIX Printing System (CUPS).
+ *
+ *   Copyright 1997-1999 by Easy Software Products.
+ *
+ *   These coded instructions, statements, and computer programs are the
+ *   property of Easy Software Products and are protected by Federal
+ *   copyright law.  Distribution and use rights are outlined in the file
+ *   "LICENSE.txt" which should have been included with this file.  If this
+ *   file is missing or damaged please contact Easy Software Products
+ *   at:
+ *
+ *       Attn: CUPS Licensing Information
+ *       Easy Software Products
+ *       44145 Airport View Drive, Suite 204
+ *       Hollywood, Maryland 20636-3111 USA
+ *
+ *       Voice: (301) 373-9603
+ *       EMail: cups-info@cups.org
+ *         WWW: http://www.cups.org
+ *
+ * Contents:
+ *
+ *   strdup()      - Duplicate a string.
+ *   strcasecmp()  - Do a case-insensitive comparison.
+ *   strncasecmp() - Do a case-insensitive comparison on up to N chars.
+ */
+
+/*
+ * Include necessary headers...
+ */
+
+#include "string.h"
+
+
+/*
+ * 'strdup()' - Duplicate a string.
+ */
+
+#  ifndef HAVE_STRDUP
+char *                 /* O - New string pointer */
+strdup(const char *s)  /* I - String to duplicate */
+{
+  char *t;             /* New string pointer */
+
+
+  if (s == NULL)
+    return (NULL);
+
+  if ((t = malloc(strlen(s) + 1)) == NULL)
+    return (NULL);
+
+  return (strcpy(t, s));
+}
+#  endif /* !HAVE_STRDUP */
+
+
+/*
+ * 'strcasecmp()' - Do a case-insensitive comparison.
+ */
+
+#  ifndef HAVE_STRCASECMP
+int                            /* O - Result of comparison (-1, 0, or 1) */
+strcasecmp(const char *s,      /* I - First string */
+           const char *t)      /* I - Second string */
+{
+  while (*s != '\0' && *t != '\0')
+  {
+    if (tolower(*s) < tolower(*t))
+      return (-1);
+    else if (tolower(*s) > tolower(*t))
+      return (1);
+
+    s ++;
+    t ++;
+  };
+
+  if (*s == '\0' && *t == '\0')
+    return (0);
+  else if (*s != '\0')
+    return (1);
+  else
+    return (-1);
+}
+#  endif /* !HAVE_STRCASECMP */
+
+/*
+ * 'strncasecmp()' - Do a case-insensitive comparison on up to N chars.
+ */
+
+#  ifndef HAVE_STRNCASECMP
+int                            /* O - Result of comparison (-1, 0, or 1) */
+strncasecmp(const char *s,     /* I - First string */
+            const char *t,     /* I - Second string */
+           size_t     n)       /* I - Maximum number of characters to compare */
+{
+  while (*s != '\0' && *t != '\0' && n > 0)
+  {
+    if (tolower(*s) < tolower(*t))
+      return (-1);
+    else if (tolower(*s) > tolower(*t))
+      return (1);
+
+    s ++;
+    t ++;
+    n --;
+  };
+
+  if (n == 0)
+    return (0);
+  else if (*s == '\0' && *t == '\0')
+    return (0);
+  else if (*s != '\0')
+    return (1);
+  else
+    return (-1);
+}
+#  endif /* !HAVE_STRNCASECMP */
+
+
+/*
+ * End of "$Id: string.c,v 1.1 1999/02/05 17:40:55 mike Exp $".
+ */
diff --git a/cups/string.h b/cups/string.h
new file mode 100644 (file)
index 0000000..e0d0c9b
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * "$Id: string.h,v 1.1 1999/02/05 17:40:56 mike Exp $"
+ *
+ *   String definitions for the Common UNIX Printing System (CUPS).
+ *
+ *   Copyright 1997-1999 by Easy Software Products.
+ *
+ *   These coded instructions, statements, and computer programs are the
+ *   property of Easy Software Products and are protected by Federal
+ *   copyright law.  Distribution and use rights are outlined in the file
+ *   "LICENSE.txt" which should have been included with this file.  If this
+ *   file is missing or damaged please contact Easy Software Products
+ *   at:
+ *
+ *       Attn: CUPS Licensing Information
+ *       Easy Software Products
+ *       44145 Airport View Drive, Suite 204
+ *       Hollywood, Maryland 20636-3111 USA
+ *
+ *       Voice: (301) 373-9603
+ *       EMail: cups-info@cups.org
+ *         WWW: http://www.cups.org
+ */
+
+#ifndef _CUPS_STRING_H_
+#  define _CUPS_STRING_H_
+
+/*
+ * Include necessary headers...
+ */
+
+#  include <config.h>
+#  include <string.h>
+
+
+/*
+ * Stuff for WIN32 and OS/2...
+ */
+
+#  if defined(WIN32) || defined(__EMX__)
+#    define strcasecmp stricmp
+#    define strncasecmp        strnicmp
+#  endif /* WIN32 || __EMX__ */
+
+
+/*
+ * Prototypes...
+ */
+
+#  ifndef HAVE_STRDUP
+extern char    *strdup(const char *);
+#  endif /* !HAVE_STRDUP */
+
+#  ifndef HAVE_STRCASECMP
+extern int     strcasecmp(const char *, const char *);
+#  endif /* !HAVE_STRCASECMP */
+
+#  ifndef HAVE_STRNCASECMP
+extern int     strncasecmp(const char *, const char *, size_t n);
+#  endif /* !HAVE_STRNCASECMP */
+
+#endif /* !_CUPS_STRING_H_ */
+
+/*
+ * End of "$Id: string.h,v 1.1 1999/02/05 17:40:56 mike Exp $".
+ */
index 0f73e9c76d2da1119f04eaa467a2b9b088fb7672..36f2129bd57cfd0fd637a601e55b0cf06b5d21a6 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: testhttp.c,v 1.3 1999/02/01 22:06:37 mike Exp $"
+ * "$Id: testhttp.c,v 1.4 1999/02/05 17:40:56 mike Exp $"
  *
  *   HTTP test program for the Common UNIX Printing System (CUPS).
  *
@@ -30,7 +30,7 @@
  * Include necessary headers...
  */
 
-#include <config.h>
+#include <stdio.h>
 #include "http.h"
 
 
@@ -102,5 +102,5 @@ main(int  argc,                     /* I - Number of command-line arguments */
 
 
 /*
- * End of "$Id: testhttp.c,v 1.3 1999/02/01 22:06:37 mike Exp $".
+ * End of "$Id: testhttp.c,v 1.4 1999/02/05 17:40:56 mike Exp $".
  */
index e177dcc94d626ef6bb7ad055c04234badac9a689..fb58e4c46d091211ba2305c6859e7c995bd39abd 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: testmime.c,v 1.3 1999/01/24 14:18:43 mike Exp $"
+ * "$Id: testmime.c,v 1.4 1999/02/05 17:40:56 mike Exp $"
  *
  *   MIME test program for the Common UNIX Printing System (CUPS).
  *
@@ -30,7 +30,7 @@
  * Include necessary headers...
  */
 
-#include <config.h>
+#include <stdio.h>
 #include "mime.h"
 
 
@@ -195,5 +195,5 @@ print_rules(mime_magic_t *rules)    /* I - Rules to print */
 
 
 /*
- * End of "$Id: testmime.c,v 1.3 1999/01/24 14:18:43 mike Exp $".
+ * End of "$Id: testmime.c,v 1.4 1999/02/05 17:40:56 mike Exp $".
  */
index e8ea744f5f6f6f52f2cde4b82740a7ae3c7cfcc7..b2da6455b2349c92d9c17d889e95729cdc994ed0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: testppd.c,v 1.4 1999/01/27 18:31:57 mike Exp $"
+ * "$Id: testppd.c,v 1.5 1999/02/05 17:40:57 mike Exp $"
  *
  *   PPD test program for the Common UNIX Printing System (CUPS).
  *
@@ -32,8 +32,8 @@
  * Include necessary headers...
  */
 
-#include <config.h>
 #include "ppd.h"
+#include "string.h"
 
 
 /*
@@ -181,5 +181,5 @@ main(int  argc,                     /* I - Number of command-line arguments */
 
 
 /*
- * End of "$Id: testppd.c,v 1.4 1999/01/27 18:31:57 mike Exp $".
+ * End of "$Id: testppd.c,v 1.5 1999/02/05 17:40:57 mike Exp $".
  */
index b81b165d97e118c0a1c786572487deda6a707960..a283d1c9d093566a8711c17a2f2f20ba396f6341 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: type.c,v 1.3 1999/01/24 14:18:43 mike Exp $"
+ * "$Id: type.c,v 1.4 1999/02/05 17:40:57 mike Exp $"
  *
  *   MIME typing routines for the Common UNIX Printing System (CUPS).
  *
  * Revision History:
  *
  *   $Log: type.c,v $
+ *   Revision 1.4  1999/02/05 17:40:57  mike
+ *   Added IPP client read/write code.
+ *
+ *   Added string functions missing from some UNIXs.
+ *
+ *   Added option parsing functions.
+ *
+ *   Added IPP convenience functions (not implemented yet).
+ *
+ *   Updated source files to use local string.h as needed (for
+ *   missing string functions)
+ *
  *   Revision 1.3  1999/01/24 14:18:43  mike
  *   Check-in prior to CVS use.
  *
  * Include necessary headers...
  */
 
-#include "mime.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
 #include <locale.h>
 
+#include "string.h"
+#include "mime.h"
+
 
 /*
  * Local functions...
@@ -614,8 +631,8 @@ compare(mime_type_t **t0,   /* I - First type */
   int  i;                      /* Result of comparison */
 
 
-  if ((i = strcmp((*t0)->super, (*t1)->super)) == 0)
-    i = strcmp((*t0)->type, (*t1)->type);
+  if ((i = strcasecmp((*t0)->super, (*t1)->super)) == 0)
+    i = strcasecmp((*t0)->type, (*t1)->type);
 
   return (i);
 }
@@ -1018,5 +1035,5 @@ patmatch(char *s, /* I - String to match against */
 
 
 /*
- * End of "$Id: type.c,v 1.3 1999/01/24 14:18:43 mike Exp $".
+ * End of "$Id: type.c,v 1.4 1999/02/05 17:40:57 mike Exp $".
  */
diff --git a/cups/util.c b/cups/util.c
new file mode 100644 (file)
index 0000000..1244c98
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * "$Id: util.c,v 1.1 1999/02/05 17:40:58 mike Exp $"
+ *
+ *   Printing utilities for the Common UNIX Printing System (CUPS).
+ *
+ *   Copyright 1997-1999 by Easy Software Products.
+ *
+ *   These coded instructions, statements, and computer programs are the
+ *   property of Easy Software Products and are protected by Federal
+ *   copyright law.  Distribution and use rights are outlined in the file
+ *   "LICENSE.txt" which should have been included with this file.  If this
+ *   file is missing or damaged please contact Easy Software Products
+ *   at:
+ *
+ *       Attn: CUPS Licensing Information
+ *       Easy Software Products
+ *       44145 Airport View Drive, Suite 204
+ *       Hollywood, Maryland 20636-3111 USA
+ *
+ *       Voice: (301) 373-9603
+ *       EMail: cups-info@cups.org
+ *         WWW: http://www.cups.org
+ *
+ * Contents:
+ *
+ */
+
+/*
+ * Include necessary headers...
+ */
+
+#include "cups.h"
+
+
+int
+cupsCancelJob(char *printer,
+              int  job)
+{
+}
+
+
+int
+cupsGetClasses(char ***classes)
+{
+}
+
+
+char *
+cupsGetPPD(char *printer)
+{
+}
+
+
+int
+cupsGetPrinters(char ***printers)
+{
+}
+
+
+int
+cupsPrintFile(char          *printer,
+              char          *filename,
+              int           num_options,
+             cups_option_t *options)
+{
+}
+
+
+/*
+ * End of "$Id: util.c,v 1.1 1999/02/05 17:40:58 mike Exp $".
+ */