diff options
author | Thomas E. Dickey <dickey@invisible-island.net> | 1998-11-10 19:47:00 -0500 |
---|---|---|
committer | Thomas E. Dickey <dickey@invisible-island.net> | 1998-11-10 19:47:00 -0500 |
commit | d3f9d5478df478427c2aa5db4507ddd0a38f0eb6 (patch) | |
tree | e27eacd6bbda653dd77f11cc020b9e0a59f7f4fc /src/LYCgi.c | |
parent | 18024037b515bfff83e0230b35151babe6005e18 (diff) | |
download | lynx-snapshots-d3f9d5478df478427c2aa5db4507ddd0a38f0eb6.tar.gz |
snapshot of project "lynx", label v2-8-2dev_2
Diffstat (limited to 'src/LYCgi.c')
-rw-r--r-- | src/LYCgi.c | 92 |
1 files changed, 31 insertions, 61 deletions
diff --git a/src/LYCgi.c b/src/LYCgi.c index 9a6ab780..3c27a113 100644 --- a/src/LYCgi.c +++ b/src/LYCgi.c @@ -24,7 +24,6 @@ */ #include <HTUtils.h> -#include <tcp.h> #include <HTTP.h> #include <HTParse.h> #include <HTTCP.h> @@ -41,14 +40,15 @@ #include <LYGetFile.h> #include <LYBookmark.h> #include <GridText.h> -#include <ctype.h> #include <LYCgi.h> #include <LYSignal.h> #include <LYLocal.h> #include <LYLeaks.h> -#define FREE(x) if (x) {free(x); x = NULL;} +#ifdef HAVE_SYS_WAIT_H +#include <sys/wait.h> +#endif struct _HTStream { @@ -122,7 +122,7 @@ PRIVATE int LYLoadCGI ARGS4( HTFormat, format_out, HTStream*, sink) { - int status; + int status = 0; #ifdef LYNXCGI_LINKS #ifndef VMS char *cp; @@ -190,9 +190,7 @@ PRIVATE int LYLoadCGI ARGS4( /* Found PATH_INFO data. Strip it off of pgm and into path_info. */ StrAllocCopy(path_info, pgm+strlen(pgm_buff)); strcpy(pgm, pgm_buff); - if (TRACE) - fprintf(stderr, - "LYNXCGI: stat() of %s succeeded, path_info=\"%s\".\n", + CTRACE(tfp, "LYNXCGI: stat() of %s succeeded, path_info=\"%s\".\n", pgm_buff, path_info); } FREE(pgm_buff); @@ -204,7 +202,7 @@ PRIVATE int LYLoadCGI ARGS4( * Neither the path as given nor any components examined by * backing up were stat()able. - kw */ - HTAlert("Unable to access cgi script"); + HTAlert(gettext("Unable to access cgi script")); if (TRACE) { perror("LYNXCGI: stat() failed"); } @@ -223,11 +221,8 @@ PRIVATE int LYLoadCGI ARGS4( * to confusing to know just what file is loaded. - kw */ if (path_info) { - if (TRACE) { - fprintf(stderr, - "%s is not a file and %s not an executable, giving up.\n", + CTRACE(tfp, "%s is not a file and %s not an executable, giving up.\n", orig_pgm, pgm); - } FREE(path_info); FREE(pgm); FREE(orig_pgm); @@ -235,13 +230,9 @@ PRIVATE int LYLoadCGI ARGS4( return(status); } - StrAllocCopy(new_arg, "file://localhost"); - StrAllocCat(new_arg, orig_pgm); + LYLocalFileToURL (&new_arg, orig_pgm); - if (TRACE) { - fprintf(stderr, - "%s is not an executable file, passing the buck.\n", arg); - } + CTRACE(tfp, "%s is not an executable file, passing the buck.\n", arg); status = HTLoadFile(new_arg, anAnchor, format_out, sink); FREE(new_arg); @@ -261,8 +252,7 @@ PRIVATE int LYLoadCGI ARGS4( status = HT_NOT_LOADED; } else if (no_lynxcgi) { - _statusline(CGI_DISABLED); - sleep(MessageSecs); + HTUserMsg(CGI_DISABLED); status = HT_NOT_LOADED; } else if (no_bookmark_exec && @@ -277,8 +267,7 @@ PRIVATE int LYLoadCGI ARGS4( * no_bookmark_exec is TRUE an we are not now coming from a * bookmark page. - kw */ - _statusline(BOOKMARK_EXEC_DISABLED); - sleep(MessageSecs); + HTUserMsg(BOOKMARK_EXEC_DISABLED); status = HT_NOT_LOADED; } else if (anAnchor != HTMainAnchor && @@ -324,8 +313,7 @@ PRIVATE int LYLoadCGI ARGS4( if (!target || target == NULL) { sprintf(buf, CANNOT_CONVERT_I_TO_O, HTAtom_name(format_in), HTAtom_name(format_out)); - _statusline(buf); - sleep(AlertSecs); + HTAlert(buf); status = HT_NOT_LOADED; } else if (anAnchor->post_data && pipe(fd1) < 0) { @@ -372,13 +360,10 @@ PRIVATE int LYLoadCGI ARGS4( close(fd1[0]); /* We have form data to push across the pipe */ - if (TRACE) { - fprintf(stderr, "LYNXCGI: Doing post, content-type '%s'\n", + CTRACE(tfp, "LYNXCGI: Doing post, content-type '%s'\n", anAnchor->post_content_type); - fprintf(stderr, - "LYNXCGI: Writing:\n%s----------------------------------\n", + CTRACE(tfp, "LYNXCGI: Writing:\n%s----------------------------------\n", anAnchor->post_data); - } remaining = strlen(anAnchor->post_data); while ((written = write(fd1[1], anAnchor->post_data + total_written, @@ -397,36 +382,24 @@ PRIVATE int LYLoadCGI ARGS4( } break; } - if (TRACE) { - fprintf(stderr, - "LYNXCGI: Wrote %d bytes of POST data.\n", + CTRACE(tfp, "LYNXCGI: Wrote %d bytes of POST data.\n", written); - } total_written += written; remaining -= written; if (remaining == 0) break; } if (remaining != 0) { - if (TRACE) - fprintf(stderr, - "LYNXCGI: %d bytes remain unwritten!\n", + CTRACE(tfp, "LYNXCGI: %d bytes remain unwritten!\n", remaining); } close(fd1[1]); } - total_chars = 0; + HTReadProgress(total_chars = 0, 0); while((chars = read(fd2[0], buf, sizeof(buf))) > 0) { - char line[40]; - - total_chars += chars; - sprintf (line, "Read %d bytes of data.", total_chars); - HTProgress(line); - if (TRACE) { - fprintf(stderr, "LYNXCGI: Rx: %.*s\n", chars, buf); - } - + HTReadProgress(total_chars += chars, 0); + CTRACE(tfp, "LYNXCGI: Rx: %.*s\n", chars, buf); (*target->isa->put_block)(target, buf, chars); } #if !HAVE_WAITPID @@ -453,7 +426,7 @@ PRIVATE int LYLoadCGI ARGS4( char post_len[32]; int argv_cnt = 3; /* name, one arg and terminator */ char **cur_argv = NULL; - char buf[BUFSIZ]; + char buf2[BUFSIZ]; /* Set up output pipe */ close(fd2[0]); @@ -461,10 +434,10 @@ PRIVATE int LYLoadCGI ARGS4( dup2(fd2[1], fileno(stderr)); close(fd2[1]); - sprintf(buf, "HTTP_ACCEPT_LANGUAGE=%.*s", - (int)(sizeof(buf) - 22), language); - buf[(sizeof(buf) - 1)] = '\0'; - add_environment_value(buf); + sprintf(buf2, "HTTP_ACCEPT_LANGUAGE=%.*s", + (int)(sizeof(buf2) - 22), language); + buf2[(sizeof(buf2) - 1)] = '\0'; + add_environment_value(buf2); if (pref_charset) { cp = NULL; @@ -571,9 +544,7 @@ PRIVATE int LYLoadCGI ARGS4( if (LYCgiDocumentRoot != NULL && path_info != NULL ) { /* Construct and add PATH_TRANSLATED to env */ StrAllocCopy(document_root, LYCgiDocumentRoot); - if (document_root[strlen(document_root) - 1] == '/') { - document_root[strlen(document_root) - 1] = '\0'; - } + LYTrimHtmlSep(document_root); path_translated = document_root; StrAllocCat(path_translated, path_info); cp = NULL; @@ -618,24 +589,24 @@ PRIVATE int LYLoadCGI ARGS4( format_out, sink, anAnchor); - sprintf(buf,"<head>\n<title>Good Advice</title>\n</head>\n<body>\n"); + sprintf(buf, "<head>\n<title>%s</title>\n</head>\n<body>\n", gettext("Good Advice")); (*target->isa->put_block)(target, buf, strlen(buf)); - sprintf(buf,"<h1>Good Advice</h1>\n"); + sprintf(buf, "<h1>%s</h1>\n", gettext("Good Advice")); (*target->isa->put_block)(target, buf, strlen(buf)); - sprintf(buf, "An excellent http server for VMS is available via <a\n"); + sprintf(buf, "%s <a\n", gettext("An excellent http server for VMS is available via")); (*target->isa->put_block)(target, buf, strlen(buf)); sprintf(buf, "href=\"http://kcgl1.eng.ohio-state.edu/www/doc/serverinfo.html\"\n"); (*target->isa->put_block)(target, buf, strlen(buf)); - sprintf(buf, ">this link</a>.\n"); + sprintf(buf, ">%s</a>.\n", gettext("this link")); (*target->isa->put_block)(target, buf, strlen(buf)); sprintf(buf, - "<p>It provides <b>state of the art</b> CGI script support.\n"); + gettext("<p>It provides <b>state of the art</b> CGI script support.\n")); (*target->isa->put_block)(target, buf, strlen(buf)); sprintf(buf,"</body>\n"); @@ -645,8 +616,7 @@ PRIVATE int LYLoadCGI ARGS4( status = HT_LOADED; #endif /* VMS */ #else /* LYNXCGI_LINKS */ - _statusline(CGI_NOT_COMPILED); - sleep(MessageSecs); + HTUserMsg(CGI_NOT_COMPILED); status = HT_NOT_LOADED; #endif /* LYNXCGI_LINKS */ return(status); |