comparison src/c/request.c @ 863:305bc0a431de

.msgs processing in FastCGI
author Adam Chlipala <adamc@hcoop.net>
date Sat, 27 Jun 2009 17:50:31 -0400
parents 86ec89baee01
children 6304f5e8fbb4
comparison
equal deleted inserted replaced
862:66dbf3953758 863:305bc0a431de
149 void uw_free_request_context(uw_request_context r) { 149 void uw_free_request_context(uw_request_context r) {
150 free(r->path_copy); 150 free(r->path_copy);
151 free(r); 151 free(r);
152 } 152 }
153 153
154 extern char *uw_url_prefix;
155
154 request_result uw_request(uw_request_context rc, uw_context ctx, 156 request_result uw_request(uw_request_context rc, uw_context ctx,
155 char *method, char *path, char *query_string, 157 char *method, char *path, char *query_string,
156 char *body, size_t body_len, 158 char *body, size_t body_len,
157 void (*on_success)(uw_context), void (*on_failure)(uw_context), 159 void (*on_success)(uw_context), void (*on_failure)(uw_context),
158 void *logger_data, uw_logger log_error, uw_logger log_debug, 160 void *logger_data, uw_logger log_error, uw_logger log_debug,
159 int sock) { 161 int sock,
162 int (*send)(int sockfd, const void *buf, size_t len),
163 int (*close)(int fd)) {
160 int retries_left = MAX_RETRIES; 164 int retries_left = MAX_RETRIES;
161 char *s; 165 char *s;
162 failure_kind fk; 166 failure_kind fk;
163 int is_post = 0, do_normal_send = 1; 167 int is_post = 0, do_normal_send = 1;
164 char *boundary = NULL; 168 char *boundary = NULL;
199 } else if (strcmp(method, "GET")) { 203 } else if (strcmp(method, "GET")) {
200 log_error(logger_data, "Not ready for non-GET/POST command: %s\n", method); 204 log_error(logger_data, "Not ready for non-GET/POST command: %s\n", method);
201 return FAILED; 205 return FAILED;
202 } 206 }
203 207
204 if (!strcmp(path, "/.msgs")) { 208 if (!strncmp(path, uw_url_prefix, strlen(uw_url_prefix))
209 && !strcmp(path + strlen(uw_url_prefix), ".msgs")) {
205 char *id = uw_Basis_requestHeader(ctx, "UrWeb-Client"); 210 char *id = uw_Basis_requestHeader(ctx, "UrWeb-Client");
206 char *pass = uw_Basis_requestHeader(ctx, "UrWeb-Pass"); 211 char *pass = uw_Basis_requestHeader(ctx, "UrWeb-Pass");
207 212
208 if (sock < 0) { 213 if (sock < 0) {
209 log_error(logger_data, ".msgs requested, but not socket supplied\n"); 214 log_error(logger_data, ".msgs requested, but not socket supplied\n");
210 return FAILED; 215 return FAILED;
211 } 216 }
212 217
213 if (id && pass) { 218 if (id && pass) {
214 unsigned idn = atoi(id); 219 unsigned idn = atoi(id);
215 uw_client_connect(idn, atoi(pass), sock); 220 uw_client_connect(idn, atoi(pass), sock, send, close);
216 log_error(logger_data, "Processed request for messages by client %u\n\n", idn); 221 log_error(logger_data, "Processed request for messages by client %u\n\n", idn);
217 return KEEP_OPEN; 222 return KEEP_OPEN;
218 } 223 }
219 else { 224 else {
220 log_error(logger_data, "Missing fields in .msgs request: %s, %s\n\n", id, pass); 225 log_error(logger_data, "Missing fields in .msgs request: %s, %s\n\n", id, pass);