{"action":"created","comment":{"url":"https://api.github.com/repos/ElektraInitiative/libelektra/pulls/comments/39827268","id":39827268,"diff_hunk":"@@ -0,0 +1,350 @@\n+/**\n+ * \\file\n+ *\n+ * \\brief Source for csvstorage plugin\n+ *\n+ * \\copyright BSD License (see doc/COPYING or http://www.libelektra.org)\n+ *\n+ */\n+\n+\n+#ifndef HAVE_KDBCONFIG\n+# include \"kdbconfig.h\"\n+#endif\n+\n+#include <string.h>\n+#include <stdio.h>\n+#include <stdlib.h>\n+#include <kdberrors.h>\n+\n+#include \"csvstorage.h\"\n+\n+static char *parseLine(char *_line, char delim, unsigned long offset)\n+{\n+\tchar *line = (_line + offset);\n+\tif(*line == '\\0')\n+\t\treturn NULL;\n+\tchar *ptr = strchr(line, delim);\n+\n+\tif(ptr == NULL)\n+\t{\n+\t\tline[strlen(line)-1]='\\0';\n+\t}\n+\telse\n+\t\t*ptr = '\\0';\n+\treturn line;\n+}\n+\n+static unsigned long getLineLength(FILE *fp)\n+{\n+\tint startPos = ftell(fp);\n+\tchar c;\n+\twhile((c = fgetc(fp)) && (!feof(fp)))\n+\t{\n+\t\tif(c == '\\n')\n+\t\t\tbreak;\n+\t}\n+\tint  endPos = ftell(fp);\n+\tfseek(fp, startPos, SEEK_SET);\n+\tif((endPos - startPos) == 0)\n+\t\treturn 0;\n+\telse\n+\t\treturn (endPos - startPos)+1;\n+}\n+\n+static unsigned long getColumnCount(char *lineBuffer, char delim)\n+{\n+\tchar *ptr = lineBuffer;\n+\tunsigned long counter = 0;\n+\twhile(*ptr != '\\0')\n+\t{\n+\t\tif(*ptr == delim)\n+\t\t\t++counter;\n+\t\t++ptr;\n+\t}\n+\t++counter;\n+\treturn counter;\n+}\n+\n+char *itostr(char *buf, unsigned long i, uint8_t len)\n+{\n+\tsnprintf(buf, len, \"%lu\", i);\n+\treturn buf;\n+}\n+\n+static Key *getKeyByOrderNr(KeySet *ks, unsigned long n)\n+{\n+\tKey *cur;\n+\tchar buf[16];\n+\tksRewind(ks);\n+\twhile((cur = ksNext(ks)) != NULL)\n+\t{\n+\t\tif(!strcmp(keyString(keyGetMeta(cur, \"csvOrder\")), itostr(buf, n, sizeof(buf)-1)))\n+\t\t\treturn cur; \n+\t}\n+\treturn NULL;\n+}\n+int elektraCsvstorageGet(Plugin *handle, KeySet *returned, Key *parentKey)\n+{\n+\tif (!strcmp(keyName(parentKey), \"system/elektra/modules/csvstorage\"))\n+\t{\n+\t\tKeySet *contract = ksNew (30,\n+\t\t\t\tkeyNew (\"system/elektra/modules/csvstorage\",\n+\t\t\t\t\tKEY_VALUE, \"csvstorage plugin waits for your orders\", KEY_END),\n+\t\t\t\tkeyNew (\"system/elektra/modules/csvstorage/exports\", KEY_END),\n+\t\t\t\tkeyNew (\"system/elektra/modules/csvstorage/exports/get\",\n+\t\t\t\t\tKEY_FUNC, elektraCsvstorageGet, KEY_END),\n+\t\t\t\tkeyNew (\"system/elektra/modules/csvstorage/exports/set\",\n+\t\t\t\t\tKEY_FUNC, elektraCsvstorageSet, KEY_END),\n+#include ELEKTRA_README(csvstorage)\n+\t\t\t\tkeyNew (\"system/elektra/modules/csvstorage/infos/version\",\n+\t\t\t\t\tKEY_VALUE, PLUGINVERSION, KEY_END),\n+\t\t\t\tKS_END);\n+\t\tksAppend (returned, contract);\n+\t\tksDel (contract);\n+\n+\t\treturn 1; /* success */\n+\t}\n+\t/* get all keys */\n+\tKeySet *config = elektraPluginGetConfig(handle);\n+\tKey *delimKey = ksLookupByName(config, \"/delimiter\", 0);\n+\tKey *readHeaderKey = ksLookupByName(config, \"/useheader\", 0);\n+\tKey *key;\n+\tKeySet *header = ksNew(0, KS_END);\n+\tKey *dirKey;\n+\tKey *cur;\n+\tFILE *fp = NULL;\n+\tchar *col;\n+\tchar buf[15];\n+\tint nr_keys = 1;\n+\t\n+\tchar delim = ';';\n+\tif(delimKey)\n+\t\tdelim = ((char *)keyString(delimKey))[0];\n+\t\n+\tuint8_t useHeader = 0;\n+\tif(readHeaderKey)\n+\t{\n+\t\tif((((char *)keyString(readHeaderKey))[0] - '0') == 1)\n+\t\t\tuseHeader = 1;\n+\t}\n+\tconst char *fileName;\n+\tfileName = keyString(parentKey);\n+\tfp = fopen(fileName, \"rb\");\n+\tif(!fp)\n+\t{\n+\t\tELEKTRA_SET_ERROR(116, parentKey, \"couldn't open file\");\n+\t\treturn -1;\n+\t}\n+\n+\tunsigned long length = 0;\n+\tlength = getLineLength(fp);\n+\tif(length == 0)\n+\t{\n+\t\tELEKTRA_ADD_WARNING(118, parentKey, \"Empty file\");\n+\t\tfclose(fp);\n+\t\treturn 1;\n+\t}\n+\n+\tchar *lineBuffer;\n+\tlineBuffer = malloc(length * sizeof(char)+1);","path":"src/plugins/csvstorage/csvstorage.c","position":150,"original_position":150,"commit_id":"84daebd198091fee46e701e19182dc31590ad4f9","original_commit_id":"84daebd198091fee46e701e19182dc31590ad4f9","user":{"login":"markus2330","id":7949075,"avatar_url":"https://avatars.githubusercontent.com/u/7949075?v=3","gravatar_id":"","url":"https://api.github.com/users/markus2330","html_url":"https://github.com/markus2330","followers_url":"https://api.github.com/users/markus2330/followers","following_url":"https://api.github.com/users/markus2330/following{/other_user}","gists_url":"https://api.github.com/users/markus2330/gists{/gist_id}","starred_url":"https://api.github.com/users/markus2330/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/markus2330/subscriptions","organizations_url":"https://api.github.com/users/markus2330/orgs","repos_url":"https://api.github.com/users/markus2330/repos","events_url":"https://api.github.com/users/markus2330/events{/privacy}","received_events_url":"https://api.github.com/users/markus2330/received_events","type":"User","site_admin":false},"body":"please use `elektraMalloc` instead of `malloc`. Its useful for profiling and memory allocation tests.","created_at":"2015-09-18T06:28:03Z","updated_at":"2015-09-18T06:28:03Z","html_url":"https://github.com/ElektraInitiative/libelektra/pull/298#discussion_r39827268","pull_request_url":"https://api.github.com/repos/ElektraInitiative/libelektra/pulls/298","_links":{"self":{"href":"https://api.github.com/repos/ElektraInitiative/libelektra/pulls/comments/39827268"},"html":{"href":"https://github.com/ElektraInitiative/libelektra/pull/298#discussion_r39827268"},"pull_request":{"href":"https://api.github.com/repos/ElektraInitiative/libelektra/pulls/298"}}},"pull_request":{"url":"https://api.github.com/repos/ElektraInitiative/libelektra/pulls/298","id":45352687,"html_url":"https://github.com/ElektraInitiative/libelektra/pull/298","diff_url":"https://github.com/ElektraInitiative/libelektra/pull/298.diff","patch_url":"https://github.com/ElektraInitiative/libelektra/pull/298.patch","issue_url":"https://api.github.com/repos/ElektraInitiative/libelektra/issues/298","number":298,"state":"open","locked":false,"title":"CSVStorage and Lineendings","user":{"login":"tom-wa","id":13944659,"avatar_url":"https://avatars.githubusercontent.com/u/13944659?v=3","gravatar_id":"","url":"https://api.github.com/users/tom-wa","html_url":"https://github.com/tom-wa","followers_url":"https://api.github.com/users/tom-wa/followers","following_url":"https://api.github.com/users/tom-wa/following{/other_user}","gists_url":"https://api.github.com/users/tom-wa/gists{/gist_id}","starred_url":"https://api.github.com/users/tom-wa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tom-wa/subscriptions","organizations_url":"https://api.github.com/users/tom-wa/orgs","repos_url":"https://api.github.com/users/tom-wa/repos","events_url":"https://api.github.com/users/tom-wa/events{/privacy}","received_events_url":"https://api.github.com/users/tom-wa/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-09-17T23:03:30Z","updated_at":"2015-09-18T06:28:03Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4e735621f04fb7527dd0e9762bb1a28e79a252de","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ElektraInitiative/libelektra/pulls/298/commits","review_comments_url":"https://api.github.com/repos/ElektraInitiative/libelektra/pulls/298/comments","review_comment_url":"https://api.github.com/repos/ElektraInitiative/libelektra/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ElektraInitiative/libelektra/issues/298/comments","statuses_url":"https://api.github.com/repos/ElektraInitiative/libelektra/statuses/84daebd198091fee46e701e19182dc31590ad4f9","head":{"label":"tom-wa:master","ref":"master","sha":"84daebd198091fee46e701e19182dc31590ad4f9","user":{"login":"tom-wa","id":13944659,"avatar_url":"https://avatars.githubusercontent.com/u/13944659?v=3","gravatar_id":"","url":"https://api.github.com/users/tom-wa","html_url":"https://github.com/tom-wa","followers_url":"https://api.github.com/users/tom-wa/followers","following_url":"https://api.github.com/users/tom-wa/following{/other_user}","gists_url":"https://api.github.com/users/tom-wa/gists{/gist_id}","starred_url":"https://api.github.com/users/tom-wa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tom-wa/subscriptions","organizations_url":"https://api.github.com/users/tom-wa/orgs","repos_url":"https://api.github.com/users/tom-wa/repos","events_url":"https://api.github.com/users/tom-wa/events{/privacy}","received_events_url":"https://api.github.com/users/tom-wa/received_events","type":"User","site_admin":false},"repo":{"id":42685319,"name":"libelektra","full_name":"tom-wa/libelektra","owner":{"login":"tom-wa","id":13944659,"avatar_url":"https://avatars.githubusercontent.com/u/13944659?v=3","gravatar_id":"","url":"https://api.github.com/users/tom-wa","html_url":"https://github.com/tom-wa","followers_url":"https://api.github.com/users/tom-wa/followers","following_url":"https://api.github.com/users/tom-wa/following{/other_user}","gists_url":"https://api.github.com/users/tom-wa/gists{/gist_id}","starred_url":"https://api.github.com/users/tom-wa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tom-wa/subscriptions","organizations_url":"https://api.github.com/users/tom-wa/orgs","repos_url":"https://api.github.com/users/tom-wa/repos","events_url":"https://api.github.com/users/tom-wa/events{/privacy}","received_events_url":"https://api.github.com/users/tom-wa/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/tom-wa/libelektra","description":"Elektra provides a universal and secure framework to store configuration parameters in a global, hierarchical key database.","fork":true,"url":"https://api.github.com/repos/tom-wa/libelektra","forks_url":"https://api.github.com/repos/tom-wa/libelektra/forks","keys_url":"https://api.github.com/repos/tom-wa/libelektra/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tom-wa/libelektra/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tom-wa/libelektra/teams","hooks_url":"https://api.github.com/repos/tom-wa/libelektra/hooks","issue_events_url":"https://api.github.com/repos/tom-wa/libelektra/issues/events{/number}","events_url":"https://api.github.com/repos/tom-wa/libelektra/events","assignees_url":"https://api.github.com/repos/tom-wa/libelektra/assignees{/user}","branches_url":"https://api.github.com/repos/tom-wa/libelektra/branches{/branch}","tags_url":"https://api.github.com/repos/tom-wa/libelektra/tags","blobs_url":"https://api.github.com/repos/tom-wa/libelektra/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tom-wa/libelektra/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tom-wa/libelektra/git/refs{/sha}","trees_url":"https://api.github.com/repos/tom-wa/libelektra/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tom-wa/libelektra/statuses/{sha}","languages_url":"https://api.github.com/repos/tom-wa/libelektra/languages","stargazers_url":"https://api.github.com/repos/tom-wa/libelektra/stargazers","contributors_url":"https://api.github.com/repos/tom-wa/libelektra/contributors","subscribers_url":"https://api.github.com/repos/tom-wa/libelektra/subscribers","subscription_url":"https://api.github.com/repos/tom-wa/libelektra/subscription","commits_url":"https://api.github.com/repos/tom-wa/libelektra/commits{/sha}","git_commits_url":"https://api.github.com/repos/tom-wa/libelektra/git/commits{/sha}","comments_url":"https://api.github.com/repos/tom-wa/libelektra/comments{/number}","issue_comment_url":"https://api.github.com/repos/tom-wa/libelektra/issues/comments{/number}","contents_url":"https://api.github.com/repos/tom-wa/libelektra/contents/{+path}","compare_url":"https://api.github.com/repos/tom-wa/libelektra/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tom-wa/libelektra/merges","archive_url":"https://api.github.com/repos/tom-wa/libelektra/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tom-wa/libelektra/downloads","issues_url":"https://api.github.com/repos/tom-wa/libelektra/issues{/number}","pulls_url":"https://api.github.com/repos/tom-wa/libelektra/pulls{/number}","milestones_url":"https://api.github.com/repos/tom-wa/libelektra/milestones{/number}","notifications_url":"https://api.github.com/repos/tom-wa/libelektra/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tom-wa/libelektra/labels{/name}","releases_url":"https://api.github.com/repos/tom-wa/libelektra/releases{/id}","created_at":"2015-09-17T22:27:25Z","updated_at":"2015-09-17T22:27:28Z","pushed_at":"2015-09-18T01:47:04Z","git_url":"git://github.com/tom-wa/libelektra.git","ssh_url":"git@github.com:tom-wa/libelektra.git","clone_url":"https://github.com/tom-wa/libelektra.git","svn_url":"https://github.com/tom-wa/libelektra","homepage":"","size":31436,"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":"ElektraInitiative:master","ref":"master","sha":"547d5ca7588f068196699e5f22770220b1ccbb7a","user":{"login":"ElektraInitiative","id":7949092,"avatar_url":"https://avatars.githubusercontent.com/u/7949092?v=3","gravatar_id":"","url":"https://api.github.com/users/ElektraInitiative","html_url":"https://github.com/ElektraInitiative","followers_url":"https://api.github.com/users/ElektraInitiative/followers","following_url":"https://api.github.com/users/ElektraInitiative/following{/other_user}","gists_url":"https://api.github.com/users/ElektraInitiative/gists{/gist_id}","starred_url":"https://api.github.com/users/ElektraInitiative/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ElektraInitiative/subscriptions","organizations_url":"https://api.github.com/users/ElektraInitiative/orgs","repos_url":"https://api.github.com/users/ElektraInitiative/repos","events_url":"https://api.github.com/users/ElektraInitiative/events{/privacy}","received_events_url":"https://api.github.com/users/ElektraInitiative/received_events","type":"Organization","site_admin":false},"repo":{"id":21063580,"name":"libelektra","full_name":"ElektraInitiative/libelektra","owner":{"login":"ElektraInitiative","id":7949092,"avatar_url":"https://avatars.githubusercontent.com/u/7949092?v=3","gravatar_id":"","url":"https://api.github.com/users/ElektraInitiative","html_url":"https://github.com/ElektraInitiative","followers_url":"https://api.github.com/users/ElektraInitiative/followers","following_url":"https://api.github.com/users/ElektraInitiative/following{/other_user}","gists_url":"https://api.github.com/users/ElektraInitiative/gists{/gist_id}","starred_url":"https://api.github.com/users/ElektraInitiative/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ElektraInitiative/subscriptions","organizations_url":"https://api.github.com/users/ElektraInitiative/orgs","repos_url":"https://api.github.com/users/ElektraInitiative/repos","events_url":"https://api.github.com/users/ElektraInitiative/events{/privacy}","received_events_url":"https://api.github.com/users/ElektraInitiative/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ElektraInitiative/libelektra","description":"Elektra provides a universal and secure framework to store configuration parameters in a global, hierarchical key database.","fork":false,"url":"https://api.github.com/repos/ElektraInitiative/libelektra","forks_url":"https://api.github.com/repos/ElektraInitiative/libelektra/forks","keys_url":"https://api.github.com/repos/ElektraInitiative/libelektra/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ElektraInitiative/libelektra/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ElektraInitiative/libelektra/teams","hooks_url":"https://api.github.com/repos/ElektraInitiative/libelektra/hooks","issue_events_url":"https://api.github.com/repos/ElektraInitiative/libelektra/issues/events{/number}","events_url":"https://api.github.com/repos/ElektraInitiative/libelektra/events","assignees_url":"https://api.github.com/repos/ElektraInitiative/libelektra/assignees{/user}","branches_url":"https://api.github.com/repos/ElektraInitiative/libelektra/branches{/branch}","tags_url":"https://api.github.com/repos/ElektraInitiative/libelektra/tags","blobs_url":"https://api.github.com/repos/ElektraInitiative/libelektra/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ElektraInitiative/libelektra/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ElektraInitiative/libelektra/git/refs{/sha}","trees_url":"https://api.github.com/repos/ElektraInitiative/libelektra/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ElektraInitiative/libelektra/statuses/{sha}","languages_url":"https://api.github.com/repos/ElektraInitiative/libelektra/languages","stargazers_url":"https://api.github.com/repos/ElektraInitiative/libelektra/stargazers","contributors_url":"https://api.github.com/repos/ElektraInitiative/libelektra/contributors","subscribers_url":"https://api.github.com/repos/ElektraInitiative/libelektra/subscribers","subscription_url":"https://api.github.com/repos/ElektraInitiative/libelektra/subscription","commits_url":"https://api.github.com/repos/ElektraInitiative/libelektra/commits{/sha}","git_commits_url":"https://api.github.com/repos/ElektraInitiative/libelektra/git/commits{/sha}","comments_url":"https://api.github.com/repos/ElektraInitiative/libelektra/comments{/number}","issue_comment_url":"https://api.github.com/repos/ElektraInitiative/libelektra/issues/comments{/number}","contents_url":"https://api.github.com/repos/ElektraInitiative/libelektra/contents/{+path}","compare_url":"https://api.github.com/repos/ElektraInitiative/libelektra/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ElektraInitiative/libelektra/merges","archive_url":"https://api.github.com/repos/ElektraInitiative/libelektra/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ElektraInitiative/libelektra/downloads","issues_url":"https://api.github.com/repos/ElektraInitiative/libelektra/issues{/number}","pulls_url":"https://api.github.com/repos/ElektraInitiative/libelektra/pulls{/number}","milestones_url":"https://api.github.com/repos/ElektraInitiative/libelektra/milestones{/number}","notifications_url":"https://api.github.com/repos/ElektraInitiative/libelektra/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ElektraInitiative/libelektra/labels{/name}","releases_url":"https://api.github.com/repos/ElektraInitiative/libelektra/releases{/id}","created_at":"2014-06-21T08:01:04Z","updated_at":"2015-08-30T22:05:09Z","pushed_at":"2015-09-18T01:47:05Z","git_url":"git://github.com/ElektraInitiative/libelektra.git","ssh_url":"git@github.com:ElektraInitiative/libelektra.git","clone_url":"https://github.com/ElektraInitiative/libelektra.git","svn_url":"https://github.com/ElektraInitiative/libelektra","homepage":"","size":31436,"stargazers_count":17,"watchers_count":17,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":15,"mirror_url":null,"open_issues_count":39,"forks":15,"open_issues":39,"watchers":17,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ElektraInitiative/libelektra/pulls/298"},"html":{"href":"https://github.com/ElektraInitiative/libelektra/pull/298"},"issue":{"href":"https://api.github.com/repos/ElektraInitiative/libelektra/issues/298"},"comments":{"href":"https://api.github.com/repos/ElektraInitiative/libelektra/issues/298/comments"},"review_comments":{"href":"https://api.github.com/repos/ElektraInitiative/libelektra/pulls/298/comments"},"review_comment":{"href":"https://api.github.com/repos/ElektraInitiative/libelektra/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ElektraInitiative/libelektra/pulls/298/commits"},"statuses":{"href":"https://api.github.com/repos/ElektraInitiative/libelektra/statuses/84daebd198091fee46e701e19182dc31590ad4f9"}}}}