comparison src/c/urweb.c @ 474:70ee90105fce

[getCookie] reads cookie settings from current page generation
author Adam Chlipala <adamc@hcoop.net>
date Sat, 08 Nov 2008 10:46:14 -0500
parents 7cb418e9714f
children c9566d49ecfe
comparison
equal deleted inserted replaced
473:04b91c33ef54 474:70ee90105fce
339 int len = strlen(s); 339 int len = strlen(s);
340 340
341 uw_check_headers(ctx, len + 1); 341 uw_check_headers(ctx, len + 1);
342 strcpy(ctx->outHeaders_front, s); 342 strcpy(ctx->outHeaders_front, s);
343 ctx->outHeaders_front += len; 343 ctx->outHeaders_front += len;
344 *ctx->outHeaders_front = 0;
344 } 345 }
345 346
346 static void uw_check(uw_context ctx, size_t extra) { 347 static void uw_check(uw_context ctx, size_t extra) {
347 size_t desired = ctx->page_front - ctx->page + extra, next; 348 size_t desired = ctx->page_front - ctx->page + extra, next;
348 char *new_page; 349 char *new_page;
1170 } 1171 }
1171 } 1172 }
1172 1173
1173 uw_Basis_string uw_Basis_get_cookie(uw_context ctx, uw_Basis_string c) { 1174 uw_Basis_string uw_Basis_get_cookie(uw_context ctx, uw_Basis_string c) {
1174 int len = strlen(c); 1175 int len = strlen(c);
1175 char *s = ctx->headers, *p; 1176 char *s = ctx->headers, *p = ctx->outHeaders;
1177
1178 while (p = strstr(p, "\nSet-Cookie: ")) {
1179 char *p2;
1180 p += 13;
1181 p2 = strchr(p, '=');
1182
1183 if (p2) {
1184 size_t sz = strcspn(p2+1, ";\r\n");
1185
1186 if (!strncasecmp(p, c, p2 - p)) {
1187 char *ret = uw_malloc(ctx, sz + 1);
1188 memcpy(ret, p2+1, sz);
1189 ret[sz] = 0;
1190 return ret;
1191 }
1192 }
1193 }
1176 1194
1177 while (p = strchr(s, ':')) { 1195 while (p = strchr(s, ':')) {
1178 if (!strncasecmp(s, "Cookie: ", 8) && !strncmp(p + 2, c, len) 1196 if (!strncasecmp(s, "Cookie: ", 8) && !strncmp(p + 2, c, len)
1179 && p + 2 + len < ctx->headers_end && p[2 + len] == '=') { 1197 && p + 2 + len < ctx->headers_end && p[2 + len] == '=') {
1180 return p + 3 + len; 1198 return p + 3 + len;