]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: server: move parsing of keyword "id" to server.c
authorWilly Tarreau <w@1wt.eu>
Wed, 10 Oct 2012 15:51:05 +0000 (17:51 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 10 Oct 2012 15:51:05 +0000 (17:51 +0200)
This is the first keyword to be moved to server.c.

src/cfgparse.c
src/server.c

index 4e06f7e7149cf7ce59379c94b7e739b1bdfdd7ad..84988a66f39a74566d64eaff7d3f34fe94656ebb 100644 (file)
@@ -4028,38 +4028,7 @@ stats_error_parsing:
                }
 
                while (*args[cur_arg]) {
-                       if (!defsrv && !strcmp(args[cur_arg], "id")) {
-                               struct eb32_node *node;
-
-                               if (!*args[cur_arg + 1]) {
-                                       Alert("parsing [%s:%d]: '%s' expects an integer argument.\n",
-                                               file, linenum, args[cur_arg]);
-                                       err_code |= ERR_ALERT | ERR_FATAL;
-                                       goto out;
-                               }
-
-                               newsrv->puid = atol(args[cur_arg + 1]);
-                               newsrv->conf.id.key = newsrv->puid;
-
-                               if (newsrv->puid <= 0) {
-                                       Alert("parsing [%s:%d]: custom id has to be > 0.\n",
-                                               file, linenum);
-                                       err_code |= ERR_ALERT | ERR_FATAL;
-                                       goto out;
-                               }
-
-                               node = eb32_lookup(&curproxy->conf.used_server_id, newsrv->puid);
-                               if (node) {
-                                       struct server *target = container_of(node, struct server, conf.id);
-                                       Alert("parsing [%s:%d]: server %s reuses same custom id as server %s (declared at %s:%d).\n",
-                                             file, linenum, newsrv->id, target->id, target->conf.file, target->conf.line);
-                                       err_code |= ERR_ALERT | ERR_FATAL;
-                                       goto out;
-                               }
-                               eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id);
-                               cur_arg += 2;
-                       }
-                       else if (!defsrv && !strcmp(args[cur_arg], "cookie")) {
+                       if (!defsrv && !strcmp(args[cur_arg], "cookie")) {
                                newsrv->cookie = strdup(args[cur_arg + 1]);
                                newsrv->cklen = strlen(args[cur_arg + 1]);
                                cur_arg += 2;
index ae46af5d244c767a00e5cda6b4e353a37e8be62b..568d042206d8208dbdd2139d9e21543281cb4c13 100644 (file)
@@ -12,6 +12,7 @@
  */
 
 #include <common/config.h>
+#include <common/errors.h>
 #include <common/time.h>
 
 #include <proto/server.h>
@@ -106,6 +107,55 @@ void srv_dump_kws(char **out)
        }
 }
 
+/* parse the "id" server keyword */
+static int srv_parse_id(char **args, int *cur_arg, struct proxy *curproxy, struct server *newsrv, char **err)
+{
+       struct eb32_node *node;
+
+       if (!*args[*cur_arg + 1]) {
+               memprintf(err, "'%s' : expects an integer argument", args[*cur_arg]);
+               return ERR_ALERT | ERR_FATAL;
+       }
+
+       newsrv->puid = atol(args[*cur_arg + 1]);
+       newsrv->conf.id.key = newsrv->puid;
+
+       if (newsrv->puid <= 0) {
+               memprintf(err, "'%s' : custom id has to be > 0", args[*cur_arg]);
+               return ERR_ALERT | ERR_FATAL;
+       }
+
+       node = eb32_lookup(&curproxy->conf.used_server_id, newsrv->puid);
+       if (node) {
+               struct server *target = container_of(node, struct server, conf.id);
+               memprintf(err, "'%s' : custom id %d already used at %s:%d ('server %s')",
+                         args[*cur_arg], newsrv->puid, target->conf.file, target->conf.line,
+                         target->id);
+               return ERR_ALERT | ERR_FATAL;
+       }
+
+       eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id);
+       return 0;
+}
+
+/* Note: must not be declared <const> as its list will be overwritten.
+ * Please take care of keeping this list alphabetically sorted, doing so helps
+ * all code contributors.
+ * Optional keywords are also declared with a NULL ->parse() function so that
+ * the config parser can report an appropriate error when a known keyword was
+ * not enabled.
+ */
+static struct srv_kw_list srv_kws = { "ALL", { }, {
+       { "id",           srv_parse_id,           1,  0 }, /* set id# of server */
+       { NULL, NULL, 0 },
+}};
+
+__attribute__((constructor))
+static void __listener_init(void)
+{
+       srv_register_keywords(&srv_kws);
+}
+
 /*
  * Local variables:
  *  c-indent-level: 8