summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormrb0nk500 <b0nk@b0nk.xyz>2022-08-05 21:43:47 -0300
committermrb0nk500 <b0nk@b0nk.xyz>2022-08-05 21:49:29 -0300
commit2898adab6fde190d09f87cac58862c67ee193559 (patch)
tree7e0575564952a14c07a747e8968aa7a490713844
parent16f20cd4834c6a004246a80ca18033ca80224b56 (diff)
keyword: Add `get_keyword_cb`, and add `get_callback` to `struct keyword`
This will be used for creating a getter callback for keywords. I also renamed `keyword_cb` to `set_keyword_cb`, aswell as renamed `callback` to `set_callback` in `struct keyword`.
-rw-r--r--config.h14
-rw-r--r--git.h29
-rw-r--r--keyword.c2
-rw-r--r--keyword.h16
4 files changed, 34 insertions, 27 deletions
diff --git a/config.h b/config.h
index 4d35af6..7380061 100644
--- a/config.h
+++ b/config.h
@@ -20,13 +20,13 @@ int check_port(void *ctx, void *ret, const keyword *key, keyword_val val);
#define offset_list(...) (size_t []){__VA_ARGS__, -1}
static const keyword *config_keywords[] = {
- &(const keyword){"git-root", "Root of git server (can also be a url).", NULL, TYPE_STRING, offset_list(offsetof(config, git_root)), NULL},
- &(const keyword){"socket-type", "Socket type to use (options: unix, network. default: network).", NULL, TYPE_STRING, offset_list(offsetof(config, sock_type)), NULL},
- &(const keyword){"socket", "Path, IP address, or domain name of socket.", NULL, TYPE_STRING, offset_list(offsetof(config, sock)), NULL},
- &(const keyword){"port", "Port to listen on (network socket only).", NULL, TYPE_STRING, offset_list(offsetof(config, port)), check_port},
- &(const keyword){"merge-type", "Type of merge (options: 0 = Merge individually, 1 = Merge into one).", NULL, TYPE_INT, offset_list(offsetof(config, merge_type)), NULL},
- &(const keyword){"pr-root", "Directory to store pull requests in.", NULL, TYPE_STRING, offset_list(offsetof(config, pr_root)), NULL},
- &(const keyword){"key-file", "Path to file containing gpg/pgp public keys of each maintainer.", NULL, TYPE_STRING, offset_list(offsetof(config, key_path)), NULL},
+ &(const keyword){"git-root", "Root of git server (can also be a url).", NULL, TYPE_STRING, offset_list(offsetof(config, git_root)), NULL, NULL},
+ &(const keyword){"socket-type", "Socket type to use (options: unix, network. default: network).", NULL, TYPE_STRING, offset_list(offsetof(config, sock_type)), NULL, NULL},
+ &(const keyword){"socket", "Path, IP address, or domain name of socket.", NULL, TYPE_STRING, offset_list(offsetof(config, sock)), NULL, NULL},
+ &(const keyword){"port", "Port to listen on (network socket only).", NULL, TYPE_STRING, offset_list(offsetof(config, port)), check_port, NULL},
+ &(const keyword){"merge-type", "Type of merge (options: 0 = Merge individually, 1 = Merge into one).", NULL, TYPE_INT, offset_list(offsetof(config, merge_type)), NULL, NULL},
+ &(const keyword){"pr-root", "Directory to store pull requests in.", NULL, TYPE_STRING, offset_list(offsetof(config, pr_root)), NULL, NULL},
+ &(const keyword){"key-file", "Path to file containing gpg/pgp public keys of each maintainer.", NULL, TYPE_STRING, offset_list(offsetof(config, key_path)), NULL, NULL},
NULL,
};
#undef offset_list
diff --git a/git.h b/git.h
index e2c6776..80cdc92 100644
--- a/git.h
+++ b/git.h
@@ -63,16 +63,21 @@ int parse_remote_branch(void *ctx, void *ret, const keyword *key, keyword_val va
int parse_patch_list(void *ctx, void *ret, const keyword *key, keyword_val val);
int parse_comment_reply(void *ctx, void *ret, const keyword *key, keyword_val val);
+
+int has_remote_branch(void *ctx, void *ret, const keyword *key, keyword_val *val);
+int get_patch_list(void *ctx, void *data, const keyword *key, keyword_val *val);
+int get_comment_reply(void *ctx, void *data, const keyword *key, keyword_val *val);
+
#define offset_list(...) (size_t []){__VA_ARGS__, -1}
static const keyword *info_keywords[] = {
- &(const keyword){"title", "Title of Pull Request.", NULL, TYPE_STRING, offset_list(offsetof(pull_request, title)), NULL},
- &(const keyword){"author", "Author of Pull Request.", NULL, TYPE_STRING, offset_list(offsetof(pull_request, author)), NULL},
- &(const keyword){"date", "Date of Pull Request's creation.", "%a %b %e %H:%M:%S %Y %z", TYPE_TIME, offset_list(offsetof(pull_request, date)), NULL},
- &(const keyword){"description", "Description of Pull Request.", NULL, TYPE_STRING, offset_list(offsetof(pull_request, desc)), NULL},
- &(const keyword){"type", "Type of Pull Request (0 = patch files, 1 = remote repo).", NULL, TYPE_INT, offset_list(offsetof(pull_request, pr_type)), NULL},
- &(const keyword){"branch", "Branch of remote repo.", NULL, TYPE_STRING, offset_list(offsetof(pull_request, branch), offsetof(git_branch, name)), parse_remote_branch},
- &(const keyword){"repo", "URL of remote repo.", NULL, TYPE_STRING, offset_list(offsetof(pull_request, branch), offsetof(git_branch, repo)), parse_remote_branch},
- &(const keyword){"patches", "Patch file(s) of Pull Request.", NULL, TYPE_STRING, offset_list(offsetof(pull_request, patches), offsetof(file, name)), parse_patch_list},
+ &(const keyword){"title", "Title of Pull Request.", NULL, TYPE_STRING, offset_list(offsetof(pull_request, title)), NULL, NULL},
+ &(const keyword){"author", "Author of Pull Request.", NULL, TYPE_STRING, offset_list(offsetof(pull_request, author)), NULL, NULL},
+ &(const keyword){"date", "Date of Pull Request's creation.", "%a %b %e %H:%M:%S %Y %z", TYPE_TIME, offset_list(offsetof(pull_request, date)), NULL, NULL},
+ &(const keyword){"description", "Description of Pull Request.", NULL, TYPE_STRING, offset_list(offsetof(pull_request, desc)), NULL, NULL},
+ &(const keyword){"type", "Type of Pull Request (0 = patch files, 1 = remote repo).", NULL, TYPE_INT, offset_list(offsetof(pull_request, pr_type)), NULL, NULL},
+ &(const keyword){"branch", "Branch of remote repo.", NULL, TYPE_STRING, offset_list(offsetof(pull_request, branch), offsetof(git_branch, name)), parse_remote_branch, has_remote_branch},
+ &(const keyword){"repo", "URL of remote repo.", NULL, TYPE_STRING, offset_list(offsetof(pull_request, branch), offsetof(git_branch, repo)), parse_remote_branch, has_remote_branch},
+ &(const keyword){"patches", "Patch file(s) of Pull Request.", NULL, TYPE_STRING, offset_list(offsetof(pull_request, patches), offsetof(file, name)), parse_patch_list, get_patch_list},
&(const keyword){"merge-branch", "Branch to merge Pull Request with.", NULL, TYPE_STRING, offset_list(offsetof(pull_request, merge_branch)), NULL},
NULL,
};
@@ -81,10 +86,10 @@ static const keyword *comment_keywords[] = {
&(const keyword){"id", "ID of Comment.", NULL, TYPE_INT, offset_list(offsetof(comment, id)), NULL},
&(const keyword){"author", "Author of Comment.", NULL, TYPE_STRING, offset_list(offsetof(comment, author)), NULL},
&(const keyword){"date", "Date of Comment's creation.", "%a %b %e %H:%M:%S %Y %z", TYPE_TIME, offset_list(offsetof(comment, date)), NULL},
- &(const keyword){"reply-to", "ID of replied Comment.", NULL, TYPE_INT, offset_list(offsetof(comment, reply), offsetof(comment, id)), parse_comment_reply},
- &(const keyword){"reply-author", "Author of replied Comment.", NULL, TYPE_STRING, offset_list(offsetof(comment, reply), offsetof(comment, author)), parse_comment_reply},
- &(const keyword){"reply-date", "Date of replied Comment's creation", "%a %b %e %H:%M:%S %Y %z", TYPE_TIME, offset_list(offsetof(comment, reply), offsetof(comment, date)), parse_comment_reply},
- &(const keyword){"description", "Message of Comment.", NULL, TYPE_STRING, offset_list(offsetof(comment, desc)), NULL},
+ &(const keyword){"reply-to", "ID of replied Comment.", NULL, TYPE_INT, offset_list(offsetof(comment, reply), offsetof(comment, id)), parse_comment_reply, get_comment_reply},
+ &(const keyword){"reply-author", "Author of replied Comment.", NULL, TYPE_STRING, offset_list(offsetof(comment, reply), offsetof(comment, author)), parse_comment_reply, get_comment_reply},
+ &(const keyword){"reply-date", "Date of replied Comment's creation", "%a %b %e %H:%M:%S %Y %z", TYPE_TIME, offset_list(offsetof(comment, reply), offsetof(comment, date)), parse_comment_reply, get_comment_reply},
+ &(const keyword){"description", "Message of Comment.", NULL, TYPE_STRING, offset_list(offsetof(comment, desc)), NULL, NULL},
NULL,
};
#undef offset_list
diff --git a/keyword.c b/keyword.c
index 16db0a2..24db8d9 100644
--- a/keyword.c
+++ b/keyword.c
@@ -46,7 +46,7 @@ keyword_val get_keyword_value(const keyword *key, char *value, int *error) {
}
int set_keyword(const keyword *key, keyword_val val, void *ret, void *ctx) {
- const int callback_ret = (key->callback != NULL) ? key->callback(ctx, ret, key, val) : 0;
+ const int callback_ret = (key->set_callback != NULL) ? key->set_callback(ctx, ret, key, val) : 0;
if (callback_ret < 0 || callback_ret > 0) {
return (callback_ret > 0) ? 0 : 5;
} else {
diff --git a/keyword.h b/keyword.h
index 5fccbc4..c39f13c 100644
--- a/keyword.h
+++ b/keyword.h
@@ -6,7 +6,8 @@
typedef enum keyword_type keyword_type;
typedef struct keyword keyword;
typedef union keyword_val keyword_val;
-typedef int (keyword_cb)(void *ctx, void *ret, const keyword *key, keyword_val val);
+typedef int (set_keyword_cb)(void *ctx, void *ret, const keyword *key, keyword_val val);
+typedef int (get_keyword_cb)(void *ctx, void *data, const keyword *key, keyword_val *val);
typedef int (parse_callback)(void **ret, void *ctx, char *buf);
enum keyword_type {
@@ -20,12 +21,13 @@ enum keyword_type {
};
struct keyword {
- const char *key; /* Keyword. */
- const char *desc; /* Description of the keyword. */
- const char *time_fmt; /* Format string used to parse a timestamp (if needed). */
- keyword_type type; /* Datatype of the keyword. */
- size_t *offsets; /* Offset(s) of member(s) in a struct (if needed). */
- keyword_cb *callback; /* Callback to keyword specific parsing function (if needed). */
+ const char *key; /* Keyword. */
+ const char *desc; /* Description of the keyword. */
+ const char *time_fmt; /* Format string used to parse a timestamp (if needed). */
+ keyword_type type; /* Datatype of the keyword. */
+ size_t *offsets; /* Offset(s) of member(s) in a struct (if needed). */
+ set_keyword_cb *set_callback; /* Callback to keyword specific setter function (if needed). */
+ get_keyword_cb *get_callback; /* Callback to keyword specific getter function (if needed). */
};
union keyword_val {