/** * Called when a client has finished reading input and can create a cmd */ void worker_process_client(struct http_client *c) { /* check that the command can be executed */ struct worker *w = c->w; cmd_response_t ret = CMD_PARAM_ERROR; switch(c->parser.method) { case HTTP_GET: if(c->path_sz == 16 && memcmp(c->path, "/crossdomain.xml", 16) == 0) { http_crossdomain(c); return; } slog(w->s, WEBDIS_DEBUG, c->path, c->path_sz); ret = cmd_run(c->w, c, 1+c->path, c->path_sz-1, NULL, 0); break; case HTTP_POST: slog(w->s, WEBDIS_DEBUG, c->path, c->path_sz); ret = cmd_run(c->w, c, c->body, c->body_sz, NULL, 0); break; case HTTP_PUT: slog(w->s, WEBDIS_DEBUG, c->path, c->path_sz); ret = cmd_run(c->w, c, 1+c->path, c->path_sz-1, c->body, c->body_sz); break; case HTTP_OPTIONS: http_send_options(c); return; default: slog(w->s, WEBDIS_DEBUG, "405", 3); http_send_error(c, 405, "Method Not Allowed"); return; } switch(ret) { case CMD_ACL_FAIL: case CMD_PARAM_ERROR: slog(w->s, WEBDIS_DEBUG, "403", 3); http_send_error(c, 403, "Forbidden"); break; case CMD_REDIS_UNAVAIL: slog(w->s, WEBDIS_DEBUG, "503", 3); http_send_error(c, 503, "Service Unavailable"); break; default: break; } }
/** * Called when a client has finished reading input and can create a cmd */ void worker_process_client(struct http_client *c) { /* check that the command can be executed */ struct worker *w = c->w; cmd_response_t ret = CMD_PARAM_ERROR; char *client_ip; /* well set this equal to the IP string address returned by inet_ntoa */ client_ip = inet_ntoa(*(struct in_addr *)&c->addr); /* cast x as a struct in_addr */ char msg[128] = {}; sprintf(msg,"%s %s",client_ip,c->path); switch(c->parser.method) { case HTTP_GET: if(c->path_sz == 16 && memcmp(c->path, "/crossdomain.xml", 16) == 0) { http_crossdomain(c); return; } ret = cmd_run(c->w, c, 1+c->path, c->path_sz-1, NULL, 0); sprintf(msg,"%s GET %d",msg,(int)ret); slog(w->s, WEBDIS_DEBUG, msg, strlen(msg)); break; case HTTP_POST: ret = cmd_run(c->w, c, c->body, c->body_sz, NULL, 0); sprintf(msg,"%s POST %d",msg,(int)ret); slog(w->s, WEBDIS_DEBUG, msg, strlen(msg)); break; case HTTP_PUT: ret = cmd_run(c->w, c, 1+c->path, c->path_sz-1, c->body, c->body_sz); sprintf(msg,"%s PUT %d",msg,(int)ret); slog(w->s, WEBDIS_DEBUG, msg, strlen(msg)); break; case HTTP_OPTIONS: http_send_options(c); default: slog(w->s, WEBDIS_DEBUG, "405", 3); http_send_error(c, 405, "Method Not Allowed"); return; } switch(ret) { case CMD_ACL_FAIL: case CMD_PARAM_ERROR: slog(w->s, WEBDIS_DEBUG, "403", 3); http_send_error(c, 403, "Forbidden"); break; case CMD_REDIS_UNAVAIL: slog(w->s, WEBDIS_DEBUG, "503", 3); http_send_error(c, 503, "Service Unavailable"); break; default: break; } }