From 373b89e70cdbaa906d55f8ba571b6cd05bbba8c5 Mon Sep 17 00:00:00 2001 From: Unbit Date: Tue, 17 Sep 2013 16:03:40 +0200 Subject: [PATCH] finally removed strtok() --- buildconf/all.ini | 2 +- core/uwsgi.c | 31 ++++++++++++++++--------------- plugins/carbon/carbon.c | 5 ++--- plugins/cgi/cgi_plugin.c | 5 ++--- plugins/gccgo/gccgo_plugin.c | 10 ++++------ plugins/glusterfs/glusterfs.c | 5 ++--- plugins/ldap/ldap.c | 10 ++++------ plugins/msgpack/msgpack.c | 5 ++--- plugins/python/pyutils.c | 10 ++++++---- plugins/rpc/rpc_plugin.c | 12 ++++++------ plugins/webdav/webdav.c | 5 ++--- 11 files changed, 47 insertions(+), 53 deletions(-) diff --git a/buildconf/all.ini b/buildconf/all.ini index 55a9d891..ad269d99 100644 --- a/buildconf/all.ini +++ b/buildconf/all.ini @@ -1,3 +1,3 @@ [uwsgi] -main_plugin = python,gevent,psgi,lua,php,rack,jvm,jwsgi,ring,mono,transformation_toupper,coroae,v8,cgi,xslt,webdav,ssi,ldap +main_plugin = python,gevent,psgi,lua,php,rack,jvm,jwsgi,ring,mono,transformation_toupper,coroae,v8,cgi,xslt,webdav,ssi,ldap,gccgo,rados inherit = base diff --git a/core/uwsgi.c b/core/uwsgi.c index 726ee3a3..ab888081 100644 --- a/core/uwsgi.c +++ b/core/uwsgi.c @@ -200,7 +200,7 @@ static struct uwsgi_option uwsgi_base_options[] = { {"imperial-monitor-list", no_argument, 0, "list enabled imperial monitors", uwsgi_opt_true, &uwsgi.imperial_monitor_list, 0}, {"imperial-monitors-list", no_argument, 0, "list enabled imperial monitors", uwsgi_opt_true, &uwsgi.imperial_monitor_list, 0}, {"vassals-inherit", required_argument, 0, "add config templates to vassals config (uses --inherit)", uwsgi_opt_add_string_list, &uwsgi.vassals_templates, 0}, - {"vassals-include", required_argument, 0, "inclue config templates to vassals config (uses --include instead of --inherit)", uwsgi_opt_add_string_list, &uwsgi.vassals_includes, 0}, + {"vassals-include", required_argument, 0, "include config templates to vassals config (uses --include instead of --inherit)", uwsgi_opt_add_string_list, &uwsgi.vassals_includes, 0}, {"vassals-start-hook", required_argument, 0, "run the specified command before each vassal starts", uwsgi_opt_set_str, &uwsgi.vassals_start_hook, 0}, {"vassals-stop-hook", required_argument, 0, "run the specified command after vassal's death", uwsgi_opt_set_str, &uwsgi.vassals_stop_hook, 0}, {"vassal-sos-backlog", required_argument, 0, "ask emperor for sos if backlog queue has more items than the value specified", uwsgi_opt_set_int, &uwsgi.vassal_sos_backlog, 0}, @@ -920,8 +920,8 @@ int uwsgi_manage_custom_option(struct uwsgi_custom_option *uco, char *key, char // now make a copy of the option template char *tmp_opt = uwsgi_str(uco->value); // split it - p = strtok(tmp_opt, ";"); - while (p) { + char *ctx = NULL; + uwsgi_foreach_token(tmp_opt, ";", p, ctx) { char *equal = strchr(p, '='); if (!equal) goto clear; @@ -954,7 +954,6 @@ int uwsgi_manage_custom_option(struct uwsgi_custom_option *uco, char *key, char } // we can ignore its return value (void) uwsgi_manage_opt(new_key, new_value); - p = strtok(NULL, ";"); } clear: @@ -1065,11 +1064,15 @@ void config_magic_table_fill(char *filename, char **magic_table) { int base = '0'; char *to_split = uwsgi_str(magic_table['d']); - char *p = strtok(to_split, "/"); - while (p && base <= '9') { - magic_table[base] = p; - base++; - p = strtok(NULL, "/"); + char *p, *ctx = NULL; + uwsgi_foreach_token(to_split, "/", p, ctx) { + if (base <= '9') { + magic_table[base] = p; + base++; + } + else { + break; + } } if (tmp) @@ -3247,8 +3250,8 @@ void uwsgi_worker_run() { // eventually remap plugins if (uwsgi.remap_modifier) { - char *map = strtok(uwsgi.remap_modifier, ","); - while (map != NULL) { + char *map, *ctx = NULL; + uwsgi_foreach_token(uwsgi.remap_modifier, ",", map, ctx) { char *colon = strchr(map, ':'); if (colon) { colon[0] = 0; @@ -3257,7 +3260,6 @@ void uwsgi_worker_run() { uwsgi.p[rm_dst]->request = uwsgi.p[rm_src]->request; uwsgi.p[rm_dst]->after_request = uwsgi.p[rm_src]->after_request; } - map = strtok(NULL, ","); } } @@ -4031,8 +4033,8 @@ void uwsgi_opt_load_dl(char *opt, char *value, void *none) { void uwsgi_opt_load_plugin(char *opt, char *value, void *none) { char *plugins_list = uwsgi_concat2(value, ""); - char *p = strtok(plugins_list, ","); - while (p != NULL) { + char *p, *ctx = NULL; + uwsgi_foreach_token(plugins_list, ",", p, ctx) { #ifdef UWSGI_DEBUG uwsgi_debug("loading plugin %s\n", p); #endif @@ -4043,7 +4045,6 @@ void uwsgi_opt_load_plugin(char *opt, char *value, void *none) { uwsgi_log("unable to load plugin \"%s\"\n", p); exit(1); } - p = strtok(NULL, ","); } free(p); free(plugins_list); diff --git a/plugins/carbon/carbon.c b/plugins/carbon/carbon.c index 79f237d8..670b61cd 100644 --- a/plugins/carbon/carbon.c +++ b/plugins/carbon/carbon.c @@ -71,8 +71,8 @@ static void carbon_post_init() { u_server->healthy = 1; u_server->errors = 0; - char *p = strtok(usl->value, ":"); - while (p) { + char *p, *ctx = NULL; + uwsgi_foreach_token(usl->value, ":", p, ctx) { if (!u_server->hostname) { u_server->hostname = uwsgi_str(p); } @@ -81,7 +81,6 @@ static void carbon_post_init() { } else break; - p = strtok(NULL, ":"); } if (!u_server->hostname || !u_server->port) { uwsgi_log("[carbon] invalid carbon server address (%s)\n", usl->value); diff --git a/plugins/cgi/cgi_plugin.c b/plugins/cgi/cgi_plugin.c index e6ec7c7c..5bc1c54f 100644 --- a/plugins/cgi/cgi_plugin.c +++ b/plugins/cgi/cgi_plugin.c @@ -828,8 +828,8 @@ clear2: // set the start position of args in argv i = 1; if (helper) i = 2; - char *p = strtok(qs, "+"); - while(p) { + char *p, *ctx = NULL; + uwsgi_foreach_token(qs, "+", p, ctx) { // create a copy for the url_decoded string char *arg_copy = uwsgi_str(p); uint16_t arg_copy_len = strlen(p); @@ -838,7 +838,6 @@ clear2: argv[i] = uwsgi_malloc( (arg_copy_len * 2) +1); escape_shell_arg(arg_copy, arg_copy_len, argv[i]); i++; - p = strtok(NULL, "+"); } free(qs); } diff --git a/plugins/gccgo/gccgo_plugin.c b/plugins/gccgo/gccgo_plugin.c index ea2c317e..87903160 100644 --- a/plugins/gccgo/gccgo_plugin.c +++ b/plugins/gccgo/gccgo_plugin.c @@ -123,10 +123,9 @@ static void uwsgi_gccgo_initialize() { int argc = 0; if (ugccgo.args) { char *argv_list = uwsgi_str(ugccgo.args); - char *p = strtok(argv_list, " "); - while(p) { + char *p, *ctx = NULL; + uwsgi_foreach_token(argv_list, " ", p, ctx) { argc++; - p = strtok(NULL, " "); } free(argv_list); } @@ -134,12 +133,11 @@ static void uwsgi_gccgo_initialize() { if (argc > 0) { char **argv = uwsgi_calloc(sizeof(char *) * (argc + 1)); char *argv_list = uwsgi_str(ugccgo.args); - char *p = strtok(argv_list, " "); + char *p, *ctx = NULL; int n = 0; - while(p) { + uwsgi_foreach_token(argv_list, " ", p, ctx) { argv[n] = p; n++; - p = strtok(NULL, " "); } runtime_args(argc, argv); } diff --git a/plugins/glusterfs/glusterfs.c b/plugins/glusterfs/glusterfs.c index 02f92f2e..248b62d7 100644 --- a/plugins/glusterfs/glusterfs.c +++ b/plugins/glusterfs/glusterfs.c @@ -117,13 +117,12 @@ connect: static void uwsgi_glusterfs_connect_do(struct uwsgi_app *ua) { char *servers = uwsgi_str(ua->callable); - char *p = strtok(servers, ";"); - while(p) { + char *p, *ctx = NULL; + uwsgi_foreach_token(servers, ";", p, ctx) { uwsgi_log("[glusterfs] try connect to %s for mountpoint %.*s on worker %d ...\n", p, ua->mountpoint_len, ua->mountpoint, uwsgi.mywid); if (uwsgi_glusterfs_try(ua, p)) { goto end; } - p = strtok(NULL, ";"); } end: free(servers); diff --git a/plugins/ldap/ldap.c b/plugins/ldap/ldap.c index 174ec1fc..fb9ba6e1 100644 --- a/plugins/ldap/ldap.c +++ b/plugins/ldap/ldap.c @@ -181,10 +181,9 @@ static void uwsgi_opt_ldap_dump_ldif(char *opt, char *foo, void *bar) { entry = &ule[i]; char *list2 = uwsgi_concat2(entry->names + 1, ""); - char *p = strtok(list2, " "); - while (p != NULL) { + char *p, *ctx = NULL; + uwsgi_foreach_token(list2, " ", p, ctx) { uwsgi_log("%.*s $ ", strlen(p) - 2, p + 1); - p = strtok(NULL, " "); } free(list2); @@ -228,10 +227,9 @@ static void uwsgi_opt_ldap_dump(char *opt, char *foo, void *bar) { entry = &ule[i]; char *list2 = uwsgi_concat2(entry->names + 1, ""); - char *p = strtok(list2, " "); - while (p != NULL) { + char *p, *ctx = NULL; + uwsgi_foreach_token(list2, " ", p, ctx) { uwsgi_log("%.*s $ ", strlen(p) - 2, p + 1); - p = strtok(NULL, " "); } free(list2); diff --git a/plugins/msgpack/msgpack.c b/plugins/msgpack/msgpack.c index b86fae9d..e0e080a6 100644 --- a/plugins/msgpack/msgpack.c +++ b/plugins/msgpack/msgpack.c @@ -164,8 +164,8 @@ int uwsgi_buffer_msgpack_false(struct uwsgi_buffer *ub) { static char *uwsgi_msgpack_log_encoder(struct uwsgi_log_encoder *ule, char *msg, size_t len, size_t *rlen) { char *buf = NULL; if (!ule->configured) { - char *p = strtok(ule->args, "|"); - while(p) { + char *p, *ctx = NULL; + uwsgi_foreach_token(ule->args, "|", p, ctx) { char *colon = strchr(p, ':'); if (colon) *colon = 0; // find the type of item @@ -259,7 +259,6 @@ static char *uwsgi_msgpack_log_encoder(struct uwsgi_log_encoder *ule, char *msg, } if (colon) *colon = ':'; - p = strtok(NULL, "|"); } ule->configured = 1; } diff --git a/plugins/python/pyutils.c b/plugins/python/pyutils.c index 4426c592..f4b1ef3d 100644 --- a/plugins/python/pyutils.c +++ b/plugins/python/pyutils.c @@ -320,8 +320,9 @@ void init_pyargv() { char *tmp_ptr = uwsgi_str(up.argv); #ifdef __sun__ // FIX THIS !!! - ap = strtok(tmp_ptr, " "); - while ((ap = strtok(NULL, " ")) != NULL) { + char *ctx = NULL; + ap = strtok_r(tmp_ptr, " ", &ctx); + while ((ap = strtok_r(NULL, " ", &ctx)) != NULL) { #else while ((ap = strsep(&tmp_ptr, " \t")) != NULL) { #endif @@ -352,8 +353,9 @@ void init_pyargv() { #ifdef __sun__ // FIX THIS !!! - ap = strtok(py_argv_copy, " "); - while ((ap = strtok(NULL, " ")) != NULL) { + char *ctx = NULL; + ap = strtok_r(py_argv_copy, " ", &ctx); + while ((ap = strtok_r(NULL, " ", &ctx)) != NULL) { #else while ((ap = strsep(&py_argv_copy, " \t")) != NULL) { #endif diff --git a/plugins/rpc/rpc_plugin.c b/plugins/rpc/rpc_plugin.c index 09e5575a..35f8a8da 100644 --- a/plugins/rpc/rpc_plugin.c +++ b/plugins/rpc/rpc_plugin.c @@ -158,18 +158,19 @@ static int uwsgi_rpc_request(struct wsgi_request *wsgi_req) { } argc = 0; - argv[0] = strtok(args, "/"); + char *ctx = NULL; + argv[0] = strtok_r(args, "/", &ctx); if (!argv[0]) { free(args); uwsgi_500(wsgi_req); return UWSGI_OK; } - char *p = strtok(NULL, "/"); + char *p = strtok_r(NULL, "/", &ctx); while(p) { argc++; argv[argc] = p; argvs[argc] = strlen(p); - p = strtok(NULL, "/"); + p = strtok_r(NULL, "/", &ctx); } wsgi_req->uh->pktsize = uwsgi_rpc(argv[0], argc, argv+1, argvs+1, response_buf); @@ -558,8 +559,8 @@ static int uwsgi_router_rpc_base(struct uwsgi_route *ur, char *args) { ur->custom = 0; ur->data2 = uwsgi_calloc(sizeof(char *) * UMAX8); ur->data3 = uwsgi_calloc(sizeof(uint16_t) * UMAX8); - char *p = strtok(args, " "); - while(p) { + char *p, *ctx = NULL; + uwsgi_foreach_token(args, " ", p, ctx) { if (!ur->data) { ur->data = p; } @@ -576,7 +577,6 @@ static int uwsgi_router_rpc_base(struct uwsgi_route *ur, char *args) { argvs[ur->custom] = strlen(p); ur->custom++; } - p = strtok(NULL, " "); } if (!ur->data) { diff --git a/plugins/webdav/webdav.c b/plugins/webdav/webdav.c index c08bffce..72f0984b 100644 --- a/plugins/webdav/webdav.c +++ b/plugins/webdav/webdav.c @@ -158,11 +158,10 @@ static void uwsgi_webdav_add_a_prop(xmlNode *node, char *opt, xmlNode *req_prop, else if (type == 2) { new_node = xmlNewChild(node, NULL, BAD_CAST first_space + 1, NULL); char *comps = uwsgi_str(second_space + 1); - char *p = strtok(comps, ","); - while(p) { + char *p, *ctx = NULL; + uwsgi_foreach_token(comps, ",", p, ctx) { xmlNode *comp = xmlNewChild(new_node, NULL, BAD_CAST "comp", NULL); xmlNewProp(comp, BAD_CAST "name", BAD_CAST p); - p = strtok(NULL, ","); } free(comps); }