X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/disorder/blobdiff_plain/460b9539a7c15580e41a71bbc0f47ae776238915..74b1f70dbce97198dc741ddd61214e55138f826f:/server/cgi.c diff --git a/server/cgi.c b/server/cgi.c index 02bad31..2017d1b 100644 --- a/server/cgi.c +++ b/server/cgi.c @@ -1,6 +1,6 @@ /* * This file is part of DisOrder. - * Copyright (C) 2004, 2005, 2006 Richard Kettlewell + * Copyright (C) 2004-2008 Richard Kettlewell * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -52,7 +52,7 @@ #include "cgi.h" #include "printf.h" #include "mime.h" -#include "utf8.h" +#include "unicode.h" struct kvp *cgi_args; @@ -152,13 +152,14 @@ static void cgi_parse_multipart(const char *boundary) { } static void cgi_parse_post(void) { - const char *ct; - char *q, *type, *pname, *pvalue; + const char *ct, *boundary; + char *q, *type; size_t n; + struct kvp *k; if(!(ct = getenv("CONTENT_TYPE"))) ct = "application/x-www-form-urlencoded"; - if(mime_content_type(ct, &type, &pname, &pvalue)) + if(mime_content_type(ct, &type, &k)) fatal(0, "invalid content type '%s'", ct); if(!strcmp(type, "application/x-www-form-urlencoded")) { cgi_input(&q, &n); @@ -166,10 +167,9 @@ static void cgi_parse_post(void) { return; } if(!strcmp(type, "multipart/form-data")) { - if(!pname || strcmp(pname, "boundary")) - fatal(0, "expected a boundary parameter, found %s", - pname ? pname : "nothing"); - cgi_parse_multipart(pvalue); + if(!(boundary = kvp_get(k, "boundary"))) + fatal(0, "no boundary parameter found"); + cgi_parse_multipart(boundary); return; } fatal(0, "unrecognized content type '%s'", type); @@ -187,8 +187,8 @@ void cgi_parse(void) { else fatal(0, "unknown request method %s", p); for(k = cgi_args; k; k = k->next) - if(!validutf8(k->name) - || !validutf8(k->value)) + if(!utf8_valid(k->name, strlen(k->name)) + || !utf8_valid(k->value, strlen(k->value))) fatal(0, "invalid UTF-8 sequence in cgi argument"); } @@ -225,7 +225,7 @@ char *cgi_sgmlquote(const char *s, int raw) { int n; if(!raw) { - if(!(ucs = utf82ucs4(s))) exit(EXIT_FAILURE); + if(!(ucs = utf8_to_utf32(s, strlen(s), 0))) exit(EXIT_FAILURE); } else { ucs = xmalloc_noptr((strlen(s) + 1) * sizeof(uint32_t)); for(n = 0; s[n]; ++n) @@ -585,14 +585,29 @@ const char *cgi_label(const char *key) { read_options(); if(!(label = kvp_get(labels, key))) { - if((label = strchr(key, '.'))) + /* No label found */ + if(!strncmp(key, "images.", 7)) { + static const char *url_static; + /* images.X defaults to X.png */ + + if(!url_static) + url_static = cgi_label("url.static"); + byte_xasprintf((char **)&label, "%s%s.png", url_static, key + 7); + } else if((label = strchr(key, '.'))) + /* X.Y defaults to Y */ ++label; else + /* otherwise default to label name */ label = key; } return label; } +int cgi_label_exists(const char *key) { + read_options(); + return kvp_get(labels, key) ? 1 : 0; +} + char **cgi_columns(const char *name, int *ncolumns) { struct column *c; @@ -616,4 +631,3 @@ c-basic-offset:2 comment-column:40 End: */ -/* arch-tag:a7a5220f29b8bb8d64c0f836f7f41f1f */