comparison src/c/urweb.c @ 1942:a671e5258a2c

Raise exception when recv()ing from someone else's channel; improve setting of client ID in RPCs
author Adam Chlipala <adam@chlipala.net>
date Fri, 27 Dec 2013 12:10:03 -0500
parents 9f3597979e98
children 3ecd0b6360eb
comparison
equal deleted inserted replaced
1941:9f3597979e98 1942:a671e5258a2c
732 } 732 }
733 733
734 char *uw_Basis_htmlifyString(uw_context, const char *); 734 char *uw_Basis_htmlifyString(uw_context, const char *);
735 735
736 void uw_login(uw_context ctx) { 736 void uw_login(uw_context ctx) {
737 if (ctx->needs_push) { 737 char *id_s, *pass_s;
738 char *id_s, *pass_s; 738
739 739 if ((id_s = uw_Basis_requestHeader(ctx, "UrWeb-Client"))
740 if ((id_s = uw_Basis_requestHeader(ctx, "UrWeb-Client")) 740 && (pass_s = uw_Basis_requestHeader(ctx, "UrWeb-Pass"))) {
741 && (pass_s = uw_Basis_requestHeader(ctx, "UrWeb-Pass"))) { 741 unsigned id = atoi(id_s);
742 unsigned id = atoi(id_s); 742 int pass = atoi(pass_s);
743 int pass = atoi(pass_s); 743 client *c = find_client(id);
744 client *c = find_client(id); 744
745 745 if (c == NULL)
746 if (c == NULL) 746 uw_error(ctx, FATAL, "Unknown client ID in HTTP headers (%s, %s)", uw_Basis_htmlifyString(ctx, id_s), uw_Basis_htmlifyString(ctx, pass_s));
747 uw_error(ctx, FATAL, "Unknown client ID in HTTP headers (%s, %s)", uw_Basis_htmlifyString(ctx, id_s), uw_Basis_htmlifyString(ctx, pass_s)); 747 else {
748 else {
749 use_client(c);
750 ctx->client = c;
751
752 if (c->mode != USED)
753 uw_error(ctx, FATAL, "Stale client ID (%u) in subscription request", id);
754 if (c->pass != pass)
755 uw_error(ctx, FATAL, "Wrong client password (%u, %d) in subscription request", id, pass);
756 }
757 } else {
758 client *c = new_client();
759
760 if (c == NULL)
761 uw_error(ctx, FATAL, "Limit exceeded on number of message-passing clients");
762
763 use_client(c); 748 use_client(c);
764 uw_copy_client_data(c->data, ctx->client_data);
765 ctx->client = c; 749 ctx->client = c;
766 } 750
751 if (c->mode != USED)
752 uw_error(ctx, FATAL, "Stale client ID (%u) in subscription request", id);
753 if (c->pass != pass)
754 uw_error(ctx, FATAL, "Wrong client password (%u, %d) in subscription request", id, pass);
755 }
756 } else if (ctx->needs_push) {
757 client *c = new_client();
758
759 if (c == NULL)
760 uw_error(ctx, FATAL, "Limit exceeded on number of message-passing clients");
761
762 use_client(c);
763 uw_copy_client_data(c->data, ctx->client_data);
764 ctx->client = c;
767 } 765 }
768 } 766 }
769 767
770 failure_kind uw_begin(uw_context ctx, char *path) { 768 failure_kind uw_begin(uw_context ctx, char *path) {
771 int r = setjmp(ctx->jmp_buf); 769 int r = setjmp(ctx->jmp_buf);