| 319 | */ |
| 320 | |
| 321 | int /* O - Non-zero if there was form data */ |
| 322 | cgiInitialize(void) |
| 323 | { |
| 324 | const char *method, /* Form posting method */ |
| 325 | *content_type, /* Content-Type of post data */ |
| 326 | *cups_sid_cookie, /* SID cookie */ |
| 327 | *cups_sid_form; /* SID form variable */ |
| 328 | |
| 329 | |
| 330 | /* |
| 331 | * Setup a password callback for authentication... |
| 332 | */ |
| 333 | |
| 334 | cupsSetPasswordCB(cgi_passwd); |
| 335 | |
| 336 | /* |
| 337 | * Set the locale so that times, etc. are formatted properly... |
| 338 | */ |
| 339 | |
| 340 | setlocale(LC_ALL, ""); |
| 341 | |
| 342 | #ifdef DEBUG |
| 343 | /* |
| 344 | * Disable output buffering to find bugs... |
| 345 | */ |
| 346 | |
| 347 | setbuf(stdout, NULL); |
| 348 | #endif /* DEBUG */ |
| 349 | |
| 350 | /* |
| 351 | * Get cookies... |
| 352 | */ |
| 353 | |
| 354 | cgi_initialize_cookies(); |
| 355 | |
| 356 | if ((cups_sid_cookie = cgiGetCookie(CUPS_SID)) == NULL) |
| 357 | { |
| 358 | fputs("DEBUG: " CUPS_SID " cookie not found, initializing!\n", stderr); |
| 359 | cups_sid_cookie = cgi_set_sid(); |
| 360 | } |
| 361 | |
| 362 | fprintf(stderr, "DEBUG: " CUPS_SID " cookie is \"%s\"\n", cups_sid_cookie); |
| 363 | |
| 364 | /* |
| 365 | * Get the request method (GET or POST)... |
| 366 | */ |
| 367 | |
| 368 | method = getenv("REQUEST_METHOD"); |
| 369 | content_type = getenv("CONTENT_TYPE"); |
| 370 | if (!method) |
| 371 | return (0); |
| 372 | |
| 373 | /* |
| 374 | * Grab form data from the corresponding location... |
| 375 | */ |
| 376 | |
| 377 | if (!_cups_strcasecmp(method, "GET")) |
| 378 | return (cgi_initialize_get()); |