int verify_request (struct http_request *req, char **data) { const char *msg = NULL; json_object *json_msg = NULL; json_msg = json_object_new_object (); if (req->method != HTTP_METHOD_POST) { json_object_object_add (json_msg, "result", json_object_new_int (KORE_RESULT_ERROR)); json_object_object_add (json_msg, "message", json_object_new_string ("method is not post")); msg = json_object_to_json_string(json_msg); http_response (req, 200, msg, strlen(msg)); json_object_put (json_msg); return (KORE_RESULT_ERROR); } http_populate_post (req); if (http_argument_get_string (req, "data", data) == KORE_RESULT_ERROR) { json_object_object_add (json_msg, "result", json_object_new_int (KORE_RESULT_ERROR)); json_object_object_add (json_msg, "message", json_object_new_string ("argument key is not data")); msg = json_object_to_json_string(json_msg); http_response (req, 200, msg, strlen(msg)); json_object_put (json_msg); return (KORE_RESULT_ERROR); } json_object_put (json_msg); return (KORE_RESULT_OK); }
int serve_params_test(struct http_request *req) { struct kore_buf *b; u_int8_t *d; size_t len; int r, i; char *test, name[10]; if (req->method == HTTP_METHOD_GET) http_populate_get(req); else if (req->method == HTTP_METHOD_POST) http_populate_post(req); b = kore_buf_alloc(asset_len_params_html); kore_buf_append(b, asset_params_html, asset_len_params_html); /* * The GET parameters will be filtered out on POST. */ if (http_argument_get_string(req, "arg1", &test)) { kore_buf_replace_string(b, "$arg1$", test, strlen(test)); } else { kore_buf_replace_string(b, "$arg1$", NULL, 0); } if (http_argument_get_string(req, "arg2", &test)) { kore_buf_replace_string(b, "$arg2$", test, strlen(test)); } else { kore_buf_replace_string(b, "$arg2$", NULL, 0); } if (req->method == HTTP_METHOD_GET) { kore_buf_replace_string(b, "$test1$", NULL, 0); kore_buf_replace_string(b, "$test2$", NULL, 0); kore_buf_replace_string(b, "$test3$", NULL, 0); if (http_argument_get_uint16(req, "id", &r)) kore_log(LOG_NOTICE, "id: %d", r); else kore_log(LOG_NOTICE, "No id set"); http_response_header(req, "content-type", "text/html"); d = kore_buf_release(b, &len); http_response(req, 200, d, len); kore_free(d); return (KORE_RESULT_OK); } for (i = 1; i < 4; i++) { (void)snprintf(name, sizeof(name), "test%d", i); if (http_argument_get_string(req, name, &test)) { (void)snprintf(name, sizeof(name), "$test%d$", i); kore_buf_replace_string(b, name, test, strlen(test)); } else { (void)snprintf(name, sizeof(name), "$test%d$", i); kore_buf_replace_string(b, name, NULL, 0); } } http_response_header(req, "content-type", "text/html"); d = kore_buf_release(b, &len); http_response(req, 200, d, len); kore_free(d); return (KORE_RESULT_OK); }