comparison src/c/urweb.c @ 736:796e42c93c48

Cookie signatures for RPCs
author Adam Chlipala <adamc@hcoop.net>
date Thu, 23 Apr 2009 16:13:02 -0400
parents f2a2be93331c
children d049d31a1966
comparison
equal deleted inserted replaced
735:5ccb67665d05 736:796e42c93c48
298 298
299 cleanup *cleanup, *cleanup_front, *cleanup_back; 299 cleanup *cleanup, *cleanup_front, *cleanup_back;
300 300
301 const char *script_header, *url_prefix; 301 const char *script_header, *url_prefix;
302 302
303 int needs_push; 303 int needs_push, needs_sig;
304 304
305 size_t n_deltas, used_deltas; 305 size_t n_deltas, used_deltas;
306 delta *deltas; 306 delta *deltas;
307 307
308 int timeout; 308 int timeout;
334 ctx->cleanup_front = ctx->cleanup_back = ctx->cleanup = malloc(0); 334 ctx->cleanup_front = ctx->cleanup_back = ctx->cleanup = malloc(0);
335 335
336 ctx->script_header = ""; 336 ctx->script_header = "";
337 ctx->url_prefix = "/"; 337 ctx->url_prefix = "/";
338 ctx->needs_push = 0; 338 ctx->needs_push = 0;
339 ctx->needs_sig = 0;
339 340
340 ctx->error_message[0] = 0; 341 ctx->error_message[0] = 0;
341 342
342 ctx->source_count = 0; 343 ctx->source_count = 0;
343 344
587 588
588 void uw_set_needs_push(uw_context ctx, int n) { 589 void uw_set_needs_push(uw_context ctx, int n) {
589 ctx->needs_push = n; 590 ctx->needs_push = n;
590 } 591 }
591 592
593 void uw_set_needs_sig(uw_context ctx, int n) {
594 ctx->needs_sig = n;
595 }
596
592 597
593 static void buf_check_ctx(uw_context ctx, buf *b, size_t extra, const char *desc) { 598 static void buf_check_ctx(uw_context ctx, buf *b, size_t extra, const char *desc) {
594 if (b->back - b->front < extra) { 599 if (b->back - b->front < extra) {
595 size_t desired = b->front - b->start + extra, next; 600 size_t desired = b->front - b->start + extra, next;
596 char *new_heap; 601 char *new_heap;
715 sprintf(r, " onload='%s'", s); 720 sprintf(r, " onload='%s'", s);
716 return r; 721 return r;
717 } 722 }
718 } 723 }
719 724
725 extern uw_Basis_string uw_cookie_sig(uw_context);
726
720 const char *uw_Basis_get_settings(uw_context ctx, uw_unit u) { 727 const char *uw_Basis_get_settings(uw_context ctx, uw_unit u) {
721 if (ctx->client == NULL) 728 if (ctx->client == NULL) {
722 return ""; 729 if (ctx->needs_sig) {
723 else { 730 char *sig = uw_cookie_sig(ctx);
724 char *r = uw_malloc(ctx, 59 + 3 * INTS_MAX + strlen(ctx->url_prefix)); 731 char *r = uw_malloc(ctx, strlen(sig) + 8);
725 sprintf(r, "client_id=%u;client_pass=%d;url_prefix=\"%s\";timeout=%d;listener();", 732 sprintf(r, "sig=\"%s\";", sig);
733 return r;
734 }
735 else
736 return "";
737 } else {
738 char *sig = ctx->needs_sig ? uw_cookie_sig(ctx) : "";
739 char *r = uw_malloc(ctx, 59 + 3 * INTS_MAX + strlen(ctx->url_prefix)
740 + (ctx->needs_sig ? strlen(sig) + 7 : 0));
741 sprintf(r, "client_id=%u;client_pass=%d;url_prefix=\"%s\";timeout=%d;%s%s%slistener();",
726 ctx->client->id, 742 ctx->client->id,
727 ctx->client->pass, 743 ctx->client->pass,
728 ctx->url_prefix, 744 ctx->url_prefix,
729 ctx->timeout); 745 ctx->timeout,
746 ctx->needs_sig ? "sig=\"" : "",
747 sig,
748 ctx->needs_sig ? "\";" : "");
730 return r; 749 return r;
731 } 750 }
732 } 751 }
733 752
734 uw_Basis_string uw_Basis_jsifyString(uw_context ctx, uw_Basis_string s) { 753 uw_Basis_string uw_Basis_jsifyString(uw_context ctx, uw_Basis_string s) {
1996 sprintf(&r[2*i], "%.02X", ((unsigned char *)sig)[i]); 2015 sprintf(&r[2*i], "%.02X", ((unsigned char *)sig)[i]);
1997 2016
1998 return r; 2017 return r;
1999 } 2018 }
2000 2019
2001 extern uw_Basis_string uw_cookie_sig(uw_context);
2002
2003 uw_Basis_string uw_Basis_sigString(uw_context ctx, uw_unit u) { 2020 uw_Basis_string uw_Basis_sigString(uw_context ctx, uw_unit u) {
2004 return uw_cookie_sig(ctx); 2021 return uw_cookie_sig(ctx);
2005 } 2022 }