]>
git.ipfire.org Git - thirdparty/cups.git/blob - cgi-bin/var.c
4 * CGI form variable and array functions for CUPS.
6 * Copyright 2007-2014 by Apple Inc.
7 * Copyright 1997-2005 by Easy Software Products.
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
17 * Include necessary headers...
21 #include "cgi-private.h"
22 #include <cups/http.h>
23 #include <cups/md5-private.h>
30 #define CUPS_SID "org.cups.sid"
34 * Data structure to hold all the CGI form variables and arrays...
37 typedef struct /**** Form variable structure ****/
39 const char *name
; /* Name of variable */
40 int nvalues
, /* Number of values */
41 avalues
; /* Number of values allocated */
42 const char **values
; /* Value(s) of variable */
50 static int num_cookies
= 0;/* Number of cookies */
51 static cups_option_t
*cookies
= NULL
;/* Cookies */
52 static int form_count
= 0, /* Form variable count */
53 form_alloc
= 0; /* Number of variables allocated */
54 static _cgi_var_t
*form_vars
= NULL
;
56 static cgi_file_t
*form_file
= NULL
;
64 static void cgi_add_variable(const char *name
, int element
,
66 static int cgi_compare_variables(const _cgi_var_t
*v1
,
67 const _cgi_var_t
*v2
);
68 static _cgi_var_t
*cgi_find_variable(const char *name
);
69 static void cgi_initialize_cookies(void);
70 static int cgi_initialize_get(void);
71 static int cgi_initialize_multipart(const char *boundary
);
72 static int cgi_initialize_post(void);
73 static int cgi_initialize_string(const char *data
);
74 static const char *cgi_passwd(const char *prompt
);
75 static const char *cgi_set_sid(void);
76 static void cgi_sort_variables(void);
77 static void cgi_unlink_file(void);
81 * 'cgiCheckVariables()' - Check for the presence of "required" variables.
83 * Names may be separated by spaces and/or commas.
86 int /* O - 1 if all variables present, 0 otherwise */
87 cgiCheckVariables(const char *names
) /* I - Variables to look for */
89 char name
[255], /* Current variable name */
90 *s
; /* Pointer in string */
91 const char *val
; /* Value of variable */
92 int element
; /* Array element number */
98 while (*names
!= '\0')
100 while (*names
== ' ' || *names
== ',')
103 for (s
= name
; *names
!= '\0' && *names
!= ' ' && *names
!= ','; s
++, names
++)
110 if ((s
= strrchr(name
, '-')) != NULL
)
113 element
= atoi(s
+ 1) - 1;
114 val
= cgiGetArray(name
, element
);
117 val
= cgiGetVariable(name
);
123 return (0); /* Can't be blank, either! */
131 * 'cgiClearVariables()' - Clear all form variables.
135 cgiClearVariables(void)
137 int i
, j
; /* Looping vars */
138 _cgi_var_t
*v
; /* Current variable */
141 fputs("DEBUG: cgiClearVariables called.\n", stderr
);
143 for (v
= form_vars
, i
= form_count
; i
> 0; v
++, i
--)
145 _cupsStrFree(v
->name
);
146 for (j
= 0; j
< v
->nvalues
; j
++)
148 _cupsStrFree(v
->values
[j
]);
158 * 'cgiGetArray()' - Get an element from a form array.
161 const char * /* O - Element value or NULL */
162 cgiGetArray(const char *name
, /* I - Name of array variable */
163 int element
) /* I - Element number (0 to N) */
165 _cgi_var_t
*var
; /* Pointer to variable */
168 if ((var
= cgi_find_variable(name
)) == NULL
)
171 if (element
< 0 || element
>= var
->nvalues
)
174 return (_cupsStrRetain(var
->values
[element
]));
179 * 'cgiGetCookie()' - Get a cookie value.
182 const char * /* O - Value or NULL */
183 cgiGetCookie(const char *name
) /* I - Name of cookie */
185 return (cupsGetOption(name
, num_cookies
, cookies
));
190 * 'cgiGetFile()' - Get the file (if any) that was submitted in the form.
193 const cgi_file_t
* /* O - Attached file or NULL */
201 * 'cgiGetSize()' - Get the size of a form array value.
204 int /* O - Number of elements */
205 cgiGetSize(const char *name
) /* I - Name of variable */
207 _cgi_var_t
*var
; /* Pointer to variable */
210 if ((var
= cgi_find_variable(name
)) == NULL
)
213 return (var
->nvalues
);
218 * 'cgiGetVariable()' - Get a CGI variable from the database.
220 * Returns NULL if the variable doesn't exist. If the variable is an
221 * array of values, returns the last element.
224 const char * /* O - Value of variable */
225 cgiGetVariable(const char *name
) /* I - Name of variable */
227 const _cgi_var_t
*var
; /* Returned variable */
230 var
= cgi_find_variable(name
);
234 DEBUG_printf(("cgiGetVariable(\"%s\") is returning NULL...\n", name
));
236 DEBUG_printf(("cgiGetVariable(\"%s\") is returning \"%s\"...\n", name
,
237 var
->values
[var
->nvalues
- 1]));
240 return ((var
== NULL
) ? NULL
: _cupsStrRetain(var
->values
[var
->nvalues
- 1]));
245 * 'cgiInitialize()' - Initialize the CGI variable "database".
248 int /* O - Non-zero if there was form data */
251 const char *method
, /* Form posting method */
252 *content_type
, /* Content-Type of post data */
253 *cups_sid_cookie
, /* SID cookie */
254 *cups_sid_form
; /* SID form variable */
258 * Setup a password callback for authentication...
261 cupsSetPasswordCB(cgi_passwd
);
264 * Set the locale so that times, etc. are formatted properly...
267 setlocale(LC_ALL
, "");
271 * Disable output buffering to find bugs...
274 setbuf(stdout
, NULL
);
281 cgi_initialize_cookies();
283 if ((cups_sid_cookie
= cgiGetCookie(CUPS_SID
)) == NULL
)
285 fputs("DEBUG: " CUPS_SID
" cookie not found, initializing!\n", stderr
);
286 cups_sid_cookie
= cgi_set_sid();
289 fprintf(stderr
, "DEBUG: " CUPS_SID
" cookie is \"%s\"\n", cups_sid_cookie
);
292 * Get the request method (GET or POST)...
295 method
= getenv("REQUEST_METHOD");
296 content_type
= getenv("CONTENT_TYPE");
301 * Grab form data from the corresponding location...
304 if (!_cups_strcasecmp(method
, "GET"))
305 return (cgi_initialize_get());
306 else if (!_cups_strcasecmp(method
, "POST") && content_type
)
308 const char *boundary
= strstr(content_type
, "boundary=");
313 if (content_type
&& !strncmp(content_type
, "multipart/form-data; ", 21))
315 if (!cgi_initialize_multipart(boundary
))
318 else if (!cgi_initialize_post())
321 if ((cups_sid_form
= cgiGetVariable(CUPS_SID
)) == NULL
||
322 strcmp(cups_sid_cookie
, cups_sid_form
))
325 fprintf(stderr
, "DEBUG: " CUPS_SID
" form variable is \"%s\"\n",
328 fputs("DEBUG: " CUPS_SID
" form variable is not present.\n", stderr
);
342 * 'cgiIsPOST()' - Determine whether this page was POSTed.
345 int /* O - 1 if POST, 0 if GET */
348 const char *method
; /* REQUEST_METHOD environment variable */
351 if ((method
= getenv("REQUEST_METHOD")) == NULL
)
354 return (!strcmp(method
, "POST"));
359 * 'cgiSetArray()' - Set array element N to the specified string.
361 * If the variable array is smaller than (element + 1), the intervening
362 * elements are set to NULL.
366 cgiSetArray(const char *name
, /* I - Name of variable */
367 int element
, /* I - Element number (0 to N) */
368 const char *value
) /* I - Value of variable */
370 int i
; /* Looping var */
371 _cgi_var_t
*var
; /* Returned variable */
374 if (name
== NULL
|| value
== NULL
|| element
< 0 || element
> 100000)
377 fprintf(stderr
, "DEBUG: cgiSetArray: %s[%d]=\"%s\"\n", name
, element
, value
);
379 if ((var
= cgi_find_variable(name
)) == NULL
)
381 cgi_add_variable(name
, element
, value
);
382 cgi_sort_variables();
386 if (element
>= var
->avalues
)
388 const char **temp
; /* Temporary pointer */
390 temp
= (const char **)realloc((void *)(var
->values
),
391 sizeof(char *) * (size_t)(element
+ 16));
395 var
->avalues
= element
+ 16;
399 if (element
>= var
->nvalues
)
401 for (i
= var
->nvalues
; i
< element
; i
++)
402 var
->values
[i
] = NULL
;
404 var
->nvalues
= element
+ 1;
406 else if (var
->values
[element
])
407 _cupsStrFree((char *)var
->values
[element
]);
409 var
->values
[element
] = _cupsStrAlloc(value
);
415 * 'cgiSetCookie()' - Set a cookie value.
419 cgiSetCookie(const char *name
, /* I - Name */
420 const char *value
, /* I - Value */
421 const char *path
, /* I - Path (typically "/") */
422 const char *domain
, /* I - Domain name */
423 time_t expires
, /* I - Expiration date (0 for session) */
424 int secure
) /* I - Require SSL */
426 num_cookies
= cupsAddOption(name
, value
, num_cookies
, &cookies
);
428 printf("Set-Cookie: %s=%s;", name
, value
);
430 printf(" path=%s;", path
);
432 printf(" domain=%s;", domain
);
435 char date
[256]; /* Date string */
437 printf(" expires=%s;", httpGetDateString2(expires
, date
, sizeof(date
)));
447 * 'cgiSetSize()' - Set the array size.
451 cgiSetSize(const char *name
, /* I - Name of variable */
452 int size
) /* I - Number of elements (0 to N) */
454 int i
; /* Looping var */
455 _cgi_var_t
*var
; /* Returned variable */
458 if (name
== NULL
|| size
< 0 || size
> 100000)
461 if ((var
= cgi_find_variable(name
)) == NULL
)
464 if (size
>= var
->avalues
)
466 const char **temp
; /* Temporary pointer */
468 temp
= (const char **)realloc((void *)(var
->values
),
469 sizeof(char *) * (size_t)(size
+ 16));
473 var
->avalues
= size
+ 16;
477 if (size
> var
->nvalues
)
479 for (i
= var
->nvalues
; i
< size
; i
++)
480 var
->values
[i
] = NULL
;
482 else if (size
< var
->nvalues
)
484 for (i
= size
; i
< var
->nvalues
; i
++)
486 _cupsStrFree((void *)(var
->values
[i
]));
494 * 'cgiSetVariable()' - Set a CGI variable in the database.
496 * If the variable is an array, this truncates the array to a single element.
500 cgiSetVariable(const char *name
, /* I - Name of variable */
501 const char *value
) /* I - Value of variable */
503 int i
; /* Looping var */
504 _cgi_var_t
*var
; /* Returned variable */
507 if (name
== NULL
|| value
== NULL
)
510 fprintf(stderr
, "cgiSetVariable: %s=\"%s\"\n", name
, value
);
512 if ((var
= cgi_find_variable(name
)) == NULL
)
514 cgi_add_variable(name
, 0, value
);
515 cgi_sort_variables();
519 for (i
= 0; i
< var
->nvalues
; i
++)
521 _cupsStrFree((char *)var
->values
[i
]);
523 var
->values
[0] = _cupsStrAlloc(value
);
530 * 'cgi_add_variable()' - Add a form variable.
534 cgi_add_variable(const char *name
, /* I - Variable name */
535 int element
, /* I - Array element number */
536 const char *value
) /* I - Variable value */
538 _cgi_var_t
*var
; /* New variable */
541 if (name
== NULL
|| value
== NULL
|| element
< 0 || element
> 100000)
544 DEBUG_printf(("cgi_add_variable: Adding variable \'%s\' with value "
545 "\'%s\'...\n", name
, value
));
547 if (form_count
>= form_alloc
)
549 _cgi_var_t
*temp_vars
; /* Temporary form pointer */
553 temp_vars
= malloc(sizeof(_cgi_var_t
) * 16);
555 temp_vars
= realloc(form_vars
, (size_t)(form_alloc
+ 16) * sizeof(_cgi_var_t
));
560 form_vars
= temp_vars
;
564 var
= form_vars
+ form_count
;
566 if ((var
->values
= calloc((size_t)element
+ 1, sizeof(char *))) == NULL
)
569 var
->name
= _cupsStrAlloc(name
);
570 var
->nvalues
= element
+ 1;
571 var
->avalues
= element
+ 1;
572 var
->values
[element
] = _cupsStrAlloc(value
);
579 * 'cgi_compare_variables()' - Compare two variables.
582 static int /* O - Result of comparison */
583 cgi_compare_variables(
584 const _cgi_var_t
*v1
, /* I - First variable */
585 const _cgi_var_t
*v2
) /* I - Second variable */
587 return (_cups_strcasecmp(v1
->name
, v2
->name
));
592 * 'cgi_find_variable()' - Find a variable.
595 static _cgi_var_t
* /* O - Variable pointer or NULL */
596 cgi_find_variable(const char *name
) /* I - Name of variable */
598 _cgi_var_t key
; /* Search key */
601 if (form_count
< 1 || name
== NULL
)
606 return ((_cgi_var_t
*)bsearch(&key
, form_vars
, (size_t)form_count
, sizeof(_cgi_var_t
),
607 (int (*)(const void *, const void *))cgi_compare_variables
));
612 * 'cgi_initialize_cookies()' - Initialize cookies.
616 cgi_initialize_cookies(void)
618 const char *cookie
; /* HTTP_COOKIE environment variable */
619 char name
[128], /* Name string */
620 value
[512], /* Value string */
621 *ptr
; /* Pointer into name/value */
624 if ((cookie
= getenv("HTTP_COOKIE")) == NULL
)
630 * Skip leading whitespace...
633 while (isspace(*cookie
& 255))
642 for (ptr
= name
; *cookie
&& *cookie
!= '=';)
643 if (ptr
< (name
+ sizeof(name
) - 1))
660 for (cookie
++, ptr
= value
; *cookie
&& *cookie
!= '\"';)
661 if (ptr
< (value
+ sizeof(value
) - 1))
671 for (ptr
= value
; *cookie
&& *cookie
!= ';';)
672 if (ptr
< (value
+ sizeof(value
) - 1))
686 * Then add the cookie to an array as long as the name doesn't start with
691 num_cookies
= cupsAddOption(name
, value
, num_cookies
, &cookies
);
697 * 'cgi_initialize_get()' - Initialize form variables using the GET method.
700 static int /* O - 1 if form data read */
701 cgi_initialize_get(void)
703 char *data
; /* Pointer to form data string */
706 DEBUG_puts("cgi_initialize_get: Initializing variables using GET method...");
709 * Check to see if there is anything for us to read...
712 data
= getenv("QUERY_STRING");
713 if (data
== NULL
|| strlen(data
) == 0)
717 * Parse it out and return...
720 return (cgi_initialize_string(data
));
725 * 'cgi_initialize_multipart()' - Initialize variables and file using the POST
728 * TODO: Update to support files > 2GB.
731 static int /* O - 1 if form data was read */
732 cgi_initialize_multipart(
733 const char *boundary
) /* I - Boundary string */
735 char line
[10240], /* MIME header line */
736 name
[1024], /* Form variable name */
737 filename
[1024], /* Form filename */
738 mimetype
[1024], /* MIME media type */
739 bstring
[256], /* Boundary string to look for */
740 *ptr
, /* Pointer into name/filename */
741 *end
; /* End of buffer */
742 int ch
, /* Character from file */
743 fd
; /* Temporary file descriptor */
744 size_t blen
; /* Length of boundary string */
747 DEBUG_printf(("cgi_initialize_multipart(boundary=\"%s\")\n", boundary
));
750 * Read multipart form data until we run out...
757 snprintf(bstring
, sizeof(bstring
), "\r\n--%s", boundary
);
758 blen
= strlen(bstring
);
760 while (fgets(line
, sizeof(line
), stdin
))
762 if (!strcmp(line
, "\r\n"))
765 * End of headers, grab value...
771 * Read an embedded file...
777 * Remove previous file...
784 * Allocate memory for the new file...
787 if ((form_file
= calloc(1, sizeof(cgi_file_t
))) == NULL
)
790 form_file
->name
= strdup(name
);
791 form_file
->filename
= strdup(filename
);
792 form_file
->mimetype
= strdup(mimetype
);
794 fd
= cupsTempFd(form_file
->tempfile
, sizeof(form_file
->tempfile
));
799 atexit(cgi_unlink_file
);
802 * Copy file data to the temp file...
807 while ((ch
= getchar()) != EOF
)
811 if ((size_t)(ptr
- line
) >= blen
&& !memcmp(ptr
- blen
, bstring
, blen
))
817 if ((ptr
- line
- (int)blen
) >= 8192)
820 * Write out the first 8k of the buffer...
823 write(fd
, line
, 8192);
824 memmove(line
, line
+ 8192, (size_t)(ptr
- line
- 8192));
830 * Write the rest of the data and close the temp file...
834 write(fd
, line
, (size_t)(ptr
- line
));
841 * Just get a form variable; the current code only handles
842 * form values up to 10k in size...
846 end
= line
+ sizeof(line
) - 1;
848 while ((ch
= getchar()) != EOF
)
853 if ((size_t)(ptr
- line
) >= blen
&& !memcmp(ptr
- blen
, bstring
, blen
))
863 * Set the form variable...
866 if ((ptr
= strrchr(name
, '-')) != NULL
&& isdigit(ptr
[1] & 255))
869 * Set a specific index in the array...
874 cgiSetArray(name
, atoi(ptr
) - 1, line
);
876 else if (cgiGetVariable(name
))
879 * Add another element in the array...
882 cgiSetArray(name
, cgiGetSize(name
), line
);
887 * Just set the line...
890 cgiSetVariable(name
, line
);
895 * Read the rest of the current line...
898 fgets(line
, sizeof(line
), stdin
);
901 * Clear the state vars...
908 else if (!_cups_strncasecmp(line
, "Content-Disposition:", 20))
910 if ((ptr
= strstr(line
+ 20, " name=\"")) != NULL
)
912 strlcpy(name
, ptr
+ 7, sizeof(name
));
914 if ((ptr
= strchr(name
, '\"')) != NULL
)
918 if ((ptr
= strstr(line
+ 20, " filename=\"")) != NULL
)
920 strlcpy(filename
, ptr
+ 11, sizeof(filename
));
922 if ((ptr
= strchr(filename
, '\"')) != NULL
)
926 else if (!_cups_strncasecmp(line
, "Content-Type:", 13))
928 for (ptr
= line
+ 13; isspace(*ptr
& 255); ptr
++);
930 strlcpy(mimetype
, ptr
, sizeof(mimetype
));
932 for (ptr
= mimetype
+ strlen(mimetype
) - 1;
933 ptr
> mimetype
&& isspace(*ptr
& 255);
939 * Return 1 for "form data found"...
947 * 'cgi_initialize_post()' - Initialize variables using the POST method.
950 static int /* O - 1 if form data was read */
951 cgi_initialize_post(void)
953 char *content_length
, /* Length of input data (string) */
954 *data
; /* Pointer to form data string */
955 size_t length
, /* Length of input data */
956 tbytes
; /* Total number of bytes read */
957 ssize_t nbytes
; /* Number of bytes read this read() */
958 int status
; /* Return status */
961 DEBUG_puts("cgi_initialize_post: Initializing variables using POST method...");
964 * Check to see if there is anything for us to read...
967 content_length
= getenv("CONTENT_LENGTH");
968 if (content_length
== NULL
|| atoi(content_length
) <= 0)
972 * Get the length of the input stream and allocate a buffer for it...
975 length
= (size_t)strtol(content_length
, NULL
, 10);
976 data
= malloc(length
+ 1);
982 * Read the data into the buffer...
985 for (tbytes
= 0; tbytes
< length
; tbytes
+= (size_t)nbytes
)
986 if ((nbytes
= read(0, data
+ tbytes
, (size_t)(length
- tbytes
))) < 0)
996 else if (nbytes
== 0)
999 * CUPS STR #3176: OpenBSD: Early end-of-file on POST data causes 100% CPU
1001 * This should never happen, but does on OpenBSD. If we see early end-of-
1002 * file, treat this as an error and process no data.
1009 data
[length
] = '\0';
1015 status
= cgi_initialize_string(data
);
1018 * Free the data and return...
1028 * 'cgi_initialize_string()' - Initialize form variables from a string.
1031 static int /* O - 1 if form data was processed */
1032 cgi_initialize_string(const char *data
) /* I - Form data string */
1034 int done
; /* True if we're done reading a form variable */
1035 char *s
, /* Pointer to current form string */
1036 ch
, /* Temporary character */
1037 name
[255], /* Name of form variable */
1038 value
[65536]; /* Variable value */
1049 * Loop until we've read all the form data...
1052 while (*data
!= '\0')
1055 * Get the variable name...
1058 for (s
= name
; *data
!= '\0'; data
++)
1061 else if (*data
>= ' ' && s
< (name
+ sizeof(name
) - 1))
1071 * Read the variable value...
1074 for (s
= value
, done
= 0; !done
&& *data
!= '\0'; data
++)
1077 case '&' : /* End of data... */
1081 case '+' : /* Escaped space character */
1082 if (s
< (value
+ sizeof(value
) - 1))
1086 case '%' : /* Escaped control character */
1088 * Read the hex code...
1091 if (!isxdigit(data
[1] & 255) || !isxdigit(data
[2] & 255))
1094 if (s
< (value
+ sizeof(value
) - 1))
1100 *s
= (char)(ch
<< 4);
1112 default : /* Other characters come straight through */
1113 if (*data
>= ' ' && s
< (value
+ sizeof(value
) - 1))
1118 *s
= '\0'; /* nul terminate the string */
1121 * Remove trailing whitespace...
1127 while (s
>= value
&& isspace(*s
& 255))
1131 * Add the string to the variable "database"...
1134 if ((s
= strrchr(name
, '-')) != NULL
&& isdigit(s
[1] & 255))
1138 cgiSetArray(name
, atoi(s
) - 1, value
);
1140 else if (cgiGetVariable(name
) != NULL
)
1141 cgiSetArray(name
, cgiGetSize(name
), value
);
1143 cgiSetVariable(name
, value
);
1151 * 'cgi_passwd()' - Catch authentication requests and notify the server.
1153 * This function sends a Status header and exits, forcing authentication
1157 static const char * /* O - NULL (no return) */
1158 cgi_passwd(const char *prompt
) /* I - Prompt (not used) */
1162 fprintf(stderr
, "DEBUG: cgi_passwd(prompt=\"%s\") called!\n",
1163 prompt
? prompt
: "(null)");
1166 * Send a 401 (unauthorized) status to the server, so it can notify
1167 * the client that authentication is required.
1170 puts("Status: 401\n");
1174 * This code is never executed, but is present to satisfy the compiler.
1182 * 'cgi_set_sid()' - Set the CUPS session ID.
1185 static const char * /* O - New session ID */
1188 char buffer
[512], /* SID data */
1189 sid
[33]; /* SID string */
1190 _cups_md5_state_t md5
; /* MD5 state */
1191 unsigned char sum
[16]; /* MD5 sum */
1192 const char *remote_addr
, /* REMOTE_ADDR */
1193 *server_name
, /* SERVER_NAME */
1194 *server_port
; /* SERVER_PORT */
1197 if ((remote_addr
= getenv("REMOTE_ADDR")) == NULL
)
1198 remote_addr
= "REMOTE_ADDR";
1199 if ((server_name
= getenv("SERVER_NAME")) == NULL
)
1200 server_name
= "SERVER_NAME";
1201 if ((server_port
= getenv("SERVER_PORT")) == NULL
)
1202 server_port
= "SERVER_PORT";
1204 CUPS_SRAND(time(NULL
));
1205 snprintf(buffer
, sizeof(buffer
), "%s:%s:%s:%02X%02X%02X%02X%02X%02X%02X%02X",
1206 remote_addr
, server_name
, server_port
,
1207 (unsigned)CUPS_RAND() & 255, (unsigned)CUPS_RAND() & 255,
1208 (unsigned)CUPS_RAND() & 255, (unsigned)CUPS_RAND() & 255,
1209 (unsigned)CUPS_RAND() & 255, (unsigned)CUPS_RAND() & 255,
1210 (unsigned)CUPS_RAND() & 255, (unsigned)CUPS_RAND() & 255);
1212 _cupsMD5Append(&md5
, (unsigned char *)buffer
, (int)strlen(buffer
));
1213 _cupsMD5Finish(&md5
, sum
);
1215 cgiSetCookie(CUPS_SID
, httpMD5String(sum
, sid
), "/", NULL
, 0, 0);
1217 return (cupsGetOption(CUPS_SID
, num_cookies
, cookies
));
1222 * 'cgi_sort_variables()' - Sort all form variables for faster lookup.
1226 cgi_sort_variables(void)
1232 DEBUG_puts("cgi_sort_variables: Sorting variables...");
1238 qsort(form_vars
, (size_t)form_count
, sizeof(_cgi_var_t
),
1239 (int (*)(const void *, const void *))cgi_compare_variables
);
1242 DEBUG_puts("cgi_sort_variables: Sorted variable list is:");
1243 for (i
= 0; i
< form_count
; i
++)
1244 DEBUG_printf(("cgi_sort_variables: %d: %s (%d) = \"%s\" ...\n", i
,
1245 form_vars
[i
].name
, form_vars
[i
].nvalues
,
1246 form_vars
[i
].values
[0]));
1252 * 'cgi_unlink_file()' - Remove the uploaded form.
1256 cgi_unlink_file(void)
1261 * Remove the temporary file...
1264 unlink(form_file
->tempfile
);
1267 * Free memory used...
1270 free(form_file
->name
);
1271 free(form_file
->filename
);
1272 free(form_file
->mimetype
);