comparison src/c/urweb.c @ 1981:e90f218f2d48

Trim trailing whitespace in urweb.c.
author Patrick Hurst <phurst@mit.edu>
date Sat, 25 Jan 2014 18:13:33 -0500
parents 81bc76aa4acd
children 2b95ecdd94eb
comparison
equal deleted inserted replaced
1979:81bc76aa4acd 1981:e90f218f2d48
845 adjust_pointer(&x->data.entry.next, old_start, new_start, len); 845 adjust_pointer(&x->data.entry.next, old_start, new_start, len);
846 adjust_pointer(&x->data.entry.parent, old_start, new_start, len); 846 adjust_pointer(&x->data.entry.parent, old_start, new_start, len);
847 break; 847 break;
848 default: 848 default:
849 break; 849 break;
850 } 850 }
851 } 851 }
852 852
853 size_t uw_subinputs_max = SIZE_MAX; 853 size_t uw_subinputs_max = SIZE_MAX;
854 854
855 static input *check_input_space(uw_context ctx, size_t len) { 855 static input *check_input_space(uw_context ctx, size_t len) {
1861 } 1861 }
1862 1862
1863 uw_unit uw_Basis_urlifyChannel_w(uw_context ctx, uw_Basis_channel chn) { 1863 uw_unit uw_Basis_urlifyChannel_w(uw_context ctx, uw_Basis_channel chn) {
1864 if (ctx->client != NULL && chn.cli == ctx->client->id) { 1864 if (ctx->client != NULL && chn.cli == ctx->client->id) {
1865 int len; 1865 int len;
1866 1866
1867 uw_check(ctx, INTS_MAX + 1); 1867 uw_check(ctx, INTS_MAX + 1);
1868 sprintf(ctx->page.front, "%u%n", chn.chn, &len); 1868 sprintf(ctx->page.front, "%u%n", chn.chn, &len);
1869 ctx->page.front += len; 1869 ctx->page.front += len;
1870 } 1870 }
1871 1871
1872 return uw_unit_v; 1872 return uw_unit_v;
1873 } 1873 }
1874 1874
1875 uw_unit uw_Basis_urlifyFloat_w(uw_context ctx, uw_Basis_float n) { 1875 uw_unit uw_Basis_urlifyFloat_w(uw_context ctx, uw_Basis_float n) {
1876 int len; 1876 int len;
1927 return uw_unit_v; 1927 return uw_unit_v;
1928 } 1928 }
1929 1929
1930 uw_unit uw_Basis_urlifySource_w(uw_context ctx, uw_Basis_source src) { 1930 uw_unit uw_Basis_urlifySource_w(uw_context ctx, uw_Basis_source src) {
1931 int len; 1931 int len;
1932 1932
1933 uw_check(ctx, 2 * INTS_MAX + 2); 1933 uw_check(ctx, 2 * INTS_MAX + 2);
1934 sprintf(ctx->page.front, "%d/%llu%n", src.context, src.source, &len); 1934 sprintf(ctx->page.front, "%d/%llu%n", src.context, src.source, &len);
1935 ctx->page.front += len; 1935 ctx->page.front += len;
1936 1936
1937 return uw_unit_v; 1937 return uw_unit_v;
1938 } 1938 }
1939 1939
1940 1940
1941 static char *uw_unurlify_advance(char *s) { 1941 static char *uw_unurlify_advance(char *s) {
2022 } 2022 }
2023 2023
2024 uw_Basis_bool uw_Basis_unurlifyBool(uw_context ctx, char **s) { 2024 uw_Basis_bool uw_Basis_unurlifyBool(uw_context ctx, char **s) {
2025 char *new_s = uw_unurlify_advance(*s); 2025 char *new_s = uw_unurlify_advance(*s);
2026 uw_Basis_bool r; 2026 uw_Basis_bool r;
2027 2027
2028 if (*s[0] == 0 || !strcmp(*s, "0") || !strcmp(*s, "off")) 2028 if (*s[0] == 0 || !strcmp(*s, "0") || !strcmp(*s, "off"))
2029 r = uw_Basis_False; 2029 r = uw_Basis_False;
2030 else 2030 else
2031 r = uw_Basis_True; 2031 r = uw_Basis_True;
2032 2032
2083 int len; 2083 int len;
2084 2084
2085 uw_check(ctx, INTS_MAX); 2085 uw_check(ctx, INTS_MAX);
2086 sprintf(ctx->page.front, "%lld%n", n, &len); 2086 sprintf(ctx->page.front, "%lld%n", n, &len);
2087 ctx->page.front += len; 2087 ctx->page.front += len;
2088 2088
2089 return uw_unit_v; 2089 return uw_unit_v;
2090 } 2090 }
2091 2091
2092 char *uw_Basis_htmlifySpecialChar(uw_context ctx, unsigned char ch) { 2092 char *uw_Basis_htmlifySpecialChar(uw_context ctx, unsigned char ch) {
2093 unsigned int n = ch; 2093 unsigned int n = ch;
2147 int len; 2147 int len;
2148 2148
2149 uw_check(ctx, INTS_MAX); 2149 uw_check(ctx, INTS_MAX);
2150 sprintf(ctx->page.front, "%lld%n", (uw_Basis_int)n, &len); 2150 sprintf(ctx->page.front, "%lld%n", (uw_Basis_int)n, &len);
2151 ctx->page.front += len; 2151 ctx->page.front += len;
2152 2152
2153 return uw_unit_v; 2153 return uw_unit_v;
2154 } 2154 }
2155 2155
2156 char *uw_Basis_htmlifyString(uw_context ctx, const char *s) { 2156 char *uw_Basis_htmlifyString(uw_context ctx, const char *s) {
2157 char *r, *s2; 2157 char *r, *s2;
2251 int len; 2251 int len;
2252 2252
2253 uw_check(ctx, 2 * INTS_MAX + 1); 2253 uw_check(ctx, 2 * INTS_MAX + 1);
2254 sprintf(ctx->page.front, "s%d_%llu%n", src.context, src.source, &len); 2254 sprintf(ctx->page.front, "s%d_%llu%n", src.context, src.source, &len);
2255 ctx->page.front += len; 2255 ctx->page.front += len;
2256 2256
2257 return uw_unit_v; 2257 return uw_unit_v;
2258 } 2258 }
2259 2259
2260 uw_Basis_char uw_Basis_strsub(uw_context ctx, uw_Basis_string s, uw_Basis_int n) { 2260 uw_Basis_char uw_Basis_strsub(uw_context ctx, uw_Basis_string s, uw_Basis_int n) {
2261 while (n >= 0) { 2261 while (n >= 0) {
2361 uw_Basis_string r = uw_malloc(ctx, len+1); 2361 uw_Basis_string r = uw_malloc(ctx, len+1);
2362 memcpy(r, s+start, len); 2362 memcpy(r, s+start, len);
2363 r[len] = 0; 2363 r[len] = 0;
2364 return r; 2364 return r;
2365 } 2365 }
2366 2366
2367 } 2367 }
2368 2368
2369 uw_Basis_string uw_Basis_str1(uw_context ctx, uw_Basis_char ch) { 2369 uw_Basis_string uw_Basis_str1(uw_context ctx, uw_Basis_char ch) {
2370 char *r; 2370 char *r;
2371 2371
2585 } 2585 }
2586 } else { 2586 } else {
2587 sprintf(s2, "%02X", c); 2587 sprintf(s2, "%02X", c);
2588 s2 += 2; 2588 s2 += 2;
2589 } 2589 }
2590 } 2590 }
2591 2591
2592 *s2++ = '\''; 2592 *s2++ = '\'';
2593 strcpy(s2, uw_sqlsuffixBlob); 2593 strcpy(s2, uw_sqlsuffixBlob);
2594 ctx->heap.front = s2 + 1 + strlen(uw_sqlsuffixBlob); 2594 ctx->heap.front = s2 + 1 + strlen(uw_sqlsuffixBlob);
2595 return r; 2595 return r;
3252 int i; 3252 int i;
3253 char *s = strstr(haystack, sig_intro); 3253 char *s = strstr(haystack, sig_intro);
3254 3254
3255 if (!s || strlen(haystack) - (s - haystack) - (sizeof sig_intro - 1) < uw_hash_blocksize*2+1) 3255 if (!s || strlen(haystack) - (s - haystack) - (sizeof sig_intro - 1) < uw_hash_blocksize*2+1)
3256 return NULL; 3256 return NULL;
3257 3257
3258 s += sizeof sig_intro - 1; 3258 s += sizeof sig_intro - 1;
3259 3259
3260 for (i = 0; i < uw_hash_blocksize*2; ++i) 3260 for (i = 0; i < uw_hash_blocksize*2; ++i)
3261 if (!isxdigit((int)s[i])) 3261 if (!isxdigit((int)s[i]))
3262 return NULL; 3262 return NULL;
3665 } 3665 }
3666 3666
3667 uw_Basis_string uw_Basis_makeSigString(uw_context ctx, uw_Basis_string sig) { 3667 uw_Basis_string uw_Basis_makeSigString(uw_context ctx, uw_Basis_string sig) {
3668 uw_Basis_string r = uw_malloc(ctx, 2 * uw_hash_blocksize + 1); 3668 uw_Basis_string r = uw_malloc(ctx, 2 * uw_hash_blocksize + 1);
3669 int i; 3669 int i;
3670 3670
3671 for (i = 0; i < uw_hash_blocksize; ++i) 3671 for (i = 0; i < uw_hash_blocksize; ++i)
3672 sprintf(&r[2*i], "%.02X", ((unsigned char *)sig)[i]); 3672 sprintf(&r[2*i], "%.02X", ((unsigned char *)sig)[i]);
3673 3673
3674 return r; 3674 return r;
3675 } 3675 }
3883 3883
3884 uw_Basis_string uw_Basis_mstrcat(uw_context ctx, ...) { 3884 uw_Basis_string uw_Basis_mstrcat(uw_context ctx, ...) {
3885 va_list ap; 3885 va_list ap;
3886 size_t len = 1; 3886 size_t len = 1;
3887 char *s, *r, *s2; 3887 char *s, *r, *s2;
3888 3888
3889 va_start(ap, ctx); 3889 va_start(ap, ctx);
3890 for (s = va_arg(ap, char*); s; s = va_arg(ap, char*)) 3890 for (s = va_arg(ap, char*); s; s = va_arg(ap, char*))
3891 len += strlen(s); 3891 len += strlen(s);
3892 va_end(ap); 3892 va_end(ap);
3893 3893
4115 uw_Basis_int uw_Basis_rand(uw_context ctx) { 4115 uw_Basis_int uw_Basis_rand(uw_context ctx) {
4116 uw_Basis_int ret; 4116 uw_Basis_int ret;
4117 pthread_mutex_lock(&rand_mutex); 4117 pthread_mutex_lock(&rand_mutex);
4118 int r = RAND_bytes((unsigned char *)&ret, sizeof ret); 4118 int r = RAND_bytes((unsigned char *)&ret, sizeof ret);
4119 pthread_mutex_unlock(&rand_mutex); 4119 pthread_mutex_unlock(&rand_mutex);
4120 4120
4121 if (r) 4121 if (r)
4122 return abs(ret); 4122 return abs(ret);
4123 else 4123 else
4124 uw_error(ctx, FATAL, "Random number generation failed"); 4124 uw_error(ctx, FATAL, "Random number generation failed");
4125 } 4125 }