{"action":"created","comment":{"url":"https://api.github.com/repos/pilight/pilight/pulls/comments/51499393","id":51499393,"diff_hunk":"@@ -1019,3 +1024,161 @@ int file_get_contents(char *file, char **content) {\n \tfclose(fp);\n \treturn 0;\n }\n+\n+int checkdnsrr(const char *domain, const char *type)\n+{\n+\tlogprintf(LOG_STACK, \"%s(%s,%s)\", __FUNCTION__, domain ? domain : \"(NULL)\", type ? type : \"(NULL)\");\n+\treturn 0;\t// NYI.\n+}\n+\n+#if defined(__FreeBSD__) || defined(_WIN32)\n+#define use_regexp 0\n+#else\n+#define use_regexp 1\n+#endif\n+\n+// Do NOT write the next as range A-Za-z0-9 because the string may be used without RE.\n+#define AtoZ_atoz_0to9 \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\"\n+#define white_spaces \" \\t\"\n+\n+// Next email_local_part_valid_chars is defined in a way that it can be used without RE\n+// and within [] of a posix extended regular expression. Therefore the dash comes first\n+// because at later position it would mean range (and it can't be escaped because\n+// a \\ inside [] is literal - this is different from perl RE).\n+#define email_local_part_valid_chars \"-\" AtoZ_atoz_0to9 \".!#$%&'*+\\\\/=?^_`{|}~\"\n+\n+#if use_regexp\n+// The RE to check email addr is compiled only once and used commonly.\n+\n+static regex_t check_email_common_RE = { 0 };\n+static const regex_t * volatile check_email_compiled_RE = NULL;\n+\n+static void check_email_free_RE() {\n+\tif(check_email_compiled_RE != NULL) {\t// protect against unexpected calls.\n+\t\tregfree(&check_email_common_RE);\n+\t\tcheck_email_compiled_RE = NULL;\n+\t}\n+}\n+#endif\n+\n+/**\n+ * Check if an email address is valid.\n+ * @param char* addr The email address to check. Leading+trailing white spaces are accepted.\n+ * @param bool allow_lists If true, addr is allowed to be a comma separated list of email addresses.\n+ * @param bool check_domain_can_mail If true, check if domain exists in DNS system and accepts email.\n+ * @return int Values < 0 indicate error. Values >= 0 indicate success.\n+ * Where -1: syntax error, -2: DNS check for a domain failed, -8: severe internal error.\n+ */\n+int check_email_addr(const char *addr, int allow_lists, int check_domain_can_mail) {\n+\tif(addr == NULL) {\n+\t\treturn -1;\n+\t}\n+#if use_regexp\n+\tconst regex_t *RE = NULL;\n+\tint reti = 0;\n+\n+\tstatic const char email_pattern[] =\n+\t\t\"^[\" email_local_part_valid_chars \"]+\"\n+\t\t\"@(\"\n+\t\t\t   \"([A-Za-z0-9][-A-Za-z0-9]*[A-Za-z0-9])\"\n+\t\t\t\"(\\\\.[A-Za-z0-9][-A-Za-z0-9]*[A-Za-z0-9])+\"\n+\t\t\"|\"\n+\t\t\t\"[0-9]{1,3}(\\\\.[0-9]{1,3}){1,3}\"\t// IPv4 addr\n+\t\t\")$\";\n+\n+\tif((RE = check_email_compiled_RE) == NULL) { // first check without lock.\n+\t\t// RE not compiled yet.\n+\t\tatomiclock();\n+\t\tif((RE = check_email_compiled_RE) == NULL) { // locked now, need to check again.\n+\t\t\treti = regcomp(&check_email_common_RE, email_pattern, REG_EXTENDED);\n+\t\t\tif(reti == REG_NOERROR) {\n+\t\t\t\tcheck_email_compiled_RE = RE = &check_email_common_RE;\n+\t\t\t\tatexit(check_email_free_RE);\n+\t\t\t} else {\n+\t\t\t\tchar errmsg[regerror(reti, &check_email_common_RE, NULL, 0)];\n+\t\t\t\tregerror(reti, &check_email_common_RE, errmsg, sizeof(errmsg));\n+\t\t\t\tregfree(&check_email_common_RE);\n+\t\t\t\tatomicunlock();\t// do not logprintf while locked.\n+\t\t\t\tlogprintf(LOG_ERR, \"could not compile regex pattern '%s' to check email addresses: %s\",\n+\t\t\t\t\t\temail_pattern, errmsg);\n+\t\t\t\treturn -1;\n+\t\t\t}\n+\t\t}\n+\t\tatomicunlock();\n+\t}\n+#else\n+\tstatic const char local_valid_chars[] = email_local_part_valid_chars;\n+\tstatic const char domain_valid_chars[] = AtoZ_atoz_0to9 \".-\"; // . and - are not allowed everywhere.\n+#endif\n+\n+\tchar _addr[strlen(addr)+1];\n+\tconst char *at = NULL, *domain_name = NULL;\n+\tchar *comma = NULL, *next_addr = NULL;\n+\n+\tnext_addr = strcpy(_addr, addr);\t// get a writable copy.\n+\twhile(next_addr != NULL) {","path":"libs/pilight/core/common.c","position":null,"original_position":108,"commit_id":"c541fde413276dc8116f44676d165830ba233524","original_commit_id":"fe2530a87f76ca460aa88fd48c38526051cc159f","user":{"login":"yablacky","id":16855814,"avatar_url":"https://avatars.githubusercontent.com/u/16855814?v=3","gravatar_id":"","url":"https://api.github.com/users/yablacky","html_url":"https://github.com/yablacky","followers_url":"https://api.github.com/users/yablacky/followers","following_url":"https://api.github.com/users/yablacky/following{/other_user}","gists_url":"https://api.github.com/users/yablacky/gists{/gist_id}","starred_url":"https://api.github.com/users/yablacky/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yablacky/subscriptions","organizations_url":"https://api.github.com/users/yablacky/orgs","repos_url":"https://api.github.com/users/yablacky/repos","events_url":"https://api.github.com/users/yablacky/events{/privacy}","received_events_url":"https://api.github.com/users/yablacky/received_events","type":"User","site_admin":false},"body":"I'm not convinced that explode() has benefits here; anyhow I changed the code to use explode().","created_at":"2016-02-01T23:32:30Z","updated_at":"2016-02-01T23:32:30Z","html_url":"https://github.com/pilight/pilight/pull/233#discussion_r51499393","pull_request_url":"https://api.github.com/repos/pilight/pilight/pulls/233","_links":{"self":{"href":"https://api.github.com/repos/pilight/pilight/pulls/comments/51499393"},"html":{"href":"https://github.com/pilight/pilight/pull/233#discussion_r51499393"},"pull_request":{"href":"https://api.github.com/repos/pilight/pilight/pulls/233"}}},"pull_request":{"url":"https://api.github.com/repos/pilight/pilight/pulls/233","id":57879276,"html_url":"https://github.com/pilight/pilight/pull/233","diff_url":"https://github.com/pilight/pilight/pull/233.diff","patch_url":"https://github.com/pilight/pilight/pull/233.patch","issue_url":"https://api.github.com/repos/pilight/pilight/issues/233","number":233,"state":"open","locked":false,"title":"Fix checking e-mail addresses; Added a common function to check them.","user":{"login":"yablacky","id":16855814,"avatar_url":"https://avatars.githubusercontent.com/u/16855814?v=3","gravatar_id":"","url":"https://api.github.com/users/yablacky","html_url":"https://github.com/yablacky","followers_url":"https://api.github.com/users/yablacky/followers","following_url":"https://api.github.com/users/yablacky/following{/other_user}","gists_url":"https://api.github.com/users/yablacky/gists{/gist_id}","starred_url":"https://api.github.com/users/yablacky/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yablacky/subscriptions","organizations_url":"https://api.github.com/users/yablacky/orgs","repos_url":"https://api.github.com/users/yablacky/repos","events_url":"https://api.github.com/users/yablacky/events{/privacy}","received_events_url":"https://api.github.com/users/yablacky/received_events","type":"User","site_admin":false},"body":"Previous check of e-email addresses was too strict.\r\nThis has been fixed, they are now checked more precise.\r\n\r\nImplemented a common function check_email_addr() that can optionally\r\nalso accept lists of e-mail addresses. The option to check e-mail\r\ndomain names against DNS is prepared but ignored in the moment.","created_at":"2016-02-01T18:25:39Z","updated_at":"2016-02-01T23:32:30Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7f24ef6c85d02bc640c8e06a7278604fa34e561c","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/pilight/pilight/pulls/233/commits","review_comments_url":"https://api.github.com/repos/pilight/pilight/pulls/233/comments","review_comment_url":"https://api.github.com/repos/pilight/pilight/pulls/comments{/number}","comments_url":"https://api.github.com/repos/pilight/pilight/issues/233/comments","statuses_url":"https://api.github.com/repos/pilight/pilight/statuses/c541fde413276dc8116f44676d165830ba233524","head":{"label":"yablacky:fix-email-check-and-add-common-check-fxn","ref":"fix-email-check-and-add-common-check-fxn","sha":"c541fde413276dc8116f44676d165830ba233524","user":{"login":"yablacky","id":16855814,"avatar_url":"https://avatars.githubusercontent.com/u/16855814?v=3","gravatar_id":"","url":"https://api.github.com/users/yablacky","html_url":"https://github.com/yablacky","followers_url":"https://api.github.com/users/yablacky/followers","following_url":"https://api.github.com/users/yablacky/following{/other_user}","gists_url":"https://api.github.com/users/yablacky/gists{/gist_id}","starred_url":"https://api.github.com/users/yablacky/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yablacky/subscriptions","organizations_url":"https://api.github.com/users/yablacky/orgs","repos_url":"https://api.github.com/users/yablacky/repos","events_url":"https://api.github.com/users/yablacky/events{/privacy}","received_events_url":"https://api.github.com/users/yablacky/received_events","type":"User","site_admin":false},"repo":{"id":50333514,"name":"pilight","full_name":"yablacky/pilight","owner":{"login":"yablacky","id":16855814,"avatar_url":"https://avatars.githubusercontent.com/u/16855814?v=3","gravatar_id":"","url":"https://api.github.com/users/yablacky","html_url":"https://github.com/yablacky","followers_url":"https://api.github.com/users/yablacky/followers","following_url":"https://api.github.com/users/yablacky/following{/other_user}","gists_url":"https://api.github.com/users/yablacky/gists{/gist_id}","starred_url":"https://api.github.com/users/yablacky/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yablacky/subscriptions","organizations_url":"https://api.github.com/users/yablacky/orgs","repos_url":"https://api.github.com/users/yablacky/repos","events_url":"https://api.github.com/users/yablacky/events{/privacy}","received_events_url":"https://api.github.com/users/yablacky/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/yablacky/pilight","description":"open source domotica solution","fork":true,"url":"https://api.github.com/repos/yablacky/pilight","forks_url":"https://api.github.com/repos/yablacky/pilight/forks","keys_url":"https://api.github.com/repos/yablacky/pilight/keys{/key_id}","collaborators_url":"https://api.github.com/repos/yablacky/pilight/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/yablacky/pilight/teams","hooks_url":"https://api.github.com/repos/yablacky/pilight/hooks","issue_events_url":"https://api.github.com/repos/yablacky/pilight/issues/events{/number}","events_url":"https://api.github.com/repos/yablacky/pilight/events","assignees_url":"https://api.github.com/repos/yablacky/pilight/assignees{/user}","branches_url":"https://api.github.com/repos/yablacky/pilight/branches{/branch}","tags_url":"https://api.github.com/repos/yablacky/pilight/tags","blobs_url":"https://api.github.com/repos/yablacky/pilight/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/yablacky/pilight/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/yablacky/pilight/git/refs{/sha}","trees_url":"https://api.github.com/repos/yablacky/pilight/git/trees{/sha}","statuses_url":"https://api.github.com/repos/yablacky/pilight/statuses/{sha}","languages_url":"https://api.github.com/repos/yablacky/pilight/languages","stargazers_url":"https://api.github.com/repos/yablacky/pilight/stargazers","contributors_url":"https://api.github.com/repos/yablacky/pilight/contributors","subscribers_url":"https://api.github.com/repos/yablacky/pilight/subscribers","subscription_url":"https://api.github.com/repos/yablacky/pilight/subscription","commits_url":"https://api.github.com/repos/yablacky/pilight/commits{/sha}","git_commits_url":"https://api.github.com/repos/yablacky/pilight/git/commits{/sha}","comments_url":"https://api.github.com/repos/yablacky/pilight/comments{/number}","issue_comment_url":"https://api.github.com/repos/yablacky/pilight/issues/comments{/number}","contents_url":"https://api.github.com/repos/yablacky/pilight/contents/{+path}","compare_url":"https://api.github.com/repos/yablacky/pilight/compare/{base}...{head}","merges_url":"https://api.github.com/repos/yablacky/pilight/merges","archive_url":"https://api.github.com/repos/yablacky/pilight/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/yablacky/pilight/downloads","issues_url":"https://api.github.com/repos/yablacky/pilight/issues{/number}","pulls_url":"https://api.github.com/repos/yablacky/pilight/pulls{/number}","milestones_url":"https://api.github.com/repos/yablacky/pilight/milestones{/number}","notifications_url":"https://api.github.com/repos/yablacky/pilight/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/yablacky/pilight/labels{/name}","releases_url":"https://api.github.com/repos/yablacky/pilight/releases{/id}","deployments_url":"https://api.github.com/repos/yablacky/pilight/deployments","created_at":"2016-01-25T07:22:38Z","updated_at":"2016-01-25T07:22:41Z","pushed_at":"2016-02-01T23:24:39Z","git_url":"git://github.com/yablacky/pilight.git","ssh_url":"git@github.com:yablacky/pilight.git","clone_url":"https://github.com/yablacky/pilight.git","svn_url":"https://github.com/yablacky/pilight","homepage":"www.pilight.org","size":10153,"stargazers_count":0,"watchers_count":0,"language":"C","has_issues":false,"has_downloads":true,"has_wiki":false,"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":"pilight:development","ref":"development","sha":"f4feb212a84af4c26fccb1bdd3fc6fbbc2b25560","user":{"login":"pilight","id":5197912,"avatar_url":"https://avatars.githubusercontent.com/u/5197912?v=3","gravatar_id":"","url":"https://api.github.com/users/pilight","html_url":"https://github.com/pilight","followers_url":"https://api.github.com/users/pilight/followers","following_url":"https://api.github.com/users/pilight/following{/other_user}","gists_url":"https://api.github.com/users/pilight/gists{/gist_id}","starred_url":"https://api.github.com/users/pilight/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pilight/subscriptions","organizations_url":"https://api.github.com/users/pilight/orgs","repos_url":"https://api.github.com/users/pilight/repos","events_url":"https://api.github.com/users/pilight/events{/privacy}","received_events_url":"https://api.github.com/users/pilight/received_events","type":"Organization","site_admin":false},"repo":{"id":5966572,"name":"pilight","full_name":"pilight/pilight","owner":{"login":"pilight","id":5197912,"avatar_url":"https://avatars.githubusercontent.com/u/5197912?v=3","gravatar_id":"","url":"https://api.github.com/users/pilight","html_url":"https://github.com/pilight","followers_url":"https://api.github.com/users/pilight/followers","following_url":"https://api.github.com/users/pilight/following{/other_user}","gists_url":"https://api.github.com/users/pilight/gists{/gist_id}","starred_url":"https://api.github.com/users/pilight/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pilight/subscriptions","organizations_url":"https://api.github.com/users/pilight/orgs","repos_url":"https://api.github.com/users/pilight/repos","events_url":"https://api.github.com/users/pilight/events{/privacy}","received_events_url":"https://api.github.com/users/pilight/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/pilight/pilight","description":"open source domotica solution","fork":false,"url":"https://api.github.com/repos/pilight/pilight","forks_url":"https://api.github.com/repos/pilight/pilight/forks","keys_url":"https://api.github.com/repos/pilight/pilight/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pilight/pilight/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pilight/pilight/teams","hooks_url":"https://api.github.com/repos/pilight/pilight/hooks","issue_events_url":"https://api.github.com/repos/pilight/pilight/issues/events{/number}","events_url":"https://api.github.com/repos/pilight/pilight/events","assignees_url":"https://api.github.com/repos/pilight/pilight/assignees{/user}","branches_url":"https://api.github.com/repos/pilight/pilight/branches{/branch}","tags_url":"https://api.github.com/repos/pilight/pilight/tags","blobs_url":"https://api.github.com/repos/pilight/pilight/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pilight/pilight/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pilight/pilight/git/refs{/sha}","trees_url":"https://api.github.com/repos/pilight/pilight/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pilight/pilight/statuses/{sha}","languages_url":"https://api.github.com/repos/pilight/pilight/languages","stargazers_url":"https://api.github.com/repos/pilight/pilight/stargazers","contributors_url":"https://api.github.com/repos/pilight/pilight/contributors","subscribers_url":"https://api.github.com/repos/pilight/pilight/subscribers","subscription_url":"https://api.github.com/repos/pilight/pilight/subscription","commits_url":"https://api.github.com/repos/pilight/pilight/commits{/sha}","git_commits_url":"https://api.github.com/repos/pilight/pilight/git/commits{/sha}","comments_url":"https://api.github.com/repos/pilight/pilight/comments{/number}","issue_comment_url":"https://api.github.com/repos/pilight/pilight/issues/comments{/number}","contents_url":"https://api.github.com/repos/pilight/pilight/contents/{+path}","compare_url":"https://api.github.com/repos/pilight/pilight/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pilight/pilight/merges","archive_url":"https://api.github.com/repos/pilight/pilight/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pilight/pilight/downloads","issues_url":"https://api.github.com/repos/pilight/pilight/issues{/number}","pulls_url":"https://api.github.com/repos/pilight/pilight/pulls{/number}","milestones_url":"https://api.github.com/repos/pilight/pilight/milestones{/number}","notifications_url":"https://api.github.com/repos/pilight/pilight/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pilight/pilight/labels{/name}","releases_url":"https://api.github.com/repos/pilight/pilight/releases{/id}","deployments_url":"https://api.github.com/repos/pilight/pilight/deployments","created_at":"2012-09-26T13:56:20Z","updated_at":"2016-01-19T05:54:10Z","pushed_at":"2016-02-01T23:24:40Z","git_url":"git://github.com/pilight/pilight.git","ssh_url":"git@github.com:pilight/pilight.git","clone_url":"https://github.com/pilight/pilight.git","svn_url":"https://github.com/pilight/pilight","homepage":"www.pilight.org","size":13540,"stargazers_count":156,"watchers_count":156,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":121,"mirror_url":null,"open_issues_count":22,"forks":121,"open_issues":22,"watchers":156,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/pilight/pilight/pulls/233"},"html":{"href":"https://github.com/pilight/pilight/pull/233"},"issue":{"href":"https://api.github.com/repos/pilight/pilight/issues/233"},"comments":{"href":"https://api.github.com/repos/pilight/pilight/issues/233/comments"},"review_comments":{"href":"https://api.github.com/repos/pilight/pilight/pulls/233/comments"},"review_comment":{"href":"https://api.github.com/repos/pilight/pilight/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/pilight/pilight/pulls/233/commits"},"statuses":{"href":"https://api.github.com/repos/pilight/pilight/statuses/c541fde413276dc8116f44676d165830ba233524"}}}}