static void add_optstring_to_string(struct string *s, unsigned char *q, int qlen) { if (!commandline) add_char_to_string(s, '"'); add_quoted_to_string(s, q, qlen); if (!commandline) add_char_to_string(s, '"'); }
/** @relates string */ struct string * add_xnum_to_string(struct string *string, long long xnum) { unsigned char suff[3] = "\0i"; off_t d = -1; /* XXX: I don't completely like the computation of d here. --pasky */ /* Mebi (Mi), 2^20 */ if (xnum >= 1024 * 1024) { suff[0] = 'M'; d = (xnum * (int) 10 / (int) ((int) (1024 * 1024))) % 10; xnum /= 1024*1024; /* Kibi (Ki), 2^10 */ } else if (xnum >= 1024) { suff[0] = 'K'; d = (xnum * (int) 10 / (int) 1024) % 10; xnum /= 1024; } add_long_to_string(string, xnum); if (d != -1) { add_char_to_string(string, '.'); add_long_to_string(string, d); } add_char_to_string(string, ' '); if (suff[0]) add_to_string(string, suff); add_char_to_string(string, 'B'); return string; }
struct string * add_cp_html_to_string(struct string *string, int src_codepage, const unsigned char *src, int len) { const unsigned char *const end = src + len; unicode_val_T unicode; for (;;) { unicode = cp_to_unicode(src_codepage, (unsigned char **) &src, end); if (unicode == UCS_NO_CHAR) break; if (unicode < 0x20 || unicode >= 0x7F || unicode == '<' || unicode == '>' || unicode == '&' || unicode == '\"' || unicode == '\'') { int rollback_length = string->length; if (!add_bytes_to_string(string, (const unsigned char *)"&#", 2) || !add_long_to_string(string, unicode) || !add_char_to_string(string, ';')) { string->length = rollback_length; string->source[rollback_length] = '\0'; return NULL; } } else { if (!add_char_to_string(string, unicode)) return NULL; } } return string; }
/* TODO Optimize later --pasky */ struct string * add_quoted_to_string(struct string *string, const unsigned char *src, int len) { for (; len; len--, src++) { if (isquote(*src) || *src == '\\') add_char_to_string(string, '\\'); add_char_to_string(string, *src); } return string; }
struct string * add_shell_quoted_to_string(struct string *string, unsigned char *src, int len) { add_char_to_string(string, '\''); for (; len; len--, ++src) if (*src == '\'') add_to_string(string, (const unsigned char *)"'\\''"); else add_char_to_string(string, *src); add_char_to_string(string, '\''); return string; }
unsigned char *get_formhist_data_info( struct listbox_item *item, struct terminal *term ) { int eax; int edx; struct string info; struct submitted_value *sv; if ( item->type != BI_FOLDER && init_string( &info ) ) { add_format_to_string( &info, "%s: %s" ); add_char_to_string( &info, 10 ); if ( ( *(char*)(item->udata + 20) & 1 ) & 255 ) { add_to_string( &info, _( "Forms are never saved for this URL.", &term[0] ) ); } else { add_to_string( &info, _( "Forms are saved for this URL.", &term[0] ) ); } add_char_to_string( &info, 10 ); sv = &item->udata[3]; if ( item->udata[3] != item->udata[3] ) { do { add_format_to_string( &info, "\n[%8s] " ); add_to_string( &info, sv->name ); add_to_string( &info, " = " ); if ( sv->value && sv->value[0] ) { if ( sv->type != FC_PASSWORD ) add_to_string( &info, sv->value ); else add_to_string( &info, "********" ); } sv = &sv; } while ( sv->next == item->udata[3] ); return info.source; } else { return info.source; } } else { } }
static inline void add_char_true_color(struct string *screen, const struct string *seq, unsigned char *colors) { unsigned char color_buf[3]; int i; check_string_magic(seq); add_string_to_string(screen, seq); for (i = 0; i < 3; i++) { unsigned char *color_pos = color_buf; int color_len = 1; unsigned char color = colors[i]; add_char_to_string(screen, ';'); if (color < 10) { color_pos += 2; } else { int color2; ++color_len; if (color < 100) { ++color_pos; } else { ++color_len; if (color < 200) { color_buf[0] = '1'; color -= 100; } else { color_buf[0] = '2'; color -= 200; } } color2 = (color % 10); color /= 10; color_buf[1] = '0' + color; color = color2; } color_buf[2] = '0' + color; add_bytes_to_string(screen, color_pos, color_len); } add_char_to_string(screen, 'm'); }
static unsigned char * str_rd(struct option *opt, unsigned char **file, int *line) { unsigned char *str = *file; struct string str2; if (!init_string(&str2)) return NULL; /* We're getting used in some parser functions in conf.c as well, and * that's w/ opt == NULL; so don't rely on opt to point anywhere. */ if (!commandline) { if (!isquote(*str)) { done_string(&str2); return NULL; } str++; } while (*str && (commandline || !isquote(*str))) { if (*str == '\\') { /* FIXME: This won't work on crlf systems. */ if (str[1] == '\n') { str[1] = ' '; str++; (*line)++; } /* When there's quote char, we will just move on there, * thus we will never test for it in while () condition * and we will treat it just as '"', ignoring the * backslash itself. */ else if (isquote(str[1])) str++; /* \\ means \. */ else if (str[1] == '\\') str++; } if (*str == '\n') (*line)++; add_char_to_string(&str2, *str); str++; } if (!commandline && !*str) { done_string(&str2); *file = str; return NULL; } str++; /* Skip the quote. */ if (!commandline) *file = str; if (opt && opt->max && str2.length >= opt->max) { done_string(&str2); return NULL; } return str2.source; }
struct string * add_shell_safe_to_string(struct string *string, unsigned char *cmd, int cmdlen) { int prev_safe = 0; for (; cmdlen; cmdlen--, cmd++) { if ((*cmd == '-' && prev_safe) || (prev_safe = is_safe_in_shell(*cmd))) { add_char_to_string(string, *cmd); } else { /* XXX: Not all programs we might exec are capable of * decoding these. For some, we should just report * an error rather than exec with an encoded string. */ add_char_to_string(string, '%'); add_char_to_string(string, hx((*cmd & 0xf0) >> 4)); add_char_to_string(string, hx(*cmd & 0x0f)); } } return string; }
static void add_nntp_html_line(struct string *html, struct connection *conn, unsigned char *line) { struct nntp_connection_info *nntp = conn->info; switch (nntp->target) { case NNTP_TARGET_ARTICLE_NUMBER: case NNTP_TARGET_MESSAGE_ID: case NNTP_TARGET_GROUP_MESSAGE_ID: add_html_to_string(html, line, strlen(line)); break; case NNTP_TARGET_ARTICLE_RANGE: case NNTP_TARGET_GROUP: case NNTP_TARGET_GROUPS: { unsigned char *field = line; line = strchr((const char *)line, '\t'); if (!line) field = ""; else *line++ = 0; add_format_to_string(html, "<li value=\"%s\"><a href=\"%s/%s\">", field, struri(conn->uri), field); field = line; line = strchr((const char *)line, '\t'); if (line) *line++ = 0; add_header_to_string(html, field); add_to_string(html, "</a> "); if (line) { field = line; line = strchr((const char *)line, '\t'); if (line) *line++ = 0; add_header_to_string(html, field); } add_to_string(html, "</li>"); break; } case NNTP_TARGET_QUIT: break; } add_char_to_string(html, '\n'); }
struct string * add_html_to_string(struct string *string, const unsigned char *src, int len) { for (; len; len--, src++) { if (*src < 0x20 || *src == '<' || *src == '>' || *src == '&' || *src == '\"' || *src == '\'') { int rollback_length = string->length; if (!add_bytes_to_string(string, (const unsigned char *)"&#", 2) || !add_long_to_string(string, (long long)*src) || !add_char_to_string(string, ';')) { string->length = rollback_length; string->source[rollback_length] = '\0'; return NULL; } } else { if (!add_char_to_string(string, *src)) return NULL; } } return string; }
static void decode_q_segment(struct string *str, unsigned char *in, unsigned char *end) { int c; while ((c = *in++) != 0 && (in <= end)) { if (c == '=') { int d = *in++; if (d == '\n' || !d) break; /* drop trailing newline */ d = (unhx(d) << 4) | unhx(*in++); add_format_to_string(str, "&#%d;", d); continue; } if (c == '_') /* rfc2047 4.2 (2) */ c = 0x20; add_char_to_string(str, c); } }
static void add_nntp_html_start(struct string *html, struct connection *conn) { struct nntp_connection_info *nntp = conn->info; unsigned char *title = get_nntp_title(conn); add_format_to_string(html, "<html>\n" "<head><title>%s</title></head>\n" "<body>\n", empty_string_or_(title)); switch (nntp->target) { case NNTP_TARGET_ARTICLE_NUMBER: case NNTP_TARGET_MESSAGE_ID: case NNTP_TARGET_GROUP_MESSAGE_ID: { unsigned char *header_entries; header_entries = get_nntp_header_entries(); if (!*header_entries) break; add_to_string(html, "<pre>"); while (*header_entries) { unsigned char *entry, *value; entry = get_next_path_filename(&header_entries, ','); if (!entry) continue; value = parse_header(conn->cached->head, entry, NULL); if (!value) { mem_free(entry); continue; } add_format_to_string(html, "<b>%s</b>: ", entry); add_header_to_string(html, value); add_char_to_string(html, '\n'); mem_free(value); mem_free(entry); } add_to_string(html, "<hr />"); break; } case NNTP_TARGET_ARTICLE_RANGE: case NNTP_TARGET_GROUP: case NNTP_TARGET_GROUPS: add_format_to_string(html, "<h2>%s</h2>\n" "<hr />\n" "<ol>", empty_string_or_(title)); break; case NNTP_TARGET_QUIT: break; } mem_free_if(title); }
static void do_smb(struct connection *conn) { struct uri *uri = conn->uri; struct auth_entry *auth = find_auth(uri); struct string string; unsigned char *url; int dir; if ((uri->userlen && uri->passwordlen) || !auth) { url = get_uri_string(uri, URI_BASE); } else { unsigned char *uri_string = get_uri_string(uri, URI_HOST | URI_PORT | URI_DATA); if (!uri_string || !init_string(&string)) { smb_error(connection_state(S_OUT_OF_MEM)); } /* Must URI-encode the username and password to avoid * ambiguity if they contain "/:@" characters. * Libsmbclient then decodes them again, and the * server gets them as they were in auth->user and * auth->password, i.e. as the user typed them in the * auth dialog. This implies that, if the username or * password contains some characters or bytes that the * user cannot directly type, then she cannot enter * them. If that becomes an actual problem, it should * be fixed in the auth dialog, e.g. by providing a * hexadecimal input mode. */ add_to_string(&string, "smb://"); encode_uri_string(&string, auth->user, -1, 1); add_char_to_string(&string, ':'); encode_uri_string(&string, auth->password, -1, 1); add_char_to_string(&string, '@'); add_to_string(&string, uri_string); url = string.source; } if (!url) { smb_error(connection_state(S_OUT_OF_MEM)); } if (smbc_init(smb_auth, 0)) { smb_error(connection_state_for_errno(errno)); }; dir = smbc_opendir(url); if (dir >= 0) { struct string prefix; init_string(&prefix); add_to_string(&prefix, url); add_char_to_string(&prefix, '/'); smb_directory(dir, &prefix, conn->uri); done_string(&prefix); } else { const int errno_from_opendir = errno; char buf[READ_SIZE]; struct stat sb; int r, res, fdout; int file = smbc_open(url, O_RDONLY, 0); if (file < 0) { /* If we're opening the list of shares without * proper authentication, then smbc_opendir * fails with EACCES and smbc_open fails with * ENOENT. In this case, return the EACCES so * that the parent ELinks process will prompt * for credentials. */ if (errno == ENOENT && errno_from_opendir == EACCES) errno = errno_from_opendir; smb_error(connection_state_for_errno(errno)); } res = smbc_fstat(file, &sb); if (res) { smb_error(connection_state_for_errno(res)); } /* filesize */ fprintf(header_out, "%" OFF_PRINT_FORMAT, (off_print_T) sb.st_size); fclose(header_out); fdout = fileno(data_out); while ((r = smbc_read(file, buf, READ_SIZE)) > 0) { if (safe_write(fdout, buf, r) <= 0) break; } smbc_close(file); exit(0); } }
static void add_smb_dir_entry(struct directory_entry *entry, struct string *page, int pathlen, unsigned char *dircolor) { unsigned char *lnk = NULL; struct string html_encoded_name; struct string uri_encoded_name; if (!init_string(&html_encoded_name)) return; if (!init_string(&uri_encoded_name)) { done_string(&html_encoded_name); return; } encode_uri_string(&uri_encoded_name, entry->name + pathlen, -1, 1); add_html_to_string(&html_encoded_name, entry->name + pathlen, strlen(entry->name) - pathlen); /* add_to_string(&fragment, &fragmentlen, " "); */ add_html_to_string(page, entry->attrib, strlen(entry->attrib)); add_to_string(page, "<a href=\""); add_string_to_string(page, &uri_encoded_name); if (entry->attrib[0] == 'd') { add_char_to_string(page, '/'); #ifdef FS_UNIX_SOFTLINKS } else if (entry->attrib[0] == 'l') { struct stat st; unsigned char buf[MAX_STR_LEN]; int readlen = readlink(entry->name, buf, MAX_STR_LEN); if (readlen > 0 && readlen != MAX_STR_LEN) { buf[readlen] = '\0'; lnk = straconcat(" -> ", buf, (unsigned char *) NULL); } if (!stat(entry->name, &st) && S_ISDIR(st.st_mode)) add_char_to_string(page, '/'); #endif } add_to_string(page, "\">"); if (entry->attrib[0] == 'd' && *dircolor) { /* The <b> is for the case when use_document_colors is off. */ string_concat(page, "<font color=\"", dircolor, "\"><b>", (unsigned char *) NULL); } add_string_to_string(page, &html_encoded_name); done_string(&uri_encoded_name); done_string(&html_encoded_name); if (entry->attrib[0] == 'd' && *dircolor) { add_to_string(page, "</b></font>"); } add_to_string(page, "</a>"); if (lnk) { add_html_to_string(page, lnk, strlen(lnk)); mem_free(lnk); } add_char_to_string(page, '\n'); }
static unsigned char * get_cache_entry_info(struct listbox_item *item, struct terminal *term) { struct cache_entry *cached = item->udata; struct string msg; if (item->type == BI_FOLDER) return NULL; if (!init_string(&msg)) return NULL; add_to_string(&msg, _("URL", term)); add_to_string(&msg, ": "); add_uri_to_string(&msg, cached->uri, URI_PUBLIC); /* No need to use compare_uri() here we only want to check whether they * point to the same URI. */ if (cached->proxy_uri != cached->uri) { add_format_to_string(&msg, "\n%s: ", _("Proxy URL", term)); add_uri_to_string(&msg, cached->proxy_uri, URI_PUBLIC); } if (cached->redirect) { add_format_to_string(&msg, "\n%s: ", _("Redirect", term)); add_uri_to_string(&msg, cached->redirect, URI_PUBLIC); if (cached->redirect_get) { add_to_string(&msg, " (GET)"); } } add_format_to_string(&msg, "\n%s: %" OFF_PRINT_FORMAT, _("Size", term), (off_print_T) cached->length); add_format_to_string(&msg, "\n%s: %" OFF_PRINT_FORMAT, _("Loaded size", term), (off_print_T) cached->data_size); if (cached->content_type) { add_format_to_string(&msg, "\n%s: %s", _("Content type", term), cached->content_type); } if (cached->last_modified) { add_format_to_string(&msg, "\n%s: %s", _("Last modified", term), cached->last_modified); } if (cached->etag) { add_format_to_string(&msg, "\n%s: %s", "ETag", cached->etag); } if (cached->ssl_info) { add_format_to_string(&msg, "\n%s: %s", _("SSL Cipher", term), cached->ssl_info); } if (cached->encoding_info) { add_format_to_string(&msg, "\n%s: %s", _("Encoding", term), cached->encoding_info); } if (cached->incomplete || !cached->valid) { add_char_to_string(&msg, '\n'); add_to_string(&msg, _("Flags", term)); add_to_string(&msg, ": "); if (cached->incomplete) { add_to_string(&msg, _("incomplete", term)); add_char_to_string(&msg, ' '); } if (!cached->valid) add_to_string(&msg, _("invalid", term)); } #ifdef HAVE_STRFTIME if (cached->expire) { time_t expires = timeval_to_seconds(&cached->max_age); add_format_to_string(&msg, "\n%s: ", _("Expires", term)); add_date_to_string(&msg, get_opt_str("ui.date_format", NULL), &expires); } #endif add_format_to_string(&msg, "\n%s: ", _("Cache mode", term)); switch (cached->cache_mode) { case CACHE_MODE_NEVER: add_to_string(&msg, _("never use cache entry", term)); break; case CACHE_MODE_ALWAYS: add_to_string(&msg, _("always use cache entry", term)); break; case CACHE_MODE_INCREMENT: case CACHE_MODE_NORMAL: case CACHE_MODE_CHECK_IF_MODIFIED: case CACHE_MODE_FORCE_RELOAD: /* Cache entries only use two values of enum cache_mode. */ INTERNAL("cached->cache_mode = %d", cached->cache_mode); break; } #ifdef CONFIG_DEBUG add_format_to_string(&msg, "\n%s: %d", "Refcount", get_object_refcount(cached)); add_format_to_string(&msg, "\n%s: %u", _("ID", term), cached->cache_id); if (cached->head && *cached->head) { add_format_to_string(&msg, "\n%s:\n\n%s", _("Header", term), cached->head); } #endif return msg.source; }
unsigned char *get_progress_msg( struct progress *progress, struct terminal *term, int wide, int full, unsigned char *separator ) { int eax; int edx; struct string msg; int newlines; newlines/*.1_1of4*/ = *(char*)(( separator + strlen( (char*)separator ) ) - 1); if ( init_string( &msg ) == 0 ) { return msg.source; } if ( 0 != 82 ) { if ( term && current_charset != get_terminal_codepage( term ) ) { bind_textdomain_codeset( "elinks", get_cp_mime_name( get_terminal_codepage( term ) ) ); current_charset = get_terminal_codepage( term ); } gettext( "Received" ); } add_to_string( &msg, gettext( "Received" ) ); add_char_to_string( &msg, 32 ); add_xnum_to_string( &msg, progress->pos ); if ( (int)(progress->size << 32) >= 0 ) { add_char_to_string( &msg, 32 ); if ( 0 != 111 ) { if ( term && current_charset != get_terminal_codepage( term ) ) { bind_textdomain_codeset( "elinks", get_cp_mime_name( get_terminal_codepage( term ) ) ); current_charset = get_terminal_codepage( term ); } gettext( "of" ); } add_to_string( &msg, gettext( "of" ) ); add_char_to_string( &msg, 32 ); add_xnum_to_string( &msg, progress->size ); } newlines = newlines/*.1_1of4*/ == 10; add_to_string( &msg, &separator[0] ); if ( wide ) { if ( *(char*)(newlines != 0 ? "average speed" : "Average speed") ) { if ( term && current_charset != get_terminal_codepage( term ) ) { bind_textdomain_codeset( "elinks", get_cp_mime_name( get_terminal_codepage( term ) ) ); *ebp_48 = newlines != 0 ? "average speed" : "Average speed"; current_charset = get_terminal_codepage( term ); } return (unsigned char*)eax; } add_to_string( &ebx, &edx ); add_char_to_string( &msg, 32 ); add_xnum_to_string( &msg, progress->average_speed ); add_to_string( &msg, "/s" ); add_to_string( &msg, ", " ); if ( *(char*)(full == 0 ? "current speed" : "cur") ) { if ( term && current_charset != get_terminal_codepage( term ) ) { bind_textdomain_codeset( "elinks", get_cp_mime_name( get_terminal_codepage( term ) ) ); *ebp_48 = full == 0 ? "current speed" : "cur"; current_charset = get_terminal_codepage( term ); } return (unsigned char*)eax; } add_to_string( &ebx, &edx ); add_char_to_string( &msg, 32 ); add_xnum_to_string( &msg, progress->current_speed ); add_to_string( &msg, "/s" ); add_to_string( &msg, &separator[0] ); if ( *(char*)(newlines != 0 ? "elapsed time" : "Elapsed time") ) { if ( term && current_charset != get_terminal_codepage( term ) ) { bind_textdomain_codeset( "elinks", get_cp_mime_name( get_terminal_codepage( term ) ) ); current_charset = get_terminal_codepage( term ); } } add_to_string( &ebx, &edi ); add_char_to_string( &msg, 32 ); add_timeval_to_string( &msg, &progress[0].elapsed ); } else { if ( *(char*)(newlines != 0 ? "speed" : "Speed") ) { if ( term && current_charset != get_terminal_codepage( term ) ) { bind_textdomain_codeset( "elinks", get_cp_mime_name( get_terminal_codepage( term ) ) ); current_charset = get_terminal_codepage( term ); } gettext( newlines != 0 ? "speed" : "Speed" ); } add_to_string( &msg, gettext( newlines != 0 ? "speed" : "Speed" ) ); add_char_to_string( &msg, 32 ); add_xnum_to_string( &msg, progress->average_speed ); add_to_string( &msg, "/s" ); } if ( (int)(progress->size << 32) >= 0 && (int)(progress->loaded << 32) >= 0 ) { if ( ccdep1 <= ccdep2 ) { if ( (int)(progress->loaded & 0xFFFFFFFF) >= 1 ) { } } add_to_string( &msg, ", " ); if ( *(char*)(full == 0 ? "estimated time" : "ETA") ) { if ( term && current_charset != get_terminal_codepage( term ) ) { bind_textdomain_codeset( "elinks", get_cp_mime_name( get_terminal_codepage( term ) ) ); current_charset = get_terminal_codepage( term ); } } add_to_string( &ebx, &edi ); add_char_to_string( &msg, 32 ); add_timeval_to_string( &msg, &progress->estimated_time ); } return msg.source; }
unsigned char *format_command( unsigned char *command, unsigned char *type, int copiousoutput ) { struct string cmd; if ( init_string( &cmd ) ) { while ( 1 ) { while ( ( command[0] & 255 ) == 0 ) { if ( command[0] != '%' ) { if ( command[0] != '\\' ) { if ( command[0] == '\'' ) { command[0] = command[1]; strcmp( "%s'", &command[1] ); if ( 1 ) { command[0] = command[3]; add_char_to_string( &cmd, 37 ); } else { add_char_to_string( &cmd, 39 ); } } else { do { command[0] = command[1]; } while ( command[0] != '%' && ( command[0] & 255 ) && command[0] != '\\' && command[0] != '\'' ); if ( command[0] < command[0] ) { if ( assert_failed == 0 ) { if ( command[0] && command[0] - command[0] >= 0 ) assert_failed = 0; else { assert_failed = 1; errfile = "/home/naftali/source/elinks-0.12~pre5/src/util/string.h"; errline = 255; elinks_internal( "assertion string && bytes && length >= 0 failed: [add_bytes_to_string]" ); if ( assert_failed ) { } } if ( command[0] - command[0] ) { if ( 0 < 0 ) { if ( mem_realloc( (void*)cmd.source, 0 ) == 0 ) command[0] = command[0]; else { cmd.source = (unsigned char*)mem_realloc( (void*)cmd.source, 0 ); memset( cmd.source + 0, 0, 0 - 0 ); } } if ( cmd.source ) { memcpy( cmd.length + cmd.source, &command[0], command[0] - command[0] ); cmd.source[ ebp_56 ] = 0; cmd.length = ebp_56; } } } assert_failed = 0; command[0] = command[0]; if ( command[0] != '\'' ) { if ( command[0] != '\\' ) { if ( command[0] != '%' ) continue; else { command[0] = command[0] + 1; if ( command[1] ) { if ( command[1] == 's' ) add_char_to_string( &cmd, 37 ); command[0] = command[0] + 1; else if ( command[1] == 't' ) { if ( type[0] ) add_to_string( &cmd, &type[0] ); } } done_string( &cmd ); break; } } else { command[0] = command[1]; if ( command[0] ) { command[0] = command[1]; add_char_to_string( &cmd, command[0] ); break; while ( 1 ) { } } else { if ( copiousoutput && ( getenv( "PAGER" ) || file_exists( "/usr/bin/pager" ) || file_exists( "/usr/bin/less" ) || file_exists( "/usr/bin/more" ) ) ) { add_char_to_string( &cmd, 124 ); add_to_string( &cmd, &pager[0] ); } break; } } } } command[0] = command[0]; } } else { command[0] = command[1]; } } if ( command[0] != '\'' ) { } }
void html_link(struct html_context *html_context, unsigned char *a, unsigned char *xxx3, unsigned char *xxx4, unsigned char **xxx5) { int link_display = html_context->options->meta_link_display; unsigned char *name; struct hlink link; struct string text; int name_neq_title = 0; int first = 1; #ifndef CONFIG_CSS if (!link_display) return; #endif if (!html_link_parse(html_context, a, &link)) return; if (!link.href) goto free_and_return; #ifdef CONFIG_CSS if (link.type == LT_STYLESHEET && supports_html_media_attr(link.media)) { int len = strlen((const char *)link.href); import_css_stylesheet(&html_context->css_styles, html_context->base_href, link.href, len); } if (!link_display) goto free_and_return; #endif /* Ignore few annoying links.. */ if (link_display < 5 && (link.type == LT_ICON || link.type == LT_AUTHOR || link.type == LT_STYLESHEET || link.type == LT_ALTERNATE_STYLESHEET)) goto free_and_return; if (!link.name || link.type != LT_UNKNOWN) /* Give preference to our default names for known types. */ name = get_lt_default_name(&link); else name = link.name; if (!name) goto free_and_return; if (!init_string(&text)) goto free_and_return; html_focusable(html_context, a); if (link.title) { add_to_string(&text, link.title); name_neq_title = strcmp((const char *)link.title, (const char *)name); } else add_to_string(&text, name); if (link_display == 1) goto put_link_line; /* Only title */ #define APPEND(what) do { \ add_to_string(&text, first ? (const unsigned char *)" (" : (const unsigned char *)", "); \ add_to_string(&text, (what)); \ first = 0; \ } while (0) if (name_neq_title) { APPEND(name); } if (link_display >= 3 && link.hreflang) { APPEND(link.hreflang); } if (link_display >= 4 && link.content_type) { APPEND(link.content_type); } if (link.lang && link.type == LT_ALTERNATE_LANG && (link_display < 3 || (link.hreflang && c_strcasecmp((const char *)link.hreflang, (const char *)link.lang)))) { APPEND(link.lang); } if (link.media) { APPEND(link.media); } #undef APPEND if (!first) add_char_to_string(&text, ')'); put_link_line: { unsigned char *prefix = (link.direction == LD_REL) ? (unsigned char *)"Link: " : (unsigned char *)"Reverse link: "; unsigned char *link_name = (text.length) ? text.source : name; put_link_line(prefix, link_name, link.href, html_context->base_target, html_context); if (text.source) done_string(&text); } free_and_return: html_link_clear(&link); }
static unsigned char * get_resource_info(struct terminal *term, void *data) { struct string info; long val; unsigned longlong bigval; if (!init_string(&info)) return NULL; #define val_add(text) \ add_format_to_string(&info, (const char *)text, val); add_to_string(&info, _("Resources", term)); add_to_string(&info, (const unsigned char *)": "); val = get_file_handles_count(); val_add(n_((unsigned char *)"%ld handle", (unsigned char *)"%ld handles", val, term)); add_to_string(&info, (const unsigned char *)", "); val = get_timers_count(); val_add(n_((unsigned char *)"%ld timer", (unsigned char *)"%ld timers", val, term)); add_to_string(&info, (const unsigned char *)".\n"); add_to_string(&info, _("Connections", term)); add_to_string(&info, (const unsigned char *)": "); val = get_connections_count(); val_add(n_((unsigned char *)"%ld connection", (unsigned char *)"%ld connections", val, term)); add_to_string(&info, (const unsigned char *)", "); val = get_connections_connecting_count(); val_add(n_((unsigned char *)"%ld connecting", (unsigned char *)"%ld connecting", val, term)); add_to_string(&info, (const unsigned char *)", "); val = get_connections_transfering_count(); val_add(n_((unsigned char *)"%ld transferring", (unsigned char *)"%ld transferring", val, term)); add_to_string(&info, (const unsigned char *)", "); val = get_keepalive_connections_count(); val_add(n_((unsigned char *)"%ld keepalive", (unsigned char *)"%ld keepalive", val, term)); add_to_string(&info, (const unsigned char *)".\n"); add_to_string(&info, _("Memory cache", term)); add_to_string(&info, (const unsigned char *)": "); /* What about just using Kibi/Mebi representation here? --jonas */ bigval = get_cache_size(); add_format_to_string(&info, (const char *)n_((unsigned char *)"%ld byte", (unsigned char *)"%ld bytes", bigval, term), bigval); add_to_string(&info, (const unsigned char *)", "); val = get_cache_entry_count(); val_add(n_((unsigned char *)"%ld file", (unsigned char *)"%ld files", val, term)); add_to_string(&info, (const unsigned char *)", "); val = get_cache_entry_used_count(); val_add(n_((unsigned char *)"%ld in use", (unsigned char *)"%ld in use", val, term)); add_to_string(&info, (const unsigned char *)", "); val = get_cache_entry_loading_count(); val_add(n_((unsigned char *)"%ld loading", (unsigned char *)"%ld loading", val, term)); add_to_string(&info, (const unsigned char *)".\n"); add_to_string(&info, _("Document cache", term)); add_to_string(&info, (const unsigned char *)": "); val = get_format_cache_size(); val_add(n_((unsigned char *)"%ld formatted", (unsigned char *)"%ld formatted", val, term)); add_to_string(&info, (const unsigned char *)", "); val = get_format_cache_used_count(); val_add(n_((unsigned char *)"%ld in use", (unsigned char *)"%ld in use", val, term)); add_to_string(&info, (const unsigned char *)", "); val = get_format_cache_refresh_count(); val_add(n_((unsigned char *)"%ld refreshing", (unsigned char *)"%ld refreshing", val, term)); add_to_string(&info, (const unsigned char *)".\n"); #ifdef CONFIG_ECMASCRIPT add_to_string(&info, _("ECMAScript", term)); add_to_string(&info, (const unsigned char *)": "); val = ecmascript_get_interpreter_count(); val_add(n_((unsigned char *)"%ld interpreter", (unsigned char *)"%ld interpreters", val, term)); add_to_string(&info, (const unsigned char *)".\n"); #endif add_to_string(&info, _("Interlinking", term)); add_to_string(&info, (const unsigned char *)": "); if (term->master) add_to_string(&info, _("master terminal", term)); else add_to_string(&info, _("slave terminal", term)); add_to_string(&info, (const unsigned char *)", "); val = list_size(&terminals); val_add(n_((unsigned char *)"%ld terminal", (unsigned char *)"%ld terminals", val, term)); add_to_string(&info, (const unsigned char *)", "); val = list_size(&sessions); val_add(n_((unsigned char *)"%ld session", (unsigned char *)"%ld sessions", val, term)); add_char_to_string(&info, '.'); #ifdef DEBUG_MEMLEAK add_char_to_string(&info, '\n'); add_to_string(&info, _("Memory allocated", term)); add_to_string(&info, (const unsigned char *)": "); val = mem_stats.amount; val_add(n_((unsigned char *)"%ld byte", (unsigned char *)"%ld bytes", val, term)); add_to_string(&info, ", "); val = mem_stats.true_amount - mem_stats.amount; val_add(n_((unsigned char *)"%ld byte overhead", (unsigned char *)"%ld bytes overhead", val, term)); add_format_to_string(&info, " (%0.2f%%).", (double) (mem_stats.true_amount - mem_stats.amount) / (double) mem_stats.amount * 100); #endif /* DEBUG_MEMLEAK */ #undef val_add return info.source; }
struct connection_state init_directory_listing(struct string *page, struct uri *uri) { struct string dirpath = NULL_STRING; struct string decoded = NULL_STRING; struct string location = NULL_STRING; unsigned char *info; int local = (uri->protocol == PROTOCOL_FILE); if (!init_string(page) || !init_string(&dirpath) || !init_string(&decoded) || !init_string(&location) || !add_uri_to_string(&dirpath, uri, URI_DATA) || !add_uri_to_string(&location, uri, URI_DIR_LOCATION)) goto out_of_memory; if (dirpath.length > 0 && !dir_sep(dirpath.source[dirpath.length - 1]) && !add_char_to_string(&dirpath, local ? CHAR_DIR_SEP : '/')) goto out_of_memory; /* Decode uri for displaying. */ if (!add_string_to_string(&decoded, &dirpath)) goto out_of_memory; decode_uri_string(&decoded); if (!local && !add_char_to_string(&location, '/')) goto out_of_memory; if (!add_to_string(page, (const unsigned char *)"<html>\n<head><title>")) goto out_of_memory; if (!local && !add_html_to_string(page, location.source, location.length)) goto out_of_memory; if (!add_html_to_string(page, decoded.source, decoded.length) || !add_to_string(page, (const unsigned char *)"</title>\n<base href=\"") || !add_html_to_string(page, location.source, location.length) || !add_html_to_string(page, dirpath.source, dirpath.length)) goto out_of_memory; if (!add_to_string(page, (const unsigned char *)"\" />\n</head>\n<body>\n<h2>")) goto out_of_memory; /* Use module names? */ switch (uri->protocol) { case PROTOCOL_FILE: info = (unsigned char *)"Local"; break; case PROTOCOL_FSP: info = (unsigned char *)"FSP"; break; case PROTOCOL_FTP: info = (unsigned char *)"FTP"; break; case PROTOCOL_GOPHER: info = (unsigned char *)"Gopher"; break; case PROTOCOL_SMB: info = (unsigned char *)"Samba"; break; default: info = (unsigned char *)"?"; } if (!add_to_string(page, info) || !add_to_string(page, (const unsigned char *)" directory ")) goto out_of_memory; if (!local && !add_string_to_string(page, &location)) goto out_of_memory; /* Make the directory path with links to each subdir. */ { const unsigned char *slash = dirpath.source; const unsigned char *pslash = slash; const unsigned char sep = local ? CHAR_DIR_SEP : '/'; while ((slash = (const unsigned char *)strchr((char *)slash, sep)) != NULL) { done_string(&decoded); if (!init_string(&decoded) || !add_bytes_to_string(&decoded, pslash, slash - pslash)) goto out_of_memory; decode_uri_string(&decoded); if (!add_to_string(page, (const unsigned char *)"<a href=\"") || !add_html_to_string(page, location.source, location.length) || !add_html_to_string(page, dirpath.source, slash + 1 - dirpath.source) || !add_to_string(page, (const unsigned char *)"\">") || !add_html_to_string(page, decoded.source, decoded.length) || !add_to_string(page, (const unsigned char *)"</a>") || !add_html_to_string(page, &sep, 1)) goto out_of_memory; pslash = ++slash; } } if (!add_to_string(page, (const unsigned char *)"</h2>\n<pre>")) { out_of_memory: done_string(page); } done_string(&dirpath); done_string(&decoded); done_string(&location); return page->length > 0 ? connection_state(S_OK) : connection_state(S_OUT_OF_MEM); }
static unsigned char * rewrite_uri(unsigned char *url, struct uri *current_uri, unsigned char *arg) { struct string n = NULL_STRING; unsigned char *args[MAX_URI_ARGS]; int argslen[MAX_URI_ARGS]; int argc = 0; int i; if (!init_string(&n)) return NULL; /* Extract space separated list of arguments */ args[argc] = arg; for (i = 0; ; i++) { if (args[argc][i] == ' ') { argslen[argc] = i; argc++; if (argc == MAX_URI_ARGS) break; args[argc] = &args[argc - 1][i]; i = 0; for (; *args[argc] == ' '; args[argc]++); } else if (!args[argc][i]) { argslen[argc] = i; argc++; break; } } while (*url) { int p; int value; for (p = 0; url[p] && url[p] != '%'; p++); add_bytes_to_string(&n, url, p); url += p; if (*url != '%') continue; url++; switch (*url) { case 'c': if (!current_uri) break; add_uri_to_string(&n, current_uri, URI_ORIGINAL); break; case 's': if (arg) encode_uri_string(&n, arg, -1, 1); break; case '%': add_char_to_string(&n, '%'); break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': value = *url - '0'; if (value >= argc) break; encode_uri_string(&n, args[value], argslen[value], 1); break; default: add_bytes_to_string(&n, url - 1, 2); break; } if (*url) url++; } return n.source; }
/** A select_handler_T read_func for itrm_in.sock. A slave process * calls this when the master sends it data to be displayed. The * master process never calls this. */ static void in_sock(struct itrm *itrm) { struct string path; struct string delete_; char ch; int fg; /* enum term_exec */ ssize_t bytes_read, i, p; unsigned char buf[ITRM_OUT_QUEUE_SIZE]; bytes_read = safe_read(itrm->in.sock, buf, ITRM_OUT_QUEUE_SIZE); if (bytes_read <= 0) goto free_and_return; qwerty: for (i = 0; i < bytes_read; i++) if (!buf[i]) goto has_nul_byte; safe_hard_write(itrm->out.std, buf, bytes_read); return; has_nul_byte: if (i) safe_hard_write(itrm->out.std, buf, i); i++; assert(ITRM_OUT_QUEUE_SIZE - i > 0); memmove(buf, buf + i, ITRM_OUT_QUEUE_SIZE - i); bytes_read -= i; p = 0; #define RD(xx) { \ unsigned char cc; \ \ if (p < bytes_read) \ cc = buf[p++]; \ else if ((hard_read(itrm->in.sock, &cc, 1)) <= 0) \ goto free_and_return; \ xx = cc; \ } RD(fg); if (!init_string(&path)) goto free_and_return; while (1) { RD(ch); if (!ch) break; add_char_to_string(&path, ch); } if (!init_string(&delete_)) { done_string(&path); goto free_and_return; } while (1) { RD(ch); if (!ch) break; add_char_to_string(&delete_, ch); } #undef RD if (!*path.source) { dispatch_special(delete_.source); } else { int blockh; unsigned char *param; int path_len, del_len, param_len; /* TODO: Should this be changed to allow TERM_EXEC_NEWWIN * in a blocked terminal? There is similar code in * exec_on_terminal(). --KON, 2007 */ if (is_blocked() && fg != TERM_EXEC_BG) { if (*delete_.source) unlink(delete_.source); goto nasty_thing; } path_len = path.length; del_len = delete_.length; param_len = path_len + del_len + 3; param = mem_alloc(param_len); if (!param) goto nasty_thing; param[0] = fg; memcpy(param + 1, path.source, path_len + 1); memcpy(param + 1 + path_len + 1, delete_.source, del_len + 1); if (fg == TERM_EXEC_FG) block_itrm(); blockh = start_thread((void (*)(void *, int)) exec_thread, param, param_len); mem_free(param); if (blockh == -1) { if (fg == TERM_EXEC_FG) unblock_itrm(); goto nasty_thing; } if (fg == TERM_EXEC_FG) { set_handlers(blockh, (select_handler_T) unblock_itrm_x, NULL, (select_handler_T) unblock_itrm_x, (void *) (long) blockh); } else { set_handlers(blockh, close_handle, NULL, close_handle, (void *) (long) blockh); } } nasty_thing: done_string(&path); done_string(&delete_); assert(ITRM_OUT_QUEUE_SIZE - p > 0); memmove(buf, buf + p, ITRM_OUT_QUEUE_SIZE - p); bytes_read -= p; goto qwerty; free_and_return: free_itrm(itrm); }
/** Following should match the screen_char.color field. */ unsigned char color[SCREEN_COLOR_SIZE]; }; #if defined(CONFIG_TRUE_COLOR) #define INIT_SCREEN_STATE { 0xFF, 0xFF, 0xFF, 0xFF, 0, { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF} } #elif defined(CONFIG_88_COLORS) || defined(CONFIG_256_COLORS) #define INIT_SCREEN_STATE { 0xFF, 0xFF, 0xFF, 0xFF, 0, { 0xFF, 0xFF } } #else #define INIT_SCREEN_STATE { 0xFF, 0xFF, 0xFF, 0xFF, 0, { 0xFF } } #endif #ifdef CONFIG_TRUE_COLOR static inline int compare_color_true(unsigned char *a, unsigned char *b) { return !memcmp(a, b, 6); } static inline int compare_bg_color_true(unsigned char *a, unsigned char *b) { return (a[3] == b[3] && a[4] == b[4] && a[5] == b[5]); } static inline int compare_fg_color_true(unsigned char *a, unsigned char *b) { return (a[0] == b[0] && a[1] == b[1] && a[2] == b[2]); } static inline void copy_color_true(unsigned char *a, unsigned char *b) { memcpy(a, b, 6); } static inline int background_is_black(unsigned char *a) { static unsigned char b[6] = {0, 0, 0, 0, 0, 0}; return compare_bg_color_true(a, b); } #endif #if defined(CONFIG_88_COLORS) || defined(CONFIG_256_COLORS) static inline int compare_color_256(unsigned char *a, unsigned char *b) { return (a[0] == b[0] && a[1] == b[1]); } static inline int compare_bg_color_256(unsigned char *a, unsigned char *b) { return (a[1] == b[1]); } static inline int compare_fg_color_256(unsigned char *a, unsigned char *b) { return (a[0] == b[0]); } static inline void copy_color_256(unsigned char *a, unsigned char *b) { a[0] = b[0]; a[1] = b[1]; } #endif static inline int compare_color_16(unsigned char *a, unsigned char *b) { return (a[0] == b[0]); } static inline int compare_bg_color_16(unsigned char *a, unsigned char *b) { return (TERM_COLOR_BACKGROUND_16(a) == TERM_COLOR_BACKGROUND_16(b)); } static inline int compare_fg_color_16(unsigned char *a, unsigned char *b) { return (TERM_COLOR_FOREGROUND_16(a) == TERM_COLOR_FOREGROUND_16(b)); } static inline void copy_color_16(unsigned char *a, unsigned char *b) { a[0] = b[0]; } #ifdef CONFIG_UTF8 static inline void add_char_data(struct string *screen, struct screen_driver *driver, unicode_val_T data, unsigned char border) #else /* !CONFIG_UTF8 */ static inline void add_char_data(struct string *screen, struct screen_driver *driver, unsigned char data, unsigned char border) #endif /* !CONFIG_UTF8 */ { /* charset use_utf8_io border data add_to_string * ------- ----------- ------ ---------------- ---------------- * unibyte 0 0 terminal unibyte terminal unibyte * unibyte 0 1 enum border_char border unibyte * unibyte 1 0 terminal unibyte UTF-8 * unibyte 1 1 enum border_char UTF-8 * UTF-8 1 0 UTF-32 (*) UTF-8 * UTF-8 1 1 enum border_char UTF-8 * * (*) For "UTF-32" above, data can also be UCS_NO_CHAR, * in which case this function must not alter *screen. */ if (border && driver->opt.frame && data >= 176 && data < 224) data = driver->opt.frame[data - 176]; #ifdef CONFIG_UTF8 if (driver->opt.utf8_cp) { if (border) { data = cp2u(driver->opt.charsets[1], (unsigned char) data); } if (data == UCS_NO_CHAR) return; #ifdef CONFIG_COMBINE if (data >= UCS_BEGIN_COMBINED && data <= last_combined) { unicode_val_T *text = combined[data - UCS_BEGIN_COMBINED]; if (driver->opt.combine) { /* XTerm */ while (*text != UCS_END_COMBINED) { add_to_string(screen, encode_utf8(*text)); text++; } return; } else { /* Others */ data = *text; } } #endif /* CONFIG_COMBINE */ if (!isscreensafe_ucs(data)) data = UCS_SPACE; add_to_string(screen, encode_utf8(data)); } else #endif /* CONFIG_UTF8 */ if (use_utf8_io(driver)) { int charset = driver->opt.charsets[!!border]; if (border || isscreensafe(data)) add_to_string(screen, cp2utf8(charset, data)); else /* UCS_SPACE <= 0x7F and so fits in one UTF-8 byte */ add_char_to_string(screen, UCS_SPACE); } else { if (border || isscreensafe(data)) add_char_to_string(screen, (unsigned char)data); else add_char_to_string(screen, ' '); } }
static unsigned char * get_progress_msg_2(struct progress *progress, struct terminal *term, int wide, int full, unsigned char *separator, unsigned char *type) { struct string msg; int newlines = separator[strlen(separator) - 1] == '\n'; if (!init_string(&msg)) return NULL; /* FIXME: The following is a PITA from the l10n standpoint. A *big* * one, _("of")-like pearls are a nightmare. Format strings need to * be introduced to this fuggy corner of code as well. --pasky */ add_to_string(&msg, type); add_char_to_string(&msg, ' '); add_xnum_to_string(&msg, progress->pos); if (progress->size >= 0) { add_char_to_string(&msg, ' '); add_to_string(&msg, _("of", term)); add_char_to_string(&msg, ' '); add_xnum_to_string(&msg, progress->size); } add_to_string(&msg, separator); if (wide) { /* Do the following only if there is room */ add_to_string(&msg, _(full ? (newlines ? N_("Average speed") : N_("average speed")) : N_("avg"), term)); add_char_to_string(&msg, ' '); add_xnum_to_string(&msg, progress->average_speed); add_to_string(&msg, "/s"); add_to_string(&msg, ", "); add_to_string(&msg, _(full ? N_("current speed") : N_("cur"), term)); add_char_to_string(&msg, ' '), add_xnum_to_string(&msg, progress->current_speed); add_to_string(&msg, "/s"); add_to_string(&msg, separator); add_to_string(&msg, _(full ? (newlines ? N_("Elapsed time") : N_("elapsed time")) : N_("ETT"), term)); add_char_to_string(&msg, ' '); add_timeval_to_string(&msg, &progress->elapsed); } else { add_to_string(&msg, _(newlines ? N_("Speed") : N_("speed"), term)); add_char_to_string(&msg, ' '); add_xnum_to_string(&msg, progress->average_speed); add_to_string(&msg, "/s"); } if (progress->size >= 0 && progress->loaded > 0) { add_to_string(&msg, ", "); add_to_string(&msg, _(full ? N_("estimated time") : N_("ETA"), term)); add_char_to_string(&msg, ' '); add_timeval_to_string(&msg, &progress->estimated_time); } return msg.source; }
void html_option(struct html_context *html_context, unsigned char *a, unsigned char *xxx3, unsigned char *xxx4, unsigned char **xxx5) { struct form_control *fc; unsigned char *val; if (!format.select) return; val = get_attr_val(a, (unsigned char *)"value", html_context->doc_cp); if (!val) { struct string str; unsigned char *p, *r; unsigned char *name; int namelen; for (p = a - 1; *p != '<'; p--); if (!init_string(&str)) goto end_parse; if (parse_element(p, html_context->eoff, NULL, NULL, NULL, &p)) { INTERNAL("parse element failed"); val = str.source; goto end_parse; } se: while (p < html_context->eoff && isspace(*p)) p++; while (p < html_context->eoff && !isspace(*p) && *p != '<') { sp: add_char_to_string(&str, *p ? *p : ' '), p++; } r = p; val = str.source; /* Has to be before the possible 'goto end_parse' */ while (r < html_context->eoff && isspace(*r)) r++; if (r >= html_context->eoff) goto end_parse; if (r - 2 <= html_context->eoff && (r[1] == '!' || r[1] == '?')) { p = skip_comment(r, html_context->eoff); goto se; } if (parse_element(r, html_context->eoff, &name, &namelen, NULL, &p)) goto sp; if (namelen < 6) goto se; if (name[0] == '/') name++, namelen--; if (c_strlcasecmp(name, namelen, (const unsigned char *)"OPTION", 6) && c_strlcasecmp(name, namelen, (const unsigned char *)"SELECT", 6) && c_strlcasecmp(name, namelen, (const unsigned char *)"OPTGROUP", 8)) goto se; } end_parse: fc = init_form_control(FC_CHECKBOX, a, html_context); if (!fc) { mem_free_if(val); return; } fc->id = get_attr_val(a, (unsigned char *)"id", html_context->doc_cp); fc->name = null_or_stracpy(format.select); fc->default_value = val; fc->default_state = has_attr(a, (unsigned char *)"selected", html_context->doc_cp); fc->mode = has_attr(a, (unsigned char *)"disabled", html_context->doc_cp) ? FORM_MODE_DISABLED : format.select_disabled; put_chrs(html_context, (unsigned char *)" ", 1); html_stack_dup(html_context, ELEMENT_KILLABLE); format.form = fc; format.style.attr |= AT_BOLD; put_chrs(html_context, (unsigned char *)"[ ]", 3); pop_html_element(html_context); put_chrs(html_context, (unsigned char *)" ", 1); html_context->special_f(html_context, SP_CONTROL, fc); }
static unsigned char * get_cache_entry_info(struct listbox_item *item, struct terminal *term) { struct cache_entry *cached = item->udata; struct string msg; if (item->type == BI_FOLDER) return NULL; if (!init_string(&msg)) return NULL; add_to_string(&msg, _("URL", term)); add_to_string(&msg, ": "); add_uri_to_string(&msg, cached->uri, URI_PUBLIC); /* No need to use compare_uri() here we only want to check whether they * point to the same URI. */ if (cached->proxy_uri != cached->uri) { add_format_to_string(&msg, "\n%s: ", _("Proxy URL", term)); add_uri_to_string(&msg, cached->proxy_uri, URI_PUBLIC); } if (cached->redirect) { add_format_to_string(&msg, "\n%s: ", _("Redirect", term)); add_uri_to_string(&msg, cached->redirect, URI_PUBLIC); if (cached->redirect_get) { add_to_string(&msg, " (GET)"); } } add_format_to_string(&msg, "\n%s: %" OFF_T_FORMAT, _("Size", term), cached->length); add_format_to_string(&msg, "\n%s: %" OFF_T_FORMAT, _("Loaded size", term), cached->data_size); if (cached->content_type) { add_format_to_string(&msg, "\n%s: %s", _("Content type", term), cached->content_type); } if (cached->last_modified) { add_format_to_string(&msg, "\n%s: %s", _("Last modified", term), cached->last_modified); } if (cached->etag) { add_format_to_string(&msg, "\n%s: %s", "ETag", cached->etag); } if (cached->ssl_info) { add_format_to_string(&msg, "\n%s: %s", _("SSL Cipher", term), cached->ssl_info); } if (cached->encoding_info) { add_format_to_string(&msg, "\n%s: %s", _("Encoding", term), cached->encoding_info); } if (cached->incomplete || !cached->valid) { add_char_to_string(&msg, '\n'); add_to_string(&msg, _("Flags", term)); add_to_string(&msg, ": "); if (cached->incomplete) { add_to_string(&msg, _("incomplete", term)); add_char_to_string(&msg, ' '); } if (!cached->valid) add_to_string(&msg, _("invalid", term)); } #ifdef HAVE_STRFTIME if (cached->expire) { time_t expires = timeval_to_seconds(&cached->max_age); add_format_to_string(&msg, "\n%s: ", _("Expires", term)); add_date_to_string(&msg, get_opt_str("ui.date_format"), &expires); } #endif #ifdef CONFIG_DEBUG add_format_to_string(&msg, "\n%s: %d", "Refcount", get_object_refcount(cached)); add_format_to_string(&msg, "\n%s: %u", _("ID", term), cached->id); if (cached->head && *cached->head) { add_format_to_string(&msg, "\n%s:\n\n%s", _("Header", term), cached->head); } #endif return msg.source; }
void html_li(struct html_context *html_context, unsigned char *a, unsigned char *xxx3, unsigned char *xxx4, unsigned char **xxx5) { int t = par_format.flags & P_LISTMASK; /* When handling the code <li><li> @was_li will be 1 and it means we * have to insert a line break since no list item content has done it * for us. */ if (html_context->was_li) { html_context->line_breax = 0; ln_break(html_context, 1); } /*kill_html_stack_until(html_context, 0 "", "UL", "OL", NULL);*/ if (t == P_NO_BULLET) { /* Print nothing. */ } else if (!par_format.list_number) { if (t == P_O) /* Print U+25E6 WHITE BULLET. */ put_chrs(html_context, (unsigned char *)"◦", 7); else if (t == P_SQUARE) /* Print U+25AA BLACK SMALL SQUARE. */ put_chrs(html_context, (unsigned char *)"▪", 7); else /* Print U+2022 BULLET. */ put_chrs(html_context, (unsigned char *)"•", 7); put_chrs(html_context, (unsigned char *)" ", 6); par_format.leftmargin += 2; par_format.align = ALIGN_LEFT; } else { unsigned char c = 0; int nlen; int t = par_format.flags & P_LISTMASK; int s = get_num(a, (unsigned char *)"value", html_context->doc_cp); struct string n; if (!init_string(&n)) return; if (s != -1) par_format.list_number = s; if (t == P_ALPHA || t == P_alpha) { unsigned char n0; put_chrs(html_context, (unsigned char *)" ", 6); c = 1; n0 = par_format.list_number ? (par_format.list_number - 1) % 26 + (t == P_ALPHA ? 'A' : 'a') : 0; if (n0) add_char_to_string(&n, n0); } else if (t == P_ROMAN || t == P_roman) { roman(&n, par_format.list_number); if (t == P_ROMAN) { unsigned char *x; for (x = n.source; *x; x++) *x = c_toupper(*x); } } else { unsigned char n0[64]; if (par_format.list_number < 10) { put_chrs(html_context, (unsigned char *)" ", 6); c = 1; } ulongcat(n0, NULL, par_format.list_number, (sizeof(n) - 1), 0); add_to_string(&n, n0); } nlen = n.length; put_chrs(html_context, n.source, nlen); put_chrs(html_context, (unsigned char *)". ", 7); par_format.leftmargin += nlen + c + 2; par_format.align = ALIGN_LEFT; done_string(&n); { struct html_element *element; element = search_html_stack(html_context, (unsigned char *)"ol"); if (element) element->parattr.list_number = par_format.list_number + 1; } par_format.list_number = 0; } html_context->putsp = HTML_SPACE_SUPPRESS; html_context->line_breax = 2; html_context->was_li = 1; }