summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
6207d2f)
parameters rather than just one that has to be the right one. This
gets the web interface working on Opera (for Mac).
#include "hex.h"
#include "log.h"
#include "base64.h"
#include "hex.h"
#include "log.h"
#include "base64.h"
/** @brief Match whitespace characters */
static int whitespace(int c) {
/** @brief Match whitespace characters */
static int whitespace(int c) {
/** @brief Parse a MIME content-type field
* @param s Start of field
* @param typep Where to store type
/** @brief Parse a MIME content-type field
* @param s Start of field
* @param typep Where to store type
- * @param parameternamep Where to store parameter name
- * @param parametervaluep Wher to store parameter value
+ * @param parametersp Where to store parameter list
* @return 0 on success, non-0 on error
*
* See <a href="http://tools.ietf.org/html/rfc2045#section-5">RFC 2045 s5</a>.
*/
int mime_content_type(const char *s,
char **typep,
* @return 0 on success, non-0 on error
*
* See <a href="http://tools.ietf.org/html/rfc2045#section-5">RFC 2045 s5</a>.
*/
int mime_content_type(const char *s,
char **typep,
- char **parameternamep,
- char **parametervaluep) {
+ struct kvp **parametersp) {
struct dynstr type, parametername;
struct dynstr type, parametername;
+ struct kvp *parameters = 0;
+ char *parametervalue;
dynstr_init(&type);
if(!(s = skipwhite(s, 1))) return -1;
dynstr_init(&type);
if(!(s = skipwhite(s, 1))) return -1;
dynstr_append(&type, tolower((unsigned char)*s++));
if(!(s = skipwhite(s, 1))) return -1;
dynstr_append(&type, tolower((unsigned char)*s++));
if(!(s = skipwhite(s, 1))) return -1;
dynstr_init(¶metername);
++s;
if(!(s = skipwhite(s, 1))) return -1;
dynstr_init(¶metername);
++s;
if(!(s = skipwhite(s, 1))) return -1;
if(!(s = skipwhite(s, 1))) return -1;
if(*s++ != '=') return -1;
if(!(s = skipwhite(s, 1))) return -1;
if(!(s = skipwhite(s, 1))) return -1;
if(*s++ != '=') return -1;
if(!(s = skipwhite(s, 1))) return -1;
- if(!(s = parseword(s, parametervaluep, tspecial))) return -1;
+ if(!(s = parseword(s, ¶metervalue, tspecial))) return -1;
if(!(s = skipwhite(s, 1))) return -1;
dynstr_terminate(¶metername);
if(!(s = skipwhite(s, 1))) return -1;
dynstr_terminate(¶metername);
- *parameternamep = parametername.vec;
- } else
- *parametervaluep = *parameternamep = 0;
+ kvp_set(¶meters, parametername.vec, parametervalue);
+ }
dynstr_terminate(&type);
*typep = type.vec;
dynstr_terminate(&type);
*typep = type.vec;
+ *parametersp = parameters;
#ifndef MIME_H
#define MIME_H
#ifndef MIME_H
#define MIME_H
int mime_content_type(const char *s,
char **typep,
int mime_content_type(const char *s,
char **typep,
- char **parameternamep,
- char **parametervaluep);
-/* Parse a content-type value. returns 0 on success, -1 on error.
- * paramaternamep and parametervaluep are only set if present.
- * type and parametername are forced to lower case.
- */
+ struct kvp **parametersp);
const char *mime_parse(const char *s,
int (*callback)(const char *name, const char *value,
const char *mime_parse(const char *s,
int (*callback)(const char *name, const char *value,
static void test_mime(void) {
char *t, *n, *v;
struct vector parts[1];
static void test_mime(void) {
char *t, *n, *v;
struct vector parts[1];
fprintf(stderr, "test_mime\n");
fprintf(stderr, "test_mime\n");
- t = n = v = 0;
- insist(!mime_content_type("text/plain", &t, &n, &v));
+ t = 0;
+ k = 0;
+ insist(!mime_content_type("text/plain", &t, &k));
check_string(t, "text/plain");
check_string(t, "text/plain");
- insist(n == 0);
- insist(v == 0);
- insist(mime_content_type("TEXT ((broken) comment", &t, &n, &v) < 0);
- insist(mime_content_type("TEXT ((broken) comment\\", &t, &n, &v) < 0);
+ insist(mime_content_type("TEXT ((broken) comment", &t, &k) < 0);
+ insist(mime_content_type("TEXT ((broken) comment\\", &t, &k) < 0);
- t = n = v = 0;
- insist(!mime_content_type("TEXT ((nested)\\ comment) /plain", &t, &n, &v));
+ t = 0;
+ k = 0;
+ insist(!mime_content_type("TEXT ((nested)\\ comment) /plain", &t, &k));
check_string(t, "text/plain");
check_string(t, "text/plain");
- insist(n == 0);
- insist(v == 0);
- t = n = v = 0;
- insist(!mime_content_type(" text/plain ; Charset=\"utf-\\8\"", &t, &n, &v));
+ t = 0;
+ k = 0;
+ insist(!mime_content_type(" text/plain ; Charset=\"utf-\\8\"", &t, &k));
check_string(t, "text/plain");
check_string(t, "text/plain");
- check_string(n, "charset");
- check_string(v, "utf-8");
+ insist(k != 0);
+ insist(k->next == 0);
+ check_string(k->name, "charset");
+ check_string(k->value, "utf-8");
- t = n = v = 0;
- insist(!mime_content_type("text/plain;charset = ISO-8859-1 ", &t, &n, &v));
+ t = 0;
+ k = 0;
+ insist(!mime_content_type("text/plain;charset = ISO-8859-1 ", &t, &k));
+ insist(k != 0);
+ insist(k->next == 0);
check_string(t, "text/plain");
check_string(t, "text/plain");
- check_string(n, "charset");
- check_string(v, "ISO-8859-1");
+ check_string(k->name, "charset");
+ check_string(k->value, "ISO-8859-1");
t = n = v = 0;
insist(!mime_rfc2388_content_disposition("form-data; name=\"field1\"", &t, &n, &v));
t = n = v = 0;
insist(!mime_rfc2388_content_disposition("form-data; name=\"field1\"", &t, &n, &v));
}
static void cgi_parse_post(void) {
}
static void cgi_parse_post(void) {
- const char *ct;
- char *q, *type, *pname, *pvalue;
+ const char *ct, *boundary;
+ char *q, *type;
if(!(ct = getenv("CONTENT_TYPE")))
ct = "application/x-www-form-urlencoded";
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);
fatal(0, "invalid content type '%s'", ct);
if(!strcmp(type, "application/x-www-form-urlencoded")) {
cgi_input(&q, &n);
return;
}
if(!strcmp(type, "multipart/form-data")) {
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);
return;
}
fatal(0, "unrecognized content type '%s'", type);