/* Checks protocols headers for a suitable filename */ static unsigned char * get_content_filename(struct uri *uri, struct cache_entry *cached) { unsigned char *filename, *pos; if (!cached) cached = find_in_cache(uri); if (!cached || !cached->head) return NULL; pos = parse_header(cached->head, "Content-Disposition", NULL); if (!pos) return NULL; parse_header_param(pos, "filename", &filename, 1); mem_free(pos); if (!filename) return NULL; /* Remove start and ending quotes. */ if (filename[0] == '"') { int len = strlen(filename); if (len > 1 && filename[len - 1] == '"') { filename[len - 1] = 0; memmove(filename, filename + 1, len); } /* It was an empty quotation: "" */ if (!filename[1]) { mem_free(filename); return NULL; } } /* We don't want to add any directories from the path so make sure we * only add the filename. */ pos = get_filename_position(filename); if (!*pos) { mem_free(filename); return NULL; } if (pos > filename) memmove(filename, pos, strlen(pos) + 1); return filename; }
/* sezere 1 cookie z retezce str, na zacatku nesmi byt zadne whitechars * na konci muze byt strednik nebo 0 * cookie musi byt ve tvaru nazev=hodnota, kolem rovnase nesmi byt zadne mezery * (respektive mezery se budou pocitat do nazvu a do hodnoty) */ int set_cookie(struct terminal *term, unsigned char *url, unsigned char *str) { int noval = 0; struct cookie *cookie; struct c_server *cs; unsigned char *p, *q, *s, *server, *date; d_opt = &dd_opt; int accept_cookies = dds.allow_cookies; if (accept_cookies == ACCEPT_NONE) { return 0; } for (p = str; *p != ';' && *p; p++) { /*if (WHITECHAR(*p)) return 0;*/ } for (q = str; *q != '='; q++) if (!*q || q >= p) { noval = 1; break; } if (str == q || q + 1 == p) return 0; cookie = mem_alloc(sizeof(struct cookie)); server = get_host_name(url); cookie->name = memacpy(str, q - str); cookie->value = !noval ? memacpy(q + 1, p - q - 1) : NULL; cookie->server = stracpy(server); date = parse_header_param(str, cast_uchar "expires", 0); if (date) { cookie->expires = parse_http_date(date); /* kdo tohle napsal a proc ?? */ /*if (! cookie->expires) cookie->expires++;*/ /* no harm and we can use zero then */ mem_free(date); } else cookie->expires = 0; if (!(cookie->path = parse_header_param(str, cast_uchar "path", 0))) { /*unsigned char *w;*/ cookie->path = stracpy(cast_uchar "/"); /* add_to_strn(&cookie->path, document); for (w = cookie->path; *w; w++) if (end_of_dir(cookie->path, *w)) { *w = 0; break; } for (w = cookie->path + strlen(cast_const_char cookie->path) - 1; w >= cookie->path; w--) if (*w == '/') { w[1] = 0; break; } */ } else { if (cookie->path[0] != '/') { add_to_strn(&cookie->path, cast_uchar "x"); memmove(cookie->path + 1, cookie->path, strlen(cast_const_char cookie->path) - 1); cookie->path[0] = '/'; } } if (!(cookie->domain = parse_header_param(str, cast_uchar "domain", 0))) cookie->domain = stracpy(server); if (cookie->domain[0] == '.') memmove(cookie->domain, cookie->domain + 1, strlen(cast_const_char cookie->domain)); if ((s = parse_header_param(str, cast_uchar "secure", 0))) { cookie->secure = 1; mem_free(s); } else cookie->secure = 0; if (check_domain_security(server, cookie->domain)) { mem_free(cookie->domain); cookie->domain = stracpy(server); } foreach (cs, c_servers) if (!strcasecmp(cast_const_char cs->server, cast_const_char server)) { if (cs->accpt) goto ok; else { free_cookie(cookie); mem_free(cookie); mem_free(server); return 0; } } if (accept_cookies != ACCEPT_ALL) { free_cookie(cookie); mem_free(cookie); mem_free(server); return 1; } ok: accept_cookie(cookie); mem_free(server); return 0; }
void parse_args(int argc, char *argv[]) { long l; int i; const char *progname = argv[0]; struct headers *header; initialize_params(); while ((i = getopt(argc, argv, opts)) > 0) { switch (i) { case 'H': header = parse_header_param(optarg); if (header == NULL) { fprintf(stderr, "error parsing -H parameter\n"); print_help(stderr, progname); exit(-1); } else { overwrite_header(&config_opts.headers, header); } break; case 'C': { /* split on : if present * first part is config_opts.connect * second part is config_opts.connect_port */ char *portstr; config_opts.connect = strdup(optarg); portstr = strchr(config_opts.connect, ':'); if (portstr) *portstr++ = '\0'; /* terminate the host part */ if (portstr && *portstr) { errno = 0; l = strtol(portstr, (char **)NULL, 10); if (errno) { perror("invalid connect port (-C) value"); print_help(stderr, progname); exit(-1); } else if (l < 0 || l >= USHRT_MAX) { fprintf(stderr, "invalid connect port (-C): %ld\n", l); print_help(stderr, progname); exit(-1); } config_opts.connect_port = (unsigned short)l; } } break; case 'c': errno = 0; l = strtol(optarg, (char **)NULL, 10); if (errno) { perror("invalid concurrency (-c) value"); print_help(stderr, progname); exit(-1); } else if (l <= 0 || l == LONG_MAX) { fprintf(stderr, "invalid concurrency (-c): %ld\n", l); print_help(stderr, progname); exit(-1); } config_opts.concurrency = (int)l; break; case 'n': errno = 0; l = strtol(optarg, (char **)NULL, 10); if (errno) { perror("invalid request count (-n) value"); print_help(stderr, progname); exit(-1); } else if (l <= 0 || l == LONG_MAX) { fprintf(stderr, "invalid request count (-n): %ld\n", l); print_help(stderr, progname); exit(-1); } config_opts.count = (int)l; break; case 'o': config_opts.halfopen = 1; break; case 'v': config_opts.verbose++; break; default: fprintf(stderr, "Unknown option: %o\n", i); case 'h': print_help(stderr, progname); exit(-1); break; } } argc -= optind; argv += optind; if (argc == 0) { fprintf(stderr, "At least one URL required..."); print_help(stderr, progname); exit(-1); } else for (i = 0; i < argc; i++) { struct urls *url = malloc(sizeof(*url)); RING_INIT(url); url->url = strdup(argv[i]); RING_APPEND(config_opts.urls, url); } }