{"action":"created","comment":{"url":"https://api.github.com/repos/jorisvink/kore/pulls/comments/70050986","id":70050986,"diff_hunk":"@@ -0,0 +1,493 @@\n+/*\n+ * Copyright (c) 2016 Raphaël Monrouzeau <raphael.monrouzeau@gmail.com>\n+ *\n+ * Permission to use, copy, modify, and distribute this software for any\n+ * purpose with or without fee is hereby granted, provided that the above\n+ * copyright notice and this permission notice appear in all copies.\n+ *\n+ * THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES\n+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF\n+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR\n+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES\n+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN\n+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF\n+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.\n+ */\n+\n+#include <stdbool.h>\n+\n+#include <yajl/yajl_tree.h>\n+#include <yajl/yajl_gen.h>\n+\n+#include \"kore.h\"\n+#include \"http.h\"\n+#include \"jsonrpc.h\"\n+\n+static void\n+init_log(struct jsonrpc_log *log)\n+{\n+\tlog->msg = NULL;\n+\tlog->next = log;\n+\tlog->prev = log;\n+}\n+\n+static void\n+append_log(struct jsonrpc_log *prev, int lvl, char *msg)\n+{\n+\tstruct jsonrpc_log *new = kore_malloc(sizeof(struct jsonrpc_log));\n+\n+\tnew->lvl = lvl;\n+\tnew->msg = msg;\n+\n+\tnew->prev = prev;\n+\tnew->next = prev->next;\n+\tprev->next->prev = new;\n+\tprev->next = new;\n+}\n+\n+static void\n+free_log(struct jsonrpc_log *root)\n+{\n+\tfor (struct jsonrpc_log *it = root->next; it != root; it = it->next) {\n+\t\tkore_mem_free(it);\n+\t}\n+}\n+\n+static void\n+init_request(struct jsonrpc_request *req)\n+{\n+\tinit_log(&req->log);\n+\tkore_buf_init(&req->buf, 256);\n+\treq->gen = NULL;\n+\treq->http = NULL;\n+\treq->json = NULL;\n+\treq->id = NULL;\n+\treq->method = NULL;\n+\treq->params = NULL;\n+\treq->log_levels = (1 << LOG_EMERG) | (1 << LOG_ERR) | (1 << LOG_WARNING)\n+\t\t\t| (1 << LOG_NOTICE);\n+        req->flags = 0;\n+}\n+\n+static void\n+free_request(struct jsonrpc_request *req)\n+{\n+\tif (req->gen != NULL) {\n+\t\tyajl_gen_free(req->gen);\n+\t\treq->gen = NULL;\n+\t}\n+\tif (req->json != NULL) {\n+\t\tyajl_tree_free(req->json);\n+\t\treq->json = NULL;\n+\t}\n+\tkore_buf_destroy(&req->buf);\n+\tfree_log(&req->log);\n+}\n+\n+void\n+jsonrpc_log(struct jsonrpc_request *req, int lvl, const char *fmt, ...)\n+{\n+\tva_list\t\tap;\n+\tchar\t\t*msg;\n+\tu_int32_t\tstart = req->buf.offset;\n+\n+\tva_start(ap, fmt);\n+\tkore_buf_appendv(&req->buf, fmt, ap);\n+\tva_end(ap);\n+\n+\tmsg = kore_buf_stringify(&req->buf, NULL) + start;\n+\n+\tappend_log(&req->log, lvl, msg);\n+}\n+\n+static int\n+read_json_body(struct http_request *http_req, ssize_t body_max_len,\n+    struct jsonrpc_request *req)\n+{\n+\tchar\t\t*body_string;\n+\tu_int32_t\tbody_start = req->buf.offset;\n+\tssize_t\t\tbody_len = 0, chunk_len;\n+\tu_int8_t\tchunk_buffer[BUFSIZ];\n+\tchar\t\terror_buffer[1024];\n+\n+\tfor (;;) {\n+\t\tchunk_len = http_body_read(http_req, chunk_buffer,\n+\t\t\tsizeof(chunk_buffer));\n+\t\tif (chunk_len == -1) {\n+\t\t\tjsonrpc_log(req, LOG_CRIT,\n+\t\t\t    \"Failed to read request body\");\n+\t\t\treturn (JSONRPC_SERVER_ERROR);\n+\t\t}\n+\n+\t\tif (chunk_len == 0)\n+\t\t\tbreak;\n+\n+\t\tif (body_len > SSIZE_MAX - chunk_len) {","path":"src/jsonrpc.c","position":125,"original_position":125,"commit_id":"d0fa799dd00eb4c37e334456f81caf639e81571f","original_commit_id":"d0fa799dd00eb4c37e334456f81caf639e81571f","user":{"login":"jorisvink","id":1258619,"avatar_url":"https://avatars.githubusercontent.com/u/1258619?v=3","gravatar_id":"","url":"https://api.github.com/users/jorisvink","html_url":"https://github.com/jorisvink","followers_url":"https://api.github.com/users/jorisvink/followers","following_url":"https://api.github.com/users/jorisvink/following{/other_user}","gists_url":"https://api.github.com/users/jorisvink/gists{/gist_id}","starred_url":"https://api.github.com/users/jorisvink/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jorisvink/subscriptions","organizations_url":"https://api.github.com/users/jorisvink/orgs","repos_url":"https://api.github.com/users/jorisvink/repos","events_url":"https://api.github.com/users/jorisvink/events{/privacy}","received_events_url":"https://api.github.com/users/jorisvink/received_events","type":"User","site_admin":false},"body":"I think this can be killed off completely as the incoming body is always limited to http_body_max.","created_at":"2016-07-08T09:54:28Z","updated_at":"2016-07-08T09:54:28Z","html_url":"https://github.com/jorisvink/kore/pull/135#discussion_r70050986","pull_request_url":"https://api.github.com/repos/jorisvink/kore/pulls/135","_links":{"self":{"href":"https://api.github.com/repos/jorisvink/kore/pulls/comments/70050986"},"html":{"href":"https://github.com/jorisvink/kore/pull/135#discussion_r70050986"},"pull_request":{"href":"https://api.github.com/repos/jorisvink/kore/pulls/135"}}},"pull_request":{"url":"https://api.github.com/repos/jorisvink/kore/pulls/135","id":76667951,"html_url":"https://github.com/jorisvink/kore/pull/135","diff_url":"https://github.com/jorisvink/kore/pull/135.diff","patch_url":"https://github.com/jorisvink/kore/pull/135.patch","issue_url":"https://api.github.com/repos/jorisvink/kore/issues/135","number":135,"state":"open","locked":false,"title":"Add conditional JSON-RPC support","user":{"login":"raphaelmonrouzeau","id":103309,"avatar_url":"https://avatars.githubusercontent.com/u/103309?v=3","gravatar_id":"","url":"https://api.github.com/users/raphaelmonrouzeau","html_url":"https://github.com/raphaelmonrouzeau","followers_url":"https://api.github.com/users/raphaelmonrouzeau/followers","following_url":"https://api.github.com/users/raphaelmonrouzeau/following{/other_user}","gists_url":"https://api.github.com/users/raphaelmonrouzeau/gists{/gist_id}","starred_url":"https://api.github.com/users/raphaelmonrouzeau/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/raphaelmonrouzeau/subscriptions","organizations_url":"https://api.github.com/users/raphaelmonrouzeau/orgs","repos_url":"https://api.github.com/users/raphaelmonrouzeau/repos","events_url":"https://api.github.com/users/raphaelmonrouzeau/events{/privacy}","received_events_url":"https://api.github.com/users/raphaelmonrouzeau/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-07-07T21:25:32Z","updated_at":"2016-07-08T09:54:28Z","closed_at":null,"merged_at":null,"merge_commit_sha":"55c92f41fbe3299ecf5e4e99bc28b09024d3c5cb","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/jorisvink/kore/pulls/135/commits","review_comments_url":"https://api.github.com/repos/jorisvink/kore/pulls/135/comments","review_comment_url":"https://api.github.com/repos/jorisvink/kore/pulls/comments{/number}","comments_url":"https://api.github.com/repos/jorisvink/kore/issues/135/comments","statuses_url":"https://api.github.com/repos/jorisvink/kore/statuses/d0fa799dd00eb4c37e334456f81caf639e81571f","head":{"label":"raphaelmonrouzeau:master","ref":"master","sha":"d0fa799dd00eb4c37e334456f81caf639e81571f","user":{"login":"raphaelmonrouzeau","id":103309,"avatar_url":"https://avatars.githubusercontent.com/u/103309?v=3","gravatar_id":"","url":"https://api.github.com/users/raphaelmonrouzeau","html_url":"https://github.com/raphaelmonrouzeau","followers_url":"https://api.github.com/users/raphaelmonrouzeau/followers","following_url":"https://api.github.com/users/raphaelmonrouzeau/following{/other_user}","gists_url":"https://api.github.com/users/raphaelmonrouzeau/gists{/gist_id}","starred_url":"https://api.github.com/users/raphaelmonrouzeau/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/raphaelmonrouzeau/subscriptions","organizations_url":"https://api.github.com/users/raphaelmonrouzeau/orgs","repos_url":"https://api.github.com/users/raphaelmonrouzeau/repos","events_url":"https://api.github.com/users/raphaelmonrouzeau/events{/privacy}","received_events_url":"https://api.github.com/users/raphaelmonrouzeau/received_events","type":"User","site_admin":false},"repo":{"id":60582744,"name":"kore","full_name":"raphaelmonrouzeau/kore","owner":{"login":"raphaelmonrouzeau","id":103309,"avatar_url":"https://avatars.githubusercontent.com/u/103309?v=3","gravatar_id":"","url":"https://api.github.com/users/raphaelmonrouzeau","html_url":"https://github.com/raphaelmonrouzeau","followers_url":"https://api.github.com/users/raphaelmonrouzeau/followers","following_url":"https://api.github.com/users/raphaelmonrouzeau/following{/other_user}","gists_url":"https://api.github.com/users/raphaelmonrouzeau/gists{/gist_id}","starred_url":"https://api.github.com/users/raphaelmonrouzeau/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/raphaelmonrouzeau/subscriptions","organizations_url":"https://api.github.com/users/raphaelmonrouzeau/orgs","repos_url":"https://api.github.com/users/raphaelmonrouzeau/repos","events_url":"https://api.github.com/users/raphaelmonrouzeau/events{/privacy}","received_events_url":"https://api.github.com/users/raphaelmonrouzeau/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/raphaelmonrouzeau/kore","description":"An easy to use, scalable and secure web application framework for writing web APIs in C.","fork":true,"url":"https://api.github.com/repos/raphaelmonrouzeau/kore","forks_url":"https://api.github.com/repos/raphaelmonrouzeau/kore/forks","keys_url":"https://api.github.com/repos/raphaelmonrouzeau/kore/keys{/key_id}","collaborators_url":"https://api.github.com/repos/raphaelmonrouzeau/kore/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/raphaelmonrouzeau/kore/teams","hooks_url":"https://api.github.com/repos/raphaelmonrouzeau/kore/hooks","issue_events_url":"https://api.github.com/repos/raphaelmonrouzeau/kore/issues/events{/number}","events_url":"https://api.github.com/repos/raphaelmonrouzeau/kore/events","assignees_url":"https://api.github.com/repos/raphaelmonrouzeau/kore/assignees{/user}","branches_url":"https://api.github.com/repos/raphaelmonrouzeau/kore/branches{/branch}","tags_url":"https://api.github.com/repos/raphaelmonrouzeau/kore/tags","blobs_url":"https://api.github.com/repos/raphaelmonrouzeau/kore/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/raphaelmonrouzeau/kore/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/raphaelmonrouzeau/kore/git/refs{/sha}","trees_url":"https://api.github.com/repos/raphaelmonrouzeau/kore/git/trees{/sha}","statuses_url":"https://api.github.com/repos/raphaelmonrouzeau/kore/statuses/{sha}","languages_url":"https://api.github.com/repos/raphaelmonrouzeau/kore/languages","stargazers_url":"https://api.github.com/repos/raphaelmonrouzeau/kore/stargazers","contributors_url":"https://api.github.com/repos/raphaelmonrouzeau/kore/contributors","subscribers_url":"https://api.github.com/repos/raphaelmonrouzeau/kore/subscribers","subscription_url":"https://api.github.com/repos/raphaelmonrouzeau/kore/subscription","commits_url":"https://api.github.com/repos/raphaelmonrouzeau/kore/commits{/sha}","git_commits_url":"https://api.github.com/repos/raphaelmonrouzeau/kore/git/commits{/sha}","comments_url":"https://api.github.com/repos/raphaelmonrouzeau/kore/comments{/number}","issue_comment_url":"https://api.github.com/repos/raphaelmonrouzeau/kore/issues/comments{/number}","contents_url":"https://api.github.com/repos/raphaelmonrouzeau/kore/contents/{+path}","compare_url":"https://api.github.com/repos/raphaelmonrouzeau/kore/compare/{base}...{head}","merges_url":"https://api.github.com/repos/raphaelmonrouzeau/kore/merges","archive_url":"https://api.github.com/repos/raphaelmonrouzeau/kore/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/raphaelmonrouzeau/kore/downloads","issues_url":"https://api.github.com/repos/raphaelmonrouzeau/kore/issues{/number}","pulls_url":"https://api.github.com/repos/raphaelmonrouzeau/kore/pulls{/number}","milestones_url":"https://api.github.com/repos/raphaelmonrouzeau/kore/milestones{/number}","notifications_url":"https://api.github.com/repos/raphaelmonrouzeau/kore/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/raphaelmonrouzeau/kore/labels{/name}","releases_url":"https://api.github.com/repos/raphaelmonrouzeau/kore/releases{/id}","deployments_url":"https://api.github.com/repos/raphaelmonrouzeau/kore/deployments","created_at":"2016-06-07T04:41:55Z","updated_at":"2016-06-07T04:41:56Z","pushed_at":"2016-07-07T21:22:55Z","git_url":"git://github.com/raphaelmonrouzeau/kore.git","ssh_url":"git@github.com:raphaelmonrouzeau/kore.git","clone_url":"https://github.com/raphaelmonrouzeau/kore.git","svn_url":"https://github.com/raphaelmonrouzeau/kore","homepage":"https://kore.io","size":3481,"stargazers_count":0,"watchers_count":0,"language":"C","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"jorisvink:master","ref":"master","sha":"a8917e355a3a953cbbefb824a4625adfa7732c5c","user":{"login":"jorisvink","id":1258619,"avatar_url":"https://avatars.githubusercontent.com/u/1258619?v=3","gravatar_id":"","url":"https://api.github.com/users/jorisvink","html_url":"https://github.com/jorisvink","followers_url":"https://api.github.com/users/jorisvink/followers","following_url":"https://api.github.com/users/jorisvink/following{/other_user}","gists_url":"https://api.github.com/users/jorisvink/gists{/gist_id}","starred_url":"https://api.github.com/users/jorisvink/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jorisvink/subscriptions","organizations_url":"https://api.github.com/users/jorisvink/orgs","repos_url":"https://api.github.com/users/jorisvink/repos","events_url":"https://api.github.com/users/jorisvink/events{/privacy}","received_events_url":"https://api.github.com/users/jorisvink/received_events","type":"User","site_admin":false},"repo":{"id":10504702,"name":"kore","full_name":"jorisvink/kore","owner":{"login":"jorisvink","id":1258619,"avatar_url":"https://avatars.githubusercontent.com/u/1258619?v=3","gravatar_id":"","url":"https://api.github.com/users/jorisvink","html_url":"https://github.com/jorisvink","followers_url":"https://api.github.com/users/jorisvink/followers","following_url":"https://api.github.com/users/jorisvink/following{/other_user}","gists_url":"https://api.github.com/users/jorisvink/gists{/gist_id}","starred_url":"https://api.github.com/users/jorisvink/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jorisvink/subscriptions","organizations_url":"https://api.github.com/users/jorisvink/orgs","repos_url":"https://api.github.com/users/jorisvink/repos","events_url":"https://api.github.com/users/jorisvink/events{/privacy}","received_events_url":"https://api.github.com/users/jorisvink/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jorisvink/kore","description":"An easy to use, scalable and secure web application framework for writing web APIs in C.","fork":false,"url":"https://api.github.com/repos/jorisvink/kore","forks_url":"https://api.github.com/repos/jorisvink/kore/forks","keys_url":"https://api.github.com/repos/jorisvink/kore/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jorisvink/kore/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jorisvink/kore/teams","hooks_url":"https://api.github.com/repos/jorisvink/kore/hooks","issue_events_url":"https://api.github.com/repos/jorisvink/kore/issues/events{/number}","events_url":"https://api.github.com/repos/jorisvink/kore/events","assignees_url":"https://api.github.com/repos/jorisvink/kore/assignees{/user}","branches_url":"https://api.github.com/repos/jorisvink/kore/branches{/branch}","tags_url":"https://api.github.com/repos/jorisvink/kore/tags","blobs_url":"https://api.github.com/repos/jorisvink/kore/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jorisvink/kore/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jorisvink/kore/git/refs{/sha}","trees_url":"https://api.github.com/repos/jorisvink/kore/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jorisvink/kore/statuses/{sha}","languages_url":"https://api.github.com/repos/jorisvink/kore/languages","stargazers_url":"https://api.github.com/repos/jorisvink/kore/stargazers","contributors_url":"https://api.github.com/repos/jorisvink/kore/contributors","subscribers_url":"https://api.github.com/repos/jorisvink/kore/subscribers","subscription_url":"https://api.github.com/repos/jorisvink/kore/subscription","commits_url":"https://api.github.com/repos/jorisvink/kore/commits{/sha}","git_commits_url":"https://api.github.com/repos/jorisvink/kore/git/commits{/sha}","comments_url":"https://api.github.com/repos/jorisvink/kore/comments{/number}","issue_comment_url":"https://api.github.com/repos/jorisvink/kore/issues/comments{/number}","contents_url":"https://api.github.com/repos/jorisvink/kore/contents/{+path}","compare_url":"https://api.github.com/repos/jorisvink/kore/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jorisvink/kore/merges","archive_url":"https://api.github.com/repos/jorisvink/kore/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jorisvink/kore/downloads","issues_url":"https://api.github.com/repos/jorisvink/kore/issues{/number}","pulls_url":"https://api.github.com/repos/jorisvink/kore/pulls{/number}","milestones_url":"https://api.github.com/repos/jorisvink/kore/milestones{/number}","notifications_url":"https://api.github.com/repos/jorisvink/kore/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jorisvink/kore/labels{/name}","releases_url":"https://api.github.com/repos/jorisvink/kore/releases{/id}","deployments_url":"https://api.github.com/repos/jorisvink/kore/deployments","created_at":"2013-06-05T14:37:22Z","updated_at":"2016-07-08T02:53:05Z","pushed_at":"2016-07-08T08:04:51Z","git_url":"git://github.com/jorisvink/kore.git","ssh_url":"git@github.com:jorisvink/kore.git","clone_url":"https://github.com/jorisvink/kore.git","svn_url":"https://github.com/jorisvink/kore","homepage":"https://kore.io","size":3883,"stargazers_count":2034,"watchers_count":2034,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":170,"mirror_url":null,"open_issues_count":5,"forks":170,"open_issues":5,"watchers":2034,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/jorisvink/kore/pulls/135"},"html":{"href":"https://github.com/jorisvink/kore/pull/135"},"issue":{"href":"https://api.github.com/repos/jorisvink/kore/issues/135"},"comments":{"href":"https://api.github.com/repos/jorisvink/kore/issues/135/comments"},"review_comments":{"href":"https://api.github.com/repos/jorisvink/kore/pulls/135/comments"},"review_comment":{"href":"https://api.github.com/repos/jorisvink/kore/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/jorisvink/kore/pulls/135/commits"},"statuses":{"href":"https://api.github.com/repos/jorisvink/kore/statuses/d0fa799dd00eb4c37e334456f81caf639e81571f"}}}}
{"actor":{"display_login":"jorisvink"}}