comparison src/c/urweb.c @ 742:43553c93dd8c

Reading blobs from the database
author Adam Chlipala <adamc@hcoop.net>
date Sun, 26 Apr 2009 10:45:59 -0400
parents f7e2026dd5ae
children ee2feab275db
comparison
equal deleted inserted replaced
741:f7e2026dd5ae 742:43553c93dd8c
439 *s = 0; 439 *s = 0;
440 s += 2; 440 s += 2;
441 } 441 }
442 442
443 ctx->headers_end = s; 443 ctx->headers_end = s;
444 }
445
446 void uw_headers_moved(uw_context ctx, char *headers) {
447 ctx->headers_end = headers + (ctx->headers_end - ctx->headers);
448 ctx->headers = headers;
444 } 449 }
445 450
446 int uw_db_begin(uw_context); 451 int uw_db_begin(uw_context);
447 452
448 __attribute__((noreturn)) void uw_error(uw_context ctx, failure_kind fk, const char *fmt, ...) { 453 __attribute__((noreturn)) void uw_error(uw_context ctx, failure_kind fk, const char *fmt, ...) {
1479 return uw_strdup(ctx, s1); 1484 return uw_strdup(ctx, s1);
1480 else 1485 else
1481 return NULL; 1486 return NULL;
1482 } 1487 }
1483 1488
1489 char *uw_memdup(uw_context ctx, const char *p, size_t len) {
1490 char *r = uw_malloc(ctx, len);
1491 memcpy(r, p, len);
1492 return r;
1493 }
1484 1494
1485 char *uw_Basis_sqlifyInt(uw_context ctx, uw_Basis_int n) { 1495 char *uw_Basis_sqlifyInt(uw_context ctx, uw_Basis_int n) {
1486 int len; 1496 int len;
1487 char *r; 1497 char *r;
1488 1498
1892 else if (strptime(s, TIME_FMT, &stm) == end) 1902 else if (strptime(s, TIME_FMT, &stm) == end)
1893 return mktime(&stm); 1903 return mktime(&stm);
1894 else 1904 else
1895 uw_error(ctx, FATAL, "Can't parse time: %s", s); 1905 uw_error(ctx, FATAL, "Can't parse time: %s", s);
1896 } 1906 }
1907 }
1908
1909 uw_Basis_blob uw_Basis_stringToBlob_error(uw_context ctx, uw_Basis_string s, size_t len) {
1910 char *r = ctx->heap.front;
1911 uw_Basis_blob b = {len, r};
1912
1913 uw_check_heap(ctx, len);
1914
1915 while (*s) {
1916 if (s[0] == '\\') {
1917 if (s[1] == '\\') {
1918 *r++ = '\\';
1919 s += 2;
1920 } else if (isdigit(s[1]) && isdigit(s[2]) && isdigit(s[3])) {
1921 *r++ = (s[1] - '0') * 8 * 8 + ((s[2] - '0') * 8) + (s[3] - '0');
1922 s += 4;
1923 }
1924 else {
1925 *r++ = '\\';
1926 ++s;
1927 }
1928 } else {
1929 *r++ = s[0];
1930 ++s;
1931 }
1932 }
1933
1934 b.size = r - ctx->heap.front;
1935 ctx->heap.front = r;
1936 return b;
1897 } 1937 }
1898 1938
1899 uw_Basis_string uw_Basis_get_cookie(uw_context ctx, uw_Basis_string c) { 1939 uw_Basis_string uw_Basis_get_cookie(uw_context ctx, uw_Basis_string c) {
1900 int len = strlen(c); 1940 int len = strlen(c);
1901 char *s = ctx->headers, *p = ctx->outHeaders.start; 1941 char *s = ctx->headers, *p = ctx->outHeaders.start;