int ACGI::_cgiDoFormItems(istream *pisInput) { if (pisInput) { //a_Another stream used for inputing #ifdef _DEBUG_DUMP_ cout << "<!--ACGI::_cgiDoFormItems: istream-->"; #endif return flGenerateList(pisInput, -1); } else { if (cgiIsGET()) { #ifdef _DEBUG_DUMP_ cout << "<!--ACGI::_cgiDoFormItems: GET-->"; #endif return flGenerateList(cgiGetQueryString()); } else { if (cgiIsPOST()) { #ifdef _DEBUG_DUMP_ cout << "<!--ACGI::_cgiDoFormItems: POST and GET-->"; #endif return flGenerateList(&cin, atoi(cgiGetContentLength())) + flGenerateList(cgiGetQueryString());; } else { //a_Not a POST or a GET (hmm... HEAD, PUT, LINK, UNLINK, DELETE and FILE not yet supported (inadequate documentation)) #ifdef _DEBUG_DUMP_ cout << "<!--ACGI::_cgiDoFormItems: Neither POST nor GET-->"; #endif } } } return 0x0; }
int /* O - Exit status */ main(int argc, /* I - Number of command-line arguments */ char *argv[]) /* I - Command-line arguments */ { const char *printer; /* Printer name */ const char *user; /* Username */ http_t *http; /* Connection to the server */ ipp_t *request, /* IPP request */ *response; /* IPP response */ ipp_attribute_t *attr; /* IPP attribute */ const char *op; /* Operation to perform, if any */ static const char *def_attrs[] = /* Attributes for default printer */ { "printer-name", "printer-uri-supported" }; /* * Get any form variables... */ cgiInitialize(); op = cgiGetVariable("OP"); /* * Set the web interface section... */ cgiSetVariable("SECTION", "printers"); cgiSetVariable("REFRESH_PAGE", ""); /* * See if we are displaying a printer or all printers... */ if ((printer = getenv("PATH_INFO")) != NULL) { printer ++; if (!*printer) printer = NULL; if (printer) cgiSetVariable("PRINTER_NAME", printer); } /* * See who is logged in... */ user = getenv("REMOTE_USER"); /* * Connect to the HTTP server... */ http = httpConnectEncrypt(cupsServer(), ippPort(), cupsEncryption()); /* * Get the default printer... */ if (!op || !cgiIsPOST()) { /* * Get the default destination... */ request = ippNewRequest(CUPS_GET_DEFAULT); ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, "requested-attributes", sizeof(def_attrs) / sizeof(def_attrs[0]), NULL, def_attrs); if ((response = cupsDoRequest(http, request, "/")) != NULL) { if ((attr = ippFindAttribute(response, "printer-name", IPP_TAG_NAME)) != NULL) cgiSetVariable("DEFAULT_NAME", attr->values[0].string.text); if ((attr = ippFindAttribute(response, "printer-uri-supported", IPP_TAG_URI)) != NULL) { char url[HTTP_MAX_URI]; /* New URL */ cgiSetVariable("DEFAULT_URI", cgiRewriteURL(attr->values[0].string.text, url, sizeof(url), NULL)); } ippDelete(response); } /* * See if we need to show a list of printers or the status of a * single printer... */ if (!printer) show_all_printers(http, user); else show_printer(http, printer); } else if (printer) { if (!*op) { const char *server_port = getenv("SERVER_PORT"); /* Port number string */ int port = atoi(server_port ? server_port : "0"); /* Port number */ char uri[1024]; /* URL */ httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), getenv("HTTPS") ? "https" : "http", NULL, getenv("SERVER_NAME"), port, "/printers/%s", printer); printf("Location: %s\n\n", uri); } else if (!strcmp(op, "start-printer")) do_printer_op(http, printer, IPP_RESUME_PRINTER, cgiText(_("Resume Printer"))); else if (!strcmp(op, "stop-printer")) do_printer_op(http, printer, IPP_PAUSE_PRINTER, cgiText(_("Pause Printer"))); else if (!strcmp(op, "accept-jobs")) do_printer_op(http, printer, CUPS_ACCEPT_JOBS, cgiText(_("Accept Jobs"))); else if (!strcmp(op, "reject-jobs")) do_printer_op(http, printer, CUPS_REJECT_JOBS, cgiText(_("Reject Jobs"))); else if (!strcmp(op, "purge-jobs")) do_printer_op(http, printer, IPP_PURGE_JOBS, cgiText(_("Purge Jobs"))); else if (!_cups_strcasecmp(op, "print-self-test-page")) cgiPrintCommand(http, printer, "PrintSelfTestPage", cgiText(_("Print Self-Test Page"))); else if (!_cups_strcasecmp(op, "clean-print-heads")) cgiPrintCommand(http, printer, "Clean all", cgiText(_("Clean Print Heads"))); else if (!_cups_strcasecmp(op, "print-test-page")) cgiPrintTestPage(http, printer); else if (!_cups_strcasecmp(op, "move-jobs")) cgiMoveJobs(http, printer, 0); else { /* * Unknown/bad operation... */ cgiStartHTML(printer); cgiCopyTemplateLang("error-op.tmpl"); cgiEndHTML(); } } else { /* * Unknown/bad operation... */ cgiStartHTML(cgiText(_("Printers"))); cgiCopyTemplateLang("error-op.tmpl"); cgiEndHTML(); } /* * Close the HTTP server connection... */ httpClose(http); /* * Return with no errors... */ return (0); }
int /* O - Exit status */ main(void) { http_t *http; /* Connection to the server */ const char *op; /* Operation name */ const char *job_id_var; /* Job ID form variable */ int job_id; /* Job ID */ /* * Get any form variables... */ cgiInitialize(); /* * Set the web interface section... */ cgiSetVariable("SECTION", "jobs"); cgiSetVariable("REFRESH_PAGE", ""); /* * Connect to the HTTP server... */ http = httpConnectEncrypt(cupsServer(), ippPort(), cupsEncryption()); /* * Get the job ID, if any... */ if ((job_id_var = cgiGetVariable("JOB_ID")) != NULL) job_id = atoi(job_id_var); else job_id = 0; /* * Do the operation... */ if ((op = cgiGetVariable("OP")) != NULL && job_id > 0 && cgiIsPOST()) { /* * Do the operation... */ if (!strcmp(op, "cancel-job")) do_job_op(http, job_id, IPP_CANCEL_JOB); else if (!strcmp(op, "hold-job")) do_job_op(http, job_id, IPP_HOLD_JOB); else if (!strcmp(op, "move-job")) cgiMoveJobs(http, NULL, job_id); else if (!strcmp(op, "release-job")) do_job_op(http, job_id, IPP_RELEASE_JOB); else if (!strcmp(op, "restart-job")) do_job_op(http, job_id, IPP_RESTART_JOB); else { /* * Bad operation code... Display an error... */ cgiStartHTML(cgiText(_("Jobs"))); cgiCopyTemplateLang("error-op.tmpl"); cgiEndHTML(); } } else { /* * Show a list of jobs... */ cgiStartHTML(cgiText(_("Jobs"))); cgiShowJobs(http, NULL); cgiEndHTML(); } /* * Close the HTTP server connection... */ httpClose(http); /* * Return with no errors... */ return (0); }