static const char * munge_other_line(const char *buf, cachemgr_request * req) { static const char *ttags[] = {"td", "th"}; static char html[4096]; static int table_line_num = 0; static int next_is_header = 0; int is_header = 0; const char *ttag; char *buf_copy; char *x, *p; int l = 0; /* does it look like a table? */ if (!strchr(buf, '\t') || *buf == '\t') { /* nope, just text */ snprintf(html, sizeof(html), "%s%s", table_line_num ? "</table>\n<pre>" : "", html_quote(buf)); table_line_num = 0; return html; } /* start html table */ if (!table_line_num) { l += snprintf(html + l, sizeof(html) - l, "</pre><table cellpadding=\"2\" cellspacing=\"1\">\n"); next_is_header = 0; } /* remove '\n' */ is_header = (!table_line_num || next_is_header) && !strchr(buf, ':') && !is_number(buf); ttag = ttags[is_header]; /* record starts */ l += snprintf(html + l, sizeof(html) - l, "<tr>"); /* substitute '\t' */ buf_copy = x = xstrdup(buf); if ((p = strchr(x, '\n'))) *p = '\0'; while (x && strlen(x)) { int column_span = 1; const char *cell = xstrtok(&x, '\t'); while (x && *x == '\t') { column_span++; x++; } l += snprintf(html + l, sizeof(html) - l, "<%s colspan=\"%d\" align=\"%s\">%s</%s>", ttag, column_span, is_header ? "center" : is_number(cell) ? "right" : "left", html_quote(cell), ttag); } xfree(buf_copy); /* record ends */ l += snprintf(html + l, sizeof(html) - l, "</tr>\n"); next_is_header = is_header && strstr(buf, "\t\t"); table_line_num++; return html; }
Str loadLocalDir(char *dname) { Str tmp; DIR *d; Directory *dir; struct stat st; char **flist; char *p, *qdir; Str fbuf = Strnew(); #ifdef HAVE_LSTAT struct stat lst; #ifdef HAVE_READLINK char lbuf[1024]; #endif /* HAVE_READLINK */ #endif /* HAVE_LSTAT */ int i, l, nrow = 0, n = 0, maxlen = 0; int nfile, nfile_max = 100; Str dirname; d = opendir(dname); if (d == NULL) return NULL; dirname = Strnew_charp(dname); if (Strlastchar(dirname) != '/') Strcat_char(dirname, '/'); qdir = html_quote(Str_conv_from_system(dirname)->ptr); /* FIXME: gettextize? */ tmp = Strnew_m_charp("<HTML>\n<HEAD>\n<BASE HREF=\"file://", html_quote(file_quote(dirname->ptr)), "\">\n<TITLE>Directory list of ", qdir, "</TITLE>\n</HEAD>\n<BODY>\n<H1>Directory list of ", qdir, "</H1>\n", NULL); flist = New_N(char *, nfile_max); nfile = 0; while ((dir = readdir(d)) != NULL) { flist[nfile++] = allocStr(dir->d_name, -1); if (nfile == nfile_max) { nfile_max *= 2; flist = New_Reuse(char *, flist, nfile_max); } if (multicolList) { l = strlen(dir->d_name); if (l > maxlen) maxlen = l; n++; } }
static void error_html(const char *msg) { printf("Content-Type: text/html\r\n\r\n"); printf("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n"); printf("<HTML><HEAD><TITLE>Cache Manager Error</TITLE>\n"); printf("<STYLE type=\"text/css\"><!--BODY{background-color:#ffffff;font-family:verdana,sans-serif}--></STYLE></HEAD>\n"); printf("<BODY><H1>Cache Manager Error</H1>\n"); printf("<P>\n%s</P>\n", html_quote(msg)); print_trailer(); }
static void add_news_message(Str str, int index, char *date, char *name, char *subject, char *mid, char *scheme, char *group) { time_t t; struct tm *tm; name = name_from_address(name, 16); t = mymktime(date); tm = localtime(&t); Strcat(str, Sprintf("<tr valign=top><td>%d<td nowrap>(%02d/%02d)<td nowrap>%s", index, tm->tm_mon + 1, tm->tm_mday, html_quote_s(name))); if (group) Strcat(str, Sprintf("<td><a href=\"%s%s/%d\">%s</a>\n", scheme, group, index, html_quote(subject))); else Strcat(str, Sprintf("<td><a href=\"%s%s\">%s</a>\n", scheme, html_quote(file_quote(mid)), html_quote(subject))); }
Buffer * follow_map_panel(Buffer *buf, char *name) { Str mappage; MapList *ml; ListItem *al; MapArea *a; ParsedURL pu; char *p, *q; Buffer *newbuf; ml = searchMapList(buf, name); if (ml == NULL) return NULL; mappage = Strnew_charp(map1); for (al = ml->area->first; al != NULL; al = al->next) { a = (MapArea *) al->ptr; if (!a) continue; parseURL2(a->url, &pu, baseURL(buf)); p = parsedURL2Str(&pu)->ptr; q = html_quote(p); if (DecodeURL) p = html_quote(url_unquote_conv(p, buf->document_charset)); else p = q; Strcat_m_charp(mappage, "<tr valign=top><td><a href=\"", q, "\">", html_quote(*a->alt ? a->alt : mybasename(a->url)), "</a><td>", p, NULL); } Strcat_charp(mappage, "</table></body></html>"); newbuf = loadHTMLString(mappage); #ifdef USE_M17N if (newbuf) newbuf->document_charset = buf->document_charset; #endif return newbuf; }
static const char * errorConvert(char token, ErrorState * err) { request_t *r = err->request; static MemBuf mb = MemBufNULL; const char *p = NULL; /* takes priority over mb if set */ int do_quote = 1; memBufReset(&mb); switch (token) { case 'a': if (r && r->auth_user_request) p = authenticateUserRequestUsername(r->auth_user_request); if (!p) p = "-"; break; case 'B': p = r ? ftpUrlWith2f(r) : "[no URL]"; break; case 'c': p = errorPageName(err->type); break; case 'e': memBufPrintf(&mb, "%d", err->xerrno); break; case 'E': if (err->xerrno) memBufPrintf(&mb, "(%d) %s", err->xerrno, strerror(err->xerrno)); else memBufPrintf(&mb, "[No Error]"); break; case 'f': /* FTP REQUEST LINE */ if (err->ftp.request) p = err->ftp.request; else p = "nothing"; break; case 'F': /* FTP REPLY LINE */ if (err->ftp.request) p = err->ftp.reply; else p = "nothing"; break; case 'g': /* FTP SERVER MESSAGE */ wordlistCat(err->ftp.server_msg, &mb); break; case 'h': memBufPrintf(&mb, "%s", getMyHostname()); break; case 'H': if (r) { if (r->hier.host) p = r->hier.host; else p = r->host; } else p = "[unknown host]"; break; case 'i': memBufPrintf(&mb, "%s", inet_ntoa(err->src_addr)); break; case 'I': if (r && r->hier.host) { memBufPrintf(&mb, "%s", r->hier.host); } else p = "[unknown]"; break; case 'L': if (Config.errHtmlText) { memBufPrintf(&mb, "%s", Config.errHtmlText); do_quote = 0; } else p = "[not available]"; break; case 'm': p = authenticateAuthUserRequestMessage(err->auth_user_request) ? authenticateAuthUserRequestMessage(err->auth_user_request) : "[not available]"; break; case 'M': p = r ? RequestMethods[r->method].str : "[unknown method]"; break; case 'o': p = external_acl_message; if (!p) p = "[not available]"; break; case 'p': if (r) { memBufPrintf(&mb, "%d", (int) r->port); } else { p = "[unknown port]"; } break; case 'P': p = r ? ProtocolStr[r->protocol] : "[unkown protocol]"; break; case 'R': if (NULL != r) { Packer p; memBufPrintf(&mb, "%s %s HTTP/%d.%d\n", RequestMethods[r->method].str, strLen(r->urlpath) ? strBuf(r->urlpath) : "/", r->http_ver.major, r->http_ver.minor); packerToMemInit(&p, &mb); httpHeaderPackInto(&r->header, &p); packerClean(&p); } else if (err->request_hdrs) { p = err->request_hdrs; } else { p = "[no request]"; } break; case 's': p = visible_appname_string; break; case 'S': /* signature may contain %-escapes, recursion */ if (err->page_id != ERR_SQUID_SIGNATURE) { const int saved_id = err->page_id; MemBuf sign_mb; err->page_id = ERR_SQUID_SIGNATURE; sign_mb = errorBuildContent(err); memBufPrintf(&mb, "%s", sign_mb.buf); memBufClean(&sign_mb); err->page_id = saved_id; do_quote = 0; } else { /* wow, somebody put %S into ERR_SIGNATURE, stop recursion */ p = "[%S]"; } break; case 't': memBufPrintf(&mb, "%s", mkhttpdlogtime(&squid_curtime)); break; case 'T': memBufPrintf(&mb, "%s", mkrfc1123(squid_curtime)); break; case 'U': p = r ? urlCanonicalClean(r) : err->url ? err->url : "[no URL]"; break; case 'u': p = r ? urlCanonical(r) : err->url ? err->url : "[no URL]"; break; case 'w': if (Config.adminEmail) memBufPrintf(&mb, "%s", Config.adminEmail); else p = "[unknown]"; break; case 'z': if (err->dnsserver_msg) p = err->dnsserver_msg; else p = "[unknown]"; break; case '%': p = "%"; break; default: memBufPrintf(&mb, "%%%c", token); do_quote = 0; break; } if (!p) p = mb.buf; /* do not use mb after this assignment! */ assert(p); debug(4, 3) ("errorConvert: %%%c --> '%s'\n", token, p); if (do_quote) p = html_quote(p); return p; }
void output_html_results(bool show_description, const std::string& tagname) { std::stringstream os; if(result_list.size()) { // // start by outputting the table header: // os << "<table border=\"1\" cellspacing=\"1\">\n"; os << "<tr><td><strong>Expression</strong></td>"; if(show_description) os << "<td><strong>Text</strong></td>"; #if defined(BOOST_HAS_GRETA) if(time_greta == true) os << "<td><strong>GRETA</strong></td>"; if(time_safe_greta == true) os << "<td><strong>GRETA<BR>(non-recursive mode)</strong></td>"; #endif if(time_boost == true) os << "<td><strong>Boost</strong></td>"; if(time_localised_boost == true) os << "<td><strong>Boost + C++ locale</strong></td>"; #if defined(BOOST_HAS_POSIX) if(time_posix == true) os << "<td><strong>POSIX</strong></td>"; #endif #ifdef BOOST_HAS_PCRE if(time_pcre == true) os << "<td><strong>PCRE</strong></td>"; #endif os << "</tr>\n"; // // Now enumerate through all the test results: // std::list<results>::const_iterator first, last; first = result_list.begin(); last = result_list.end(); while(first != last) { os << "<tr><td><code>" << html_quote(first->expression) << "</code></td>"; if(show_description) os << "<td>" << html_quote(first->description) << "</td>"; #if defined(BOOST_HAS_GRETA) if(time_greta == true) { print_result(os, first->greta_time, first->factor); if(first->greta_time > 0) { greta_total += first->greta_time / first->factor; ++greta_test_count; } } if(time_safe_greta == true) { print_result(os, first->safe_greta_time, first->factor); if(first->safe_greta_time > 0) { safe_greta_total += first->safe_greta_time / first->factor; ++safe_greta_test_count; } } #endif #if defined(BOOST_HAS_POSIX) if(time_boost == true) { print_result(os, first->boost_time, first->factor); if(first->boost_time > 0) { boost_total += first->boost_time / first->factor; ++boost_test_count; } } if(time_localised_boost == true) { print_result(os, first->localised_boost_time, first->factor); if(first->localised_boost_time > 0) { locale_boost_total += first->localised_boost_time / first->factor; ++locale_boost_test_count; } } #endif if(time_posix == true) { print_result(os, first->posix_time, first->factor); if(first->posix_time > 0) { posix_total += first->posix_time / first->factor; ++posix_test_count; } } #if defined(BOOST_HAS_PCRE) if(time_pcre == true) { print_result(os, first->pcre_time, first->factor); if(first->pcre_time > 0) { pcre_total += first->pcre_time / first->factor; ++pcre_test_count; } } #endif os << "</tr>\n"; ++first; } os << "</table>\n"; result_list.clear(); } else { os << "<P><I>Results not available...</I></P>\n"; } std::string result = os.str(); std::string::size_type pos = html_contents.find(tagname); if(pos != std::string::npos) { html_contents.replace(pos, tagname.size(), result); } }
/* Borrow part of code from libwww2 came with Mosaic distribution */ static void gopherToHTML(GopherStateData * gopherState, char *inbuf, int len) { char *pos = inbuf; char *lpos = NULL; char *tline = NULL; LOCAL_ARRAY(char, line, TEMP_BUF_SIZE); LOCAL_ARRAY(char, tmpbuf, TEMP_BUF_SIZE); String outbuf = StringNull; char *name = NULL; char *selector = NULL; char *host = NULL; char *port = NULL; char *escaped_selector = NULL; const char *icon_url = NULL; char gtype; StoreEntry *entry = NULL; memset(tmpbuf, '\0', TEMP_BUF_SIZE); memset(line, '\0', TEMP_BUF_SIZE); entry = gopherState->entry; if (gopherState->conversion == HTML_INDEX_PAGE) { char *html_url = html_quote(storeUrl(entry)); gopherHTMLHeader(entry, "Gopher Index %s", html_url); storeAppendPrintf(entry, "<p>This is a searchable Gopher index. Use the search\n" "function of your browser to enter search terms.\n" "<ISINDEX>\n"); gopherHTMLFooter(entry); /* now let start sending stuff to client */ storeBufferFlush(entry); gopherState->HTML_header_added = 1; return; } if (gopherState->conversion == HTML_CSO_PAGE) { char *html_url = html_quote(storeUrl(entry)); gopherHTMLHeader(entry, "CSO Search of %s", html_url); storeAppendPrintf(entry, "<P>A CSO database usually contains a phonebook or\n" "directory. Use the search function of your browser to enter\n" "search terms.</P><ISINDEX>\n"); gopherHTMLFooter(entry); /* now let start sending stuff to client */ storeBufferFlush(entry); gopherState->HTML_header_added = 1; return; } inbuf[len] = '\0'; if (!gopherState->HTML_header_added) { if (gopherState->conversion == HTML_CSO_RESULT) gopherHTMLHeader(entry, "CSO Search Result", NULL); else gopherHTMLHeader(entry, "Gopher Menu", NULL); strCat(outbuf, "<PRE>"); gopherState->HTML_header_added = 1; gopherState->HTML_pre = 1; } while ((pos != NULL) && (pos < inbuf + len)) { if (gopherState->len != 0) { /* there is something left from last tx. */ xstrncpy(line, gopherState->buf, gopherState->len + 1); if (gopherState->len + len > TEMP_BUF_SIZE) { debug(10, 1) ("GopherHTML: Buffer overflow. Lost some data on URL: %s\n", storeUrl(entry)); len = TEMP_BUF_SIZE - gopherState->len; } lpos = (char *) memccpy(line + gopherState->len, inbuf, '\n', len); if (lpos) *lpos = '\0'; else { /* there is no complete line in inbuf */ /* copy it to temp buffer */ if (gopherState->len + len > TEMP_BUF_SIZE) { debug(10, 1) ("GopherHTML: Buffer overflow. Lost some data on URL: %s\n", storeUrl(entry)); len = TEMP_BUF_SIZE - gopherState->len; } xmemcpy(gopherState->buf + gopherState->len, inbuf, len); gopherState->len += len; return; } /* skip one line */ pos = (char *) memchr(pos, '\n', len); if (pos) pos++; /* we're done with the remain from last tx. */ gopherState->len = 0; *(gopherState->buf) = '\0'; } else { lpos = (char *) memccpy(line, pos, '\n', len - (pos - inbuf)); if (lpos) *lpos = '\0'; else { /* there is no complete line in inbuf */ /* copy it to temp buffer */ if ((len - (pos - inbuf)) > TEMP_BUF_SIZE) { debug(10, 1) ("GopherHTML: Buffer overflow. Lost some data on URL: %s\n", storeUrl(entry)); len = TEMP_BUF_SIZE; } if (len > (pos - inbuf)) { xmemcpy(gopherState->buf, pos, len - (pos - inbuf)); gopherState->len = len - (pos - inbuf); } break; } /* skip one line */ pos = (char *) memchr(pos, '\n', len); if (pos) pos++; } /* at this point. We should have one line in buffer to process */ if (*line == '.') { /* skip it */ memset(line, '\0', TEMP_BUF_SIZE); continue; } switch (gopherState->conversion) { case HTML_INDEX_RESULT: case HTML_DIR:{ tline = line; gtype = *tline++; name = tline; selector = strchr(tline, TAB); if (selector) { *selector++ = '\0'; host = strchr(selector, TAB); if (host) { *host++ = '\0'; port = strchr(host, TAB); if (port) { char *junk; port[0] = ':'; junk = strchr(host, TAB); if (junk) *junk++ = 0; /* Chop port */ else { junk = strchr(host, '\r'); if (junk) *junk++ = 0; /* Chop port */ else { junk = strchr(host, '\n'); if (junk) *junk++ = 0; /* Chop port */ } } if ((port[1] == '0') && (!port[2])) port[0] = 0; /* 0 means none */ } /* escape a selector here */ escaped_selector = xstrdup(rfc1738_escape_part(selector)); switch (gtype) { case GOPHER_DIRECTORY: icon_url = mimeGetIconURL("internal-menu"); break; case GOPHER_HTML: case GOPHER_FILE: icon_url = mimeGetIconURL("internal-text"); break; case GOPHER_INDEX: case GOPHER_CSO: icon_url = mimeGetIconURL("internal-index"); break; case GOPHER_IMAGE: case GOPHER_GIF: case GOPHER_PLUS_IMAGE: icon_url = mimeGetIconURL("internal-image"); break; case GOPHER_SOUND: case GOPHER_PLUS_SOUND: icon_url = mimeGetIconURL("internal-sound"); break; case GOPHER_PLUS_MOVIE: icon_url = mimeGetIconURL("internal-movie"); break; case GOPHER_TELNET: case GOPHER_3270: icon_url = mimeGetIconURL("internal-telnet"); break; case GOPHER_BIN: case GOPHER_MACBINHEX: case GOPHER_DOSBIN: case GOPHER_UUENCODED: icon_url = mimeGetIconURL("internal-binary"); break; case GOPHER_INFO: icon_url = NULL; break; default: icon_url = mimeGetIconURL("internal-unknown"); break; } memset(tmpbuf, '\0', TEMP_BUF_SIZE); if ((gtype == GOPHER_TELNET) || (gtype == GOPHER_3270)) { if (strlen(escaped_selector) != 0) snprintf(tmpbuf, TEMP_BUF_SIZE, "<IMG border=\"0\" SRC=\"%s\"> <A HREF=\"telnet://%s@%s%s%s/\">%s</A>\n", icon_url, escaped_selector, rfc1738_escape_part(host), *port ? ":" : "", port, html_quote(name)); else snprintf(tmpbuf, TEMP_BUF_SIZE, "<IMG border=\"0\" SRC=\"%s\"> <A HREF=\"telnet://%s%s%s/\">%s</A>\n", icon_url, rfc1738_escape_part(host), *port ? ":" : "", port, html_quote(name)); } else if (gtype == GOPHER_INFO) { snprintf(tmpbuf, TEMP_BUF_SIZE, "\t%s\n", html_quote(name)); } else { if (strncmp(selector, "GET /", 5) == 0) { /* WWW link */ snprintf(tmpbuf, TEMP_BUF_SIZE, "<IMG border=\"0\" SRC=\"%s\"> <A HREF=\"http://%s/%s\">%s</A>\n", icon_url, host, rfc1738_escape_unescaped(selector + 5), html_quote(name)); } else { /* Standard link */ snprintf(tmpbuf, TEMP_BUF_SIZE, "<IMG border=\"0\" SRC=\"%s\"> <A HREF=\"gopher://%s/%c%s\">%s</A>\n", icon_url, host, gtype, escaped_selector, html_quote(name)); } } safe_free(escaped_selector); strCat(outbuf, tmpbuf); } else { memset(line, '\0', TEMP_BUF_SIZE); continue; } } else { memset(line, '\0', TEMP_BUF_SIZE); continue; } break; } /* HTML_DIR, HTML_INDEX_RESULT */ case HTML_CSO_RESULT:{ if (line[0] == '-') { int code, recno; char *s_code, *s_recno, *result; s_code = strtok(line + 1, ":\n"); s_recno = strtok(NULL, ":\n"); result = strtok(NULL, "\n"); if (!result) break; code = atoi(s_code); recno = atoi(s_recno); if (code != 200) break; if (gopherState->cso_recno != recno) { snprintf(tmpbuf, TEMP_BUF_SIZE, "</PRE><HR noshade size=\"1px\"><H2>Record# %d<br><i>%s</i></H2>\n<PRE>", recno, html_quote(result)); gopherState->cso_recno = recno; } else { snprintf(tmpbuf, TEMP_BUF_SIZE, "%s\n", html_quote(result)); } strCat(outbuf, tmpbuf); break; } else { int code; char *s_code, *result; s_code = strtok(line, ":"); result = strtok(NULL, "\n"); if (!result) break; code = atoi(s_code); switch (code) { case 200:{ /* OK */ /* Do nothing here */ break; } case 102: /* Number of matches */ case 501: /* No Match */ case 502: /* Too Many Matches */ { /* Print the message the server returns */ snprintf(tmpbuf, TEMP_BUF_SIZE, "</PRE><HR noshade size=\"1px\"><H2>%s</H2>\n<PRE>", html_quote(result)); strCat(outbuf, tmpbuf); break; } } } } /* HTML_CSO_RESULT */ default: break; /* do nothing */ } /* switch */ } /* while loop */ if (strLen(outbuf) > 0) { storeAppend(entry, strBuf(outbuf), strLen(outbuf)); /* now let start sending stuff to client */ storeBufferFlush(entry); } stringClean(&outbuf); return; }
void printMailcapPanel(char *mailcap) { FILE *f; Str tmp; char *type, *viewer; if ((f = fopen(mailcap, "rt")) == NULL) { if (errno != ENOENT) bye("Can't open", mailcap); if (!(f = fopen(mailcap, "a+"))) /* if $HOME/.mailcap is not found, make it now! */ bye("Can't open", mailcap); { char *SysMailcap = getenv("SYS_MAILCAP"); FILE *s = fopen(SysMailcap ? SysMailcap : "/etc/mailcap", "r"); if (s) { char buffer[256]; while (fgets(buffer, sizeof buffer, s)) /* Copy system mailcap to */ fputs(buffer, f); /* users' new one */ fclose(s); rewind(f); } } } #if LANG == JA /* FIXME: gettextize here */ printf("Content-Type: text/html; charset=EUC-JP\n\n"); #else printf("Content-Type: text/html\n\n"); #endif printf("<html>\n<head>\n<title>%s</title>\n</head>\n<body>\n<h1>%s</h1>\n", MSG_TITLE, MSG_TITLE); printf("<form method=post action=\"file:///$LIB/" W3MHELPERPANEL_CMDNAME "\">\n"); printf("<input type=hidden name=mode value=edit>\n"); printf("<input type=hidden name=cookie value=\"%s\">\n", html_quote(local_cookie)); printf("<table>\n<tr><td>%s:<td>%s=<input type=text name=newtype size=40>\n\ <tr><td><td>%s=<input type=text name=newcmd size=40>\n\ <tr><td><input type=submit name=submit value=\"%s\">\n</table>\n", MSG_NEW_ENTRY, MSG_TYPE, MSG_COMMAND, MSG_REGISTER); printf("<p><hr width=50%%><p>\n<table border='0' cellpadding='0'>\n\ <tr><th align=left><b>%s</b><th><b>%s</b>\n", MSG_TYPE, MSG_COMMAND); while (tmp = Strfgets(f), tmp->length > 0) { if (tmp->ptr[0] == '#') continue; Strchop(tmp); extractMailcapEntry(tmp->ptr, &type, &viewer); printf("<tr valign=top><td>%s<td>%s<td nowrap>", html_quote(type), html_quote(viewer)); printf("<input type=checkbox name=delete value=\"%s\">%s\n", html_quote(type), MSG_DELETE); } printf("</table>\n<input type=submit name=submit value=\"%s\">\n</form>\n\ </body>\n</html>\n", MSG_DOIT); fclose(f); }
Str loadNewsgroup0(ParsedURL *pu) #endif { volatile Str page; Str tmp; URLFile f; Buffer *buf; char *qgroup, *p, *q, *s, *t, *n; char *volatile scheme, *volatile group, *volatile list; int status, i, first, last; volatile int flag = 0, start = 0, end = 0; MySignalHandler(*volatile prevtrap) (SIGNAL_ARG) = NULL; #ifdef USE_M17N wc_ces doc_charset = DocumentCharset, mime_charset; *charset = WC_CES_US_ASCII; #endif if (current_news.host == NULL || !pu->file || *pu->file == '\0') return NULL; group = allocStr(pu->file, -1); if (pu->scheme == SCM_NNTP_GROUP) scheme = "/"; else scheme = "news:"; if ((list = strchr(group, '/'))) { /* <newsgroup>/<start-number>-<end-number> */ *list++ = '\0'; } if (fmInitialized) { message(Sprintf("Reading newsgroup %s...", group)->ptr, 0, 0); refresh(); } qgroup = html_quote(group); group = file_unquote(group); page = Strnew_m_charp("<html>\n<head>\n<base href=\"", parsedURL2Str(pu)->ptr, "\">\n<title>Newsgroup: ", qgroup, "</title>\n</head>\n<body>\n<h1>Newsgroup: ", qgroup, "</h1>\n<hr>\n", NULL); if (SETJMP(AbortLoading) != 0) { news_close(¤t_news); Strcat_charp(page, "</table>\n<p>Transfer Interrupted!\n"); goto news_end; } TRAP_ON; tmp = news_command(¤t_news, "GROUP", group, &status); if (status != 211) goto news_list; if (sscanf(tmp->ptr, "%d %d %d %d", &status, &i, &first, &last) != 4) goto news_list; if (list && *list) { if ((p = strchr(list, '-'))) { *p++ = '\0'; end = atoi(p); } start = atoi(list); if (start > 0) { if (start < first) start = first; if (end <= 0) end = start + MaxNewsMessage - 1; } } if (start <= 0) { start = first; end = last; if (end - start > MaxNewsMessage - 1) start = end - MaxNewsMessage + 1; } page = Sprintf("<html>\n<head>\n<base href=\"%s\">\n\ <title>Newsgroup: %s %d-%d</title>\n\ </head>\n<body>\n<h1>Newsgroup: %s %d-%d</h1>\n<hr>\n", parsedURL2Str(pu)->ptr, qgroup, start, end, qgroup, start, end); if (start > first) { i = start - MaxNewsMessage; if (i < first) i = first; Strcat(page, Sprintf("<a href=\"%s%s/%d-%d\">[%d-%d]</a>\n", scheme, qgroup, i, start - 1, i, start - 1)); } Strcat_charp(page, "<table>\n"); news_command(¤t_news, "XOVER", Sprintf("%d-%d", start, end)->ptr, &status); if (status == 224) { f.scheme = SCM_NEWS; while (true) { tmp = StrISgets(current_news.rf); if (NEWS_ENDLINE(tmp->ptr)) break; if (sscanf(tmp->ptr, "%d", &i) != 1) continue; if (!(s = strchr(tmp->ptr, '\t'))) continue; s++; if (!(n = strchr(s, '\t'))) continue; *n++ = '\0'; if (!(t = strchr(n, '\t'))) continue; *t++ = '\0'; if (!(p = strchr(t, '\t'))) continue; *p++ = '\0'; if (*p == '<') p++; if (!(q = strchr(p, '>')) && !(q = strchr(p, '\t'))) continue; *q = '\0'; tmp = decodeMIME(Strnew_charp(s), &mime_charset); s = convertLine(&f, tmp, HEADER_MODE, mime_charset ? &mime_charset : charset, mime_charset ? mime_charset : doc_charset)->ptr; tmp = decodeMIME(Strnew_charp(n), &mime_charset); n = convertLine(&f, tmp, HEADER_MODE, mime_charset ? &mime_charset : charset, mime_charset ? mime_charset : doc_charset)->ptr; add_news_message(page, i, t, n, s, p, scheme, pu->scheme == SCM_NNTP_GROUP ? qgroup : NULL); } } else { init_stream(&f, SCM_NEWS, current_news.rf); buf = newBuffer(INIT_BUFFER_WIDTH); for (i = start; i <= end && i <= last; i++) { news_command(¤t_news, "HEAD", Sprintf("%d", i)->ptr, &status); if (status != 221) continue; readHeader(&f, buf, FALSE, NULL); if (!(p = checkHeader(buf, "Message-ID:"))) continue; if (*p == '<') p++; if (!(q = strchr(p, '>')) && !(q = strchr(p, '\t'))) *q = '\0'; if (!(s = checkHeader(buf, "Subject:"))) continue; if (!(n = checkHeader(buf, "From:"))) continue; if (!(t = checkHeader(buf, "Date:"))) continue; add_news_message(page, i, t, n, s, p, scheme, pu->scheme == SCM_NNTP_GROUP ? qgroup : NULL); } } Strcat_charp(page, "</table>\n"); if (end < last) { i = end + MaxNewsMessage; if (i > last) i = last; Strcat(page, Sprintf("<a href=\"%s%s/%d-%d\">[%d-%d]</a>\n", scheme, qgroup, end + 1, i, end + 1, i)); } flag = 1; news_list: tmp = Sprintf("ACTIVE %s", group); if (!strchr(group, '*')) Strcat_charp(tmp, ".*"); news_command(¤t_news, "LIST", tmp->ptr, &status); if (status != 215) goto news_end; while (true) { tmp = StrISgets(current_news.rf); if (NEWS_ENDLINE(tmp->ptr)) break; if (flag < 2) { if (flag == 1) Strcat_charp(page, "<hr>\n"); Strcat_charp(page, "<table>\n"); flag = 2; } p = tmp->ptr; for (q = p; *q && !IS_SPACE(*q); q++) ; *(q++) = '\0'; if (sscanf(q, "%d %d", &last, &first) == 2 && last >= first) i = last - first + 1; else i = 0; Strcat(page, Sprintf ("<tr><td align=right>%d<td><a href=\"%s%s\">%s</a>\n", i, scheme, html_quote(file_quote(p)), html_quote(p))); } if (flag == 2) Strcat_charp(page, "</table>\n"); news_end: Strcat_charp(page, "</body>\n</html>\n"); TRAP_OFF; return page; }
int insert_bookmark(char *bmark, struct parsed_tagarg *data) { char *url, *title, *section; FILE *f; TextList *tl = newTextList(); int section_found = 0; int bmark_added = 0; Str tmp, section_tmp; url = tag_get_value(data, "url"); title = tag_get_value(data, "title"); section = tag_get_value(data, "newsection"); if (section == NULL || *section == '\0') section = tag_get_value(data, "section"); if (section == NULL || *section == '\0') section = DEFAULT_SECTION; if (url == NULL || *url == '\0' || title == NULL || *title == '\0') { /* Bookmark not added */ return FALSE; } url = html_quote(url); title = html_quote(title); section = html_quote(section); f = fopen(bmark, "r"); if (f == NULL) return create_new_bookmark(bmark, section, title, url, "w"); section_tmp = Sprintf("<h2>%s</h2>\n", section); for (;;) { tmp = Strfgets(f); if (tmp->length == 0) break; if (Strcasecmp(tmp, section_tmp) == 0) section_found = 1; if (section_found && !bmark_added) { Strremovefirstspaces(tmp); if (Strcmp_charp(tmp, end_section) == 0) { pushText(tl, Sprintf("<li><a href=\"%s\">%s</a>\n", url, title)->ptr); bmark_added = 1; } } if (!bmark_added && Strcasecmp_charp(tmp, "</body>\n") == 0) { pushText(tl, Sprintf("<h2>%s</h2>\n<ul>\n", section)->ptr); pushText(tl, Sprintf("<li><a href=\"%s\">%s</a>\n", url, title)->ptr); pushText(tl, end_section); pushText(tl, "</ul>\n"); bmark_added = 1; } pushText(tl, tmp->ptr); } fclose(f); if (!bmark_added) { /* Bookmark not added; perhaps the bookmark file is ill-formed */ /* In this case, a new bookmark is appeneded after the bookmark file */ return create_new_bookmark(bmark, section, title, url, "a"); } f = fopen(bmark, "w"); while (tl->nitem) { fputs(popText(tl), f); } fclose(f); return TRUE; }
static int createFrameFile(struct frameset *f, FILE * f1, Buffer *current, int level, int force_reload) { int r, c, t_stack; URLFile f2; #ifdef USE_M17N wc_ces charset, doc_charset; #endif char *d_target, *p_target, *s_target, *t_target; ParsedURL *currentURL, base; MySignalHandler(*volatile prevtrap) (SIGNAL_ARG) = NULL; int flag; if (f == NULL) return -1; if (level == 0) { if (SETJMP(AbortLoading) != 0) { TRAP_OFF; return -1; } TRAP_ON; f->name = "_top"; } if (level > 7) { fputs("Too many frameset tasked.\n", f1); return -1; } if (level == 0) { fprintf(f1, "<html><head><title>%s</title></head><body>\n", html_quote(current->buffername)); fputs("<table hborder width=\"100%\">\n", f1); } else fputs("<table hborder>\n", f1); currentURL = f->currentURL ? f->currentURL : ¤t->currentURL; for (r = 0; r < f->row; r++) { fputs("<tr valign=top>\n", f1); for (c = 0; c < f->col; c++) { union frameset_element frame; struct frameset *f_frameset; int i = c + r * f->col; char *p = ""; int status = R_ST_NORMAL; Str tok = Strnew(); int pre_mode = 0; int end_tag = 0; frame = f->frame[i]; if (frame.element == NULL) { fputs("<td>\n</td>\n", f1); continue; } fputs("<td", f1); if (frame.element->name) fprintf(f1, " id=\"_%s\"", html_quote(frame.element->name)); if (!r) fprintf(f1, " width=\"%s\"", f->width[c]); fputs(">\n", f1); flag = 0; if (force_reload) { flag |= RG_NOCACHE; if (frame.element->attr == F_BODY) unloadFrame(frame.body); } switch (frame.element->attr) { default: /* FIXME: gettextize? */ fprintf(f1, "Frameset \"%s\" frame %d: type unrecognized", html_quote(f->name), i + 1); break; case F_UNLOADED: if (!frame.body->name && f->name) { frame.body->name = Sprintf("%s_%d", f->name, i)->ptr; } fflush(f1); f_frameset = frame_download_source(frame.body, currentURL, current->baseURL, flag); if (f_frameset) { deleteFrame(frame.body); f->frame[i].set = frame.set = f_frameset; goto render_frameset; } /* fall through */ case F_BODY: init_stream(&f2, SCM_LOCAL, NULL); if (frame.body->source) { fflush(f1); examineFile(frame.body->source, &f2); } if (f2.stream == NULL) { frame.body->attr = F_UNLOADED; if (frame.body->flags & FB_NO_BUFFER) /* FIXME: gettextize? */ fprintf(f1, "Open %s with other method", html_quote(frame.body->url)); else if (frame.body->url) /* FIXME: gettextize? */ fprintf(f1, "Can't open %s", html_quote(frame.body->url)); else /* FIXME: gettextize? */ fprintf(f1, "This frame (%s) contains no src attribute", frame.body->name ? html_quote(frame.body->name) : "(no name)"); break; } parseURL2(frame.body->url, &base, currentURL); p_target = f->name; s_target = frame.body->name; t_target = "_blank"; d_target = TargetSelf ? s_target : t_target; #ifdef USE_M17N charset = WC_CES_US_ASCII; if (current->document_charset != WC_CES_US_ASCII) doc_charset = current->document_charset; else doc_charset = DocumentCharset; #endif t_stack = 0; if (frame.body->type && !strcasecmp(frame.body->type, "text/plain")) { Str tmp; fprintf(f1, "<pre>\n"); while ((tmp = StrmyUFgets(&f2))->length) { tmp = convertLine(NULL, tmp, HTML_MODE, &charset, doc_charset); fprintf(f1, "%s", html_quote(tmp->ptr)); } fprintf(f1, "</pre>\n"); UFclose(&f2); break; } do { int is_tag = FALSE; char *q; struct parsed_tag *tag; do { if (*p == '\0') { Str tmp = StrmyUFgets(&f2); if (tmp->length == 0) break; tmp = convertLine(NULL, tmp, HTML_MODE, &charset, doc_charset); p = tmp->ptr; } read_token(tok, &p, &status, 1, status != R_ST_NORMAL); } while (status != R_ST_NORMAL); if (tok->length == 0) continue; if (tok->ptr[0] == '<') { if (tok->ptr[1] && REALLY_THE_BEGINNING_OF_A_TAG(tok->ptr)) is_tag = TRUE; else if (!(pre_mode & (RB_PLAIN | RB_INTXTA | RB_SCRIPT | RB_STYLE))) { p = Strnew_m_charp(tok->ptr + 1, p, NULL)->ptr; tok = Strnew_charp("<"); } } if (is_tag) { if (pre_mode & (RB_PLAIN | RB_INTXTA | RB_SCRIPT | RB_STYLE)) { q = tok->ptr; if ((tag = parse_tag(&q, FALSE)) && tag->tagid == end_tag) { if (pre_mode & RB_PLAIN) { fputs("</PRE_PLAIN>", f1); pre_mode = 0; end_tag = 0; goto token_end; } pre_mode = 0; end_tag = 0; goto proc_normal; } if (strncmp(tok->ptr, "<!--", 4) && (q = strchr(tok->ptr + 1, '<'))) { tok = Strnew_charp_n(tok->ptr, q - tok->ptr); p = Strnew_m_charp(q, p, NULL)->ptr; status = R_ST_NORMAL; } is_tag = FALSE; } else if (pre_mode & RB_INSELECT) { q = tok->ptr; if ((tag = parse_tag(&q, FALSE))) { if ((tag->tagid == end_tag) || (tag->tagid == HTML_N_FORM)) { if (tag->tagid == HTML_N_FORM) fputs("</SELECT>", f1); pre_mode = 0; end_tag = 0; goto proc_normal; } if (t_stack) { switch (tag->tagid) { case HTML_TABLE: case HTML_N_TABLE: CASE_TABLE_TAG: fputs("</SELECT>", f1); pre_mode = 0; end_tag = 0; goto proc_normal; } } } } } proc_normal: if (is_tag) { char *q = tok->ptr; int j, a_target = 0; ParsedURL url; if (!(tag = parse_tag(&q, FALSE))) goto token_end; switch (tag->tagid) { case HTML_TITLE: fputs("<!-- title:", f1); goto token_end; case HTML_N_TITLE: fputs("-->", f1); goto token_end; case HTML_BASE: /* "BASE" is prohibit tag */ if (parsedtag_get_value(tag, ATTR_HREF, &q)) { q = url_encode(remove_space(q), NULL, charset); parseURL(q, &base, NULL); } if (parsedtag_get_value(tag, ATTR_TARGET, &q)) { if (!strcasecmp(q, "_self")) d_target = s_target; else if (!strcasecmp(q, "_parent")) d_target = p_target; else d_target = url_quote_conv(q, charset); } Strshrinkfirst(tok, 1); Strshrink(tok, 1); fprintf(f1, "<!-- %s -->", html_quote(tok->ptr)); goto token_end; case HTML_META: if (parsedtag_get_value(tag, ATTR_HTTP_EQUIV, &q) && !strcasecmp(q, "refresh")) { if (parsedtag_get_value(tag, ATTR_CONTENT, &q) ) { Str s_tmp = NULL; int refresh_interval = getMetaRefreshParam(q, &s_tmp); if (s_tmp) { q = html_quote(s_tmp->ptr); fprintf(f1, "Refresh (%d sec) <a href=\"%s\">%s</a>\n", refresh_interval, q, q); } } } #ifdef USE_M17N if (UseContentCharset && parsedtag_get_value(tag, ATTR_HTTP_EQUIV, &q) && !strcasecmp(q, "Content-Type") && parsedtag_get_value(tag, ATTR_CONTENT, &q) && (q = strcasestr(q, "charset")) != NULL) { q += 7; SKIP_BLANKS(q); if (*q == '=') { wc_ces c; q++; SKIP_BLANKS(q); if ((c = wc_guess_charset(q, 0)) != 0) { doc_charset = c; charset = WC_CES_US_ASCII; } } } #endif /* fall thru, "META" is prohibit tag */ case HTML_HEAD: case HTML_N_HEAD: case HTML_BODY: case HTML_N_BODY: case HTML_DOCTYPE: /* prohibit_tags */ Strshrinkfirst(tok, 1); Strshrink(tok, 1); fprintf(f1, "<!-- %s -->", html_quote(tok->ptr)); goto token_end; case HTML_TABLE: t_stack++; break; case HTML_N_TABLE: t_stack--; if (t_stack < 0) { t_stack = 0; Strshrinkfirst(tok, 1); Strshrink(tok, 1); fprintf(f1, "<!-- table stack underflow: %s -->", html_quote(tok->ptr)); goto token_end; } break; CASE_TABLE_TAG: /* table_tags MUST be in table stack */ if (!t_stack) { Strshrinkfirst(tok, 1); Strshrink(tok, 1); fprintf(f1, "<!-- %s -->", html_quote(tok->ptr)); goto token_end; } break; case HTML_SELECT: pre_mode = RB_INSELECT; end_tag = HTML_N_SELECT; break; case HTML_TEXTAREA: pre_mode = RB_INTXTA; end_tag = HTML_N_TEXTAREA; break; case HTML_SCRIPT: pre_mode = RB_SCRIPT; end_tag = HTML_N_SCRIPT; break; case HTML_STYLE: pre_mode = RB_STYLE; end_tag = HTML_N_STYLE; break; case HTML_LISTING: pre_mode = RB_PLAIN; end_tag = HTML_N_LISTING; fputs("<PRE_PLAIN>", f1); goto token_end; case HTML_XMP: pre_mode = RB_PLAIN; end_tag = HTML_N_XMP; fputs("<PRE_PLAIN>", f1); goto token_end; case HTML_PLAINTEXT: pre_mode = RB_PLAIN; end_tag = MAX_HTMLTAG; fputs("<PRE_PLAIN>", f1); goto token_end; default: break; } for (j = 0; j < TagMAP[tag->tagid].max_attribute; j++) { switch (tag->attrid[j]) { case ATTR_SRC: case ATTR_HREF: case ATTR_ACTION: if (!tag->value[j]) break; tag->value[j] = url_encode(remove_space(tag->value[j]), &base, charset); tag->need_reconstruct = TRUE; parseURL2(tag->value[j], &url, &base); if (url.scheme == SCM_UNKNOWN || #ifndef USE_W3MMAILER url.scheme == SCM_MAILTO || #endif url.scheme == SCM_MISSING) break; a_target |= 1; tag->value[j] = parsedURL2Str(&url)->ptr; parsedtag_set_value(tag, ATTR_REFERER, parsedURL2Str(&base)->ptr); #ifdef USE_M17N if (tag->attrid[j] == ATTR_ACTION && charset != WC_CES_US_ASCII) parsedtag_set_value(tag, ATTR_CHARSET, wc_ces_to_charset (charset)); #endif break; case ATTR_TARGET: if (!tag->value[j]) break; a_target |= 2; if (!strcasecmp(tag->value[j], "_self")) { parsedtag_set_value(tag, ATTR_TARGET, s_target); } else if (!strcasecmp(tag->value[j], "_parent")) { parsedtag_set_value(tag, ATTR_TARGET, p_target); } break; case ATTR_NAME: case ATTR_ID: if (!tag->value[j]) break; parsedtag_set_value(tag, ATTR_FRAMENAME, s_target); break; } } if (a_target == 1) { /* there is HREF attribute and no TARGET * attribute */ parsedtag_set_value(tag, ATTR_TARGET, d_target); } if (parsedtag_need_reconstruct(tag)) tok = parsedtag2str(tag); Strfputs(tok, f1); } else { if (pre_mode & RB_PLAIN) fprintf(f1, "%s", html_quote(tok->ptr)); else if (pre_mode & RB_INTXTA) fprintf(f1, "%s", html_quote(html_unquote(tok->ptr))); else Strfputs(tok, f1); } token_end: Strclear(tok); } while (*p != '\0' || !iseos(f2.stream)); if (pre_mode & RB_PLAIN) fputs("</PRE_PLAIN>\n", f1); else if (pre_mode & RB_INTXTA) fputs("</TEXTAREA></FORM>\n", f1); else if (pre_mode & RB_INSELECT) fputs("</SELECT></FORM>\n", f1); else if (pre_mode & (RB_SCRIPT | RB_STYLE)) { if (status != R_ST_NORMAL) fputs(correct_irrtag(status)->ptr, f1); if (pre_mode & RB_SCRIPT) fputs("</SCRIPT>\n", f1); else if (pre_mode & RB_STYLE) fputs("</STYLE>\n", f1); } while (t_stack--) fputs("</TABLE>\n", f1); UFclose(&f2); break; case F_FRAMESET: render_frameset: if (!frame.set->name && f->name) { frame.set->name = Sprintf("%s_%d", f->name, i)->ptr; } createFrameFile(frame.set, f1, current, level + 1, force_reload); break; } fputs("</td>\n", f1); } fputs("</tr>\n", f1); } fputs("</table>\n", f1); if (level == 0) { fputs("</body></html>\n", f1); TRAP_OFF; } return 0; }
Buffer * load_option_panel(void) { Str src; struct param_ptr *p; struct sel_c *s; #ifdef USE_M17N wc_ces_list *c; #endif int x, i; Str tmp; Buffer *buf; if (optionpanel_str == NULL) optionpanel_str = Sprintf(optionpanel_src1, w3m_version, html_quote(localCookie()->ptr), _(CMT_HELPER)); #ifdef USE_M17N #ifdef ENABLE_NLS OptionCharset = SystemCharset; /* FIXME */ #endif if (!OptionEncode) { optionpanel_str = wc_Str_conv(optionpanel_str, OptionCharset, InnerCharset); for (i = 0; sections[i].name != NULL; i++) { sections[i].name = wc_conv(_(sections[i].name), OptionCharset, InnerCharset)->ptr; for (p = sections[i].params; p->name; p++) { p->comment = wc_conv(_(p->comment), OptionCharset, InnerCharset)->ptr; if (p->inputtype == PI_SEL_C #ifdef USE_COLOR && p->select != colorstr #endif ) { for (s = (struct sel_c *)p->select; s->text != NULL; s++) { s->text = wc_conv(_(s->text), OptionCharset, InnerCharset)->ptr; } } } } #ifdef USE_COLOR for (s = colorstr; s->text; s++) s->text = wc_conv(_(s->text), OptionCharset, InnerCharset)->ptr; #endif OptionEncode = TRUE; } #endif src = Strdup(optionpanel_str); Strcat_charp(src, "<table><tr><td>"); for (i = 0; sections[i].name != NULL; i++) { Strcat_m_charp(src, "<h1>", sections[i].name, "</h1>", NULL); p = sections[i].params; Strcat_charp(src, "<table width=100% cellpadding=0>"); while (p->name) { Strcat_m_charp(src, "<tr><td>", p->comment, NULL); Strcat(src, Sprintf("</td><td width=%d>", (int)(28 * pixel_per_char))); switch (p->inputtype) { case PI_TEXT: Strcat_m_charp(src, "<input type=text name=", p->name, " value=\"", html_quote(to_str(p)->ptr), "\">", NULL); break; case PI_ONOFF: x = atoi(to_str(p)->ptr); Strcat_m_charp(src, "<input type=radio name=", p->name, " value=1", (x ? " checked" : ""), ">YES <input type=radio name=", p->name, " value=0", (x ? "" : " checked"), ">NO", NULL); break; case PI_SEL_C: tmp = to_str(p); Strcat_m_charp(src, "<select name=", p->name, ">", NULL); for (s = (struct sel_c *)p->select; s->text != NULL; s++) { Strcat_charp(src, "<option value="); Strcat(src, Sprintf("%s\n", s->cvalue)); if ((p->type != P_CHAR && s->value == atoi(tmp->ptr)) || (p->type == P_CHAR && (char)s->value == *(tmp->ptr))) Strcat_charp(src, " selected"); Strcat_char(src, '>'); Strcat_charp(src, s->text); } Strcat_charp(src, "</select>"); break; #ifdef USE_M17N case PI_CODE: tmp = to_str(p); Strcat_m_charp(src, "<select name=", p->name, ">", NULL); for (c = *(wc_ces_list **) p->select; c->desc != NULL; c++) { Strcat_charp(src, "<option value="); Strcat(src, Sprintf("%s\n", c->name)); if (c->id == atoi(tmp->ptr)) Strcat_charp(src, " selected"); Strcat_char(src, '>'); Strcat_charp(src, c->desc); } Strcat_charp(src, "</select>"); break; #endif } Strcat_charp(src, "</td></tr>\n"); p++; } Strcat_charp(src, "<tr><td></td><td><p><input type=submit value=\"OK\"></td></tr>"); Strcat_charp(src, "</table><hr width=50%>"); } Strcat_charp(src, "</table></form></body></html>"); buf = loadHTMLString(src); #ifdef USE_M17N if (buf) buf->document_charset = OptionCharset; #endif return buf; }
Str loadFTPDir0(ParsedURL *pu) #endif { Str FTPDIRtmp; Str tmp; int status; volatile int sv_type; char *realpathname, *fn, *q; char **flist; int i, nfile, nfile_max; MySignalHandler(*volatile prevtrap) (SIGNAL_ARG) = NULL; #ifdef USE_M17N wc_ces doc_charset = DocumentCharset; *charset = WC_CES_US_ASCII; #endif if (current_ftp.data == NULL) return NULL; tmp = ftp_command(¤t_ftp, "SYST", NULL, &status); if (strstr(tmp->ptr, "UNIX") != NULL || !strncmp(tmp->ptr + 4, "Windows_NT", 10)) /* :-) */ sv_type = UNIXLIKE_SERVER; else sv_type = SERVER_NONE; if (pu->file == NULL || *pu->file == '\0') { if (sv_type == UNIXLIKE_SERVER) ftp_command(¤t_ftp, "LIST", NULL, &status); else ftp_command(¤t_ftp, "NLST", NULL, &status); pu->file = "/"; } else { realpathname = file_unquote(pu->file); if (*realpathname == '/' && *(realpathname + 1) == '~') realpathname++; if (sv_type == UNIXLIKE_SERVER) { ftp_command(¤t_ftp, "CWD", realpathname, &status); if (status == 250) ftp_command(¤t_ftp, "LIST", NULL, &status); } else ftp_command(¤t_ftp, "NLST", realpathname, &status); } if (status != 125 && status != 150) { fclose(current_ftp.data); current_ftp.data = NULL; return NULL; } tmp = parsedURL2Str(pu); if (Strlastchar(tmp) != '/') Strcat_char(tmp, '/'); fn = html_quote(tmp->ptr); tmp = convertLine(NULL, Strnew_charp(file_unquote(tmp->ptr)), RAW_MODE, charset, doc_charset); q = html_quote(tmp->ptr); FTPDIRtmp = Strnew_m_charp("<html>\n<head>\n<base href=\"", fn, "\">\n<title>", q, "</title>\n</head>\n<body>\n<h1>Index of ", q, "</h1>\n", NULL); if (SETJMP(AbortLoading) != 0) { if (sv_type == UNIXLIKE_SERVER) Strcat_charp(FTPDIRtmp, "</a></pre>\n"); else Strcat_charp(FTPDIRtmp, "</a></ul>\n"); Strcat_charp(FTPDIRtmp, "<p>Transfer Interrupted!\n"); goto ftp_end; } TRAP_ON; if (sv_type == UNIXLIKE_SERVER) Strcat_charp(FTPDIRtmp, "<pre>\n"); else Strcat_charp(FTPDIRtmp, "<ul>\n<li>"); Strcat_charp(FTPDIRtmp, "<a href=\"..\">[Upper Directory]</a>\n"); nfile_max = 100; flist = New_N(char *, nfile_max); nfile = 0; if (sv_type == UNIXLIKE_SERVER) { char *name, *link, *date, *size, *type_str; int ftype, max_len, len, j; max_len = 20; while (tmp = Strfgets(current_ftp.data), tmp->length > 0) { Strchop(tmp); if ((ftype = ex_ftpdir_name_size_date(tmp->ptr, &name, &link, &date, &size)) == FTPDIR_NONE) continue; if (!strcmp(".", name) || !strcmp("..", name)) continue; len = strlen(name); if (!len) continue; if (ftype == FTPDIR_DIR) { len++; type_str = "/"; } else if (ftype == FTPDIR_LINK) { len++; type_str = "@"; } else { type_str = " "; } if (max_len < len) max_len = len; flist[nfile++] = Sprintf("%s%s\n%s %5s%s", name, type_str, date, size, link)->ptr; if (nfile == nfile_max) { nfile_max *= 2; flist = New_Reuse(char *, flist, nfile_max); } }
Buffer * link_list_panel(Buffer *buf) { LinkList *l; AnchorList *al; Anchor *a; FormItemList *fi; int i; char *t, *u, *p; ParsedURL pu; /* FIXME: gettextize? */ Str tmp = Strnew_charp("<title>Link List</title>\ <h1 align=center>Link List</h1>\n"); if (buf->bufferprop & BP_INTERNAL || (buf->linklist == NULL && buf->href == NULL && buf->img == NULL)) { return NULL; } if (buf->linklist) { Strcat_charp(tmp, "<hr><h2>Links</h2>\n<ol>\n"); for (l = buf->linklist; l; l = l->next) { if (l->url) { parseURL2(l->url, &pu, baseURL(buf)); p = parsedURL2Str(&pu)->ptr; u = html_quote(p); if (DecodeURL) p = html_quote(url_decode2(p, buf)); else p = u; } else u = p = ""; if (l->type == LINK_TYPE_REL) t = " [Rel]"; else if (l->type == LINK_TYPE_REV) t = " [Rev]"; else t = ""; t = Sprintf("%s%s\n", l->title ? l->title : "", t)->ptr; t = html_quote(t); Strcat_m_charp(tmp, "<li><a href=\"", u, "\">", t, "</a><br>", p, "\n", NULL); } Strcat_charp(tmp, "</ol>\n"); } if (buf->href) { Strcat_charp(tmp, "<hr><h2>Anchors</h2>\n<ol>\n"); al = buf->href; for (i = 0; i < al->nanchor; i++) { a = &al->anchors[i]; if (a->hseq < 0 || a->slave) continue; parseURL2(a->url, &pu, baseURL(buf)); p = parsedURL2Str(&pu)->ptr; u = html_quote(p); if (DecodeURL) p = html_quote(url_decode2(p, buf)); else p = u; t = getAnchorText(buf, al, a); t = t ? html_quote(t) : ""; Strcat_m_charp(tmp, "<li><a href=\"", u, "\">", t, "</a><br>", p, "\n", NULL); } Strcat_charp(tmp, "</ol>\n"); } if (buf->img) { Strcat_charp(tmp, "<hr><h2>Images</h2>\n<ol>\n"); al = buf->img; for (i = 0; i < al->nanchor; i++) { a = &al->anchors[i]; if (a->slave) continue; parseURL2(a->url, &pu, baseURL(buf)); p = parsedURL2Str(&pu)->ptr; u = html_quote(p); if (DecodeURL) p = html_quote(url_decode2(p, buf)); else p = u; if (a->title && *a->title) t = html_quote(a->title); else t = html_quote(url_decode2(a->url, buf)); Strcat_m_charp(tmp, "<li><a href=\"", u, "\">", t, "</a><br>", p, "\n", NULL); a = retrieveAnchor(buf->formitem, a->start.line, a->start.pos); if (!a) continue; fi = (FormItemList *)a->url; fi = fi->parent->item; if (fi->parent->method == FORM_METHOD_INTERNAL && !Strcmp_charp(fi->parent->action, "map") && fi->value) { MapList *ml = searchMapList(buf, fi->value->ptr); ListItem *mi; MapArea *m; if (!ml) continue; Strcat_charp(tmp, "<br>\n<b>Image map</b>\n<ol>\n"); for (mi = ml->area->first; mi != NULL; mi = mi->next) { m = (MapArea *) mi->ptr; if (!m) continue; parseURL2(m->url, &pu, baseURL(buf)); p = parsedURL2Str(&pu)->ptr; u = html_quote(p); if (DecodeURL) p = html_quote(url_decode2(p, buf)); else p = u; if (m->alt && *m->alt) t = html_quote(m->alt); else t = html_quote(url_decode2(m->url, buf)); Strcat_m_charp(tmp, "<li><a href=\"", u, "\">", t, "</a><br>", p, "\n", NULL); } Strcat_charp(tmp, "</ol>\n"); } } Strcat_charp(tmp, "</ol>\n"); } return loadHTMLString(tmp); }