From 2dfe499721cd57f5e24918d50f605a48391f6fda Mon Sep 17 00:00:00 2001 From: Fabian Keil Date: Fri, 8 Jun 2012 15:15:11 +0000 Subject: [PATCH] Shorten ssplit()'s prototype by removing the last two arguments We always want to skip empty fields and ignore leading delimiters, so having parameters for this only complicates the API. --- actions.c | 4 ++-- cgi.c | 4 ++-- filters.c | 6 +++--- loadcfg.c | 12 ++++++------ ssplit.c | 42 ++++++++++++++---------------------------- ssplit.h | 5 ++--- urlmatch.c | 8 ++++---- 7 files changed, 33 insertions(+), 48 deletions(-) diff --git a/actions.c b/actions.c index 1eddb068..caf62dfb 100644 --- a/actions.c +++ b/actions.c @@ -1,4 +1,4 @@ -const char actions_rcs[] = "$Id: actions.c,v 1.81 2012/03/09 18:06:13 fabiankeil Exp $"; +const char actions_rcs[] = "$Id: actions.c,v 1.82 2012/06/08 15:09:06 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/actions.c,v $ @@ -1400,7 +1400,7 @@ static int load_one_actions_file(struct client_state *csp, int fileid) return 1; /* never get here */ } - num_fields = ssplit(version_string, ".", fields, SZ(fields), 1, 1); + num_fields = ssplit(version_string, ".", fields, SZ(fields)); if (num_fields < 1 || atoi(fields[0]) == 0) { diff --git a/cgi.c b/cgi.c index 556aa436..7ce70aa1 100644 --- a/cgi.c +++ b/cgi.c @@ -1,4 +1,4 @@ -const char cgi_rcs[] = "$Id: cgi.c,v 1.151 2012/06/08 15:07:53 fabiankeil Exp $"; +const char cgi_rcs[] = "$Id: cgi.c,v 1.152 2012/06/08 15:08:33 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/cgi.c,v $ @@ -637,7 +637,7 @@ static struct map *parse_cgi_parameters(char *argstring) *p = '\0'; } - pairs = ssplit(argstring, "&", vector, max_segments, 1, 1); + pairs = ssplit(argstring, "&", vector, max_segments); assert(pairs != -1); if (pairs == -1) { diff --git a/filters.c b/filters.c index 0b643a39..a94454c1 100644 --- a/filters.c +++ b/filters.c @@ -1,4 +1,4 @@ -const char filters_rcs[] = "$Id: filters.c,v 1.170 2012/03/09 17:55:50 fabiankeil Exp $"; +const char filters_rcs[] = "$Id: filters.c,v 1.171 2012/03/18 13:47:33 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/filters.c,v $ @@ -1115,7 +1115,7 @@ char *get_last_url(char *subject, const char *redirect_mode) return NULL; } - segments = ssplit(subject, "?&", url_segments, max_segments, 1, 1); + segments = ssplit(subject, "?&", url_segments, max_segments); while (segments-- > 0) { @@ -2128,7 +2128,7 @@ const static struct forward_spec *get_forward_override_settings(struct client_st return NULL; } - vec_count = ssplit(forward_settings, " \t", vec, SZ(vec), 1, 1); + vec_count = ssplit(forward_settings, " \t", vec, SZ(vec)); if ((vec_count == 2) && !strcasecmp(vec[0], "forward")) { fwd->type = SOCKS_NONE; diff --git a/loadcfg.c b/loadcfg.c index e8526a43..6c329ec9 100644 --- a/loadcfg.c +++ b/loadcfg.c @@ -1,4 +1,4 @@ -const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.127 2012/05/24 14:57:49 fabiankeil Exp $"; +const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.128 2012/05/24 14:58:16 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/loadcfg.c,v $ @@ -624,7 +624,7 @@ struct configuration_spec * load_config(void) #ifdef FEATURE_ACL case hash_deny_access: strlcpy(tmp, arg, sizeof(tmp)); - vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1); + vec_count = ssplit(tmp, " \t", vec, SZ(vec)); if ((vec_count != 1) && (vec_count != 2)) { @@ -809,7 +809,7 @@ struct configuration_spec * load_config(void) * *************************************************************************/ case hash_forward: strlcpy(tmp, arg, sizeof(tmp)); - vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1); + vec_count = ssplit(tmp, " \t", vec, SZ(vec)); if (vec_count != 2) { @@ -864,7 +864,7 @@ struct configuration_spec * load_config(void) * *************************************************************************/ case hash_forward_socks4: strlcpy(tmp, arg, sizeof(tmp)); - vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1); + vec_count = ssplit(tmp, " \t", vec, SZ(vec)); if (vec_count != 3) { @@ -931,7 +931,7 @@ struct configuration_spec * load_config(void) case hash_forward_socks4a: case hash_forward_socks5: strlcpy(tmp, arg, sizeof(tmp)); - vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1); + vec_count = ssplit(tmp, " \t", vec, SZ(vec)); if (vec_count != 3) { @@ -1121,7 +1121,7 @@ struct configuration_spec * load_config(void) #ifdef FEATURE_ACL case hash_permit_access: strlcpy(tmp, arg, sizeof(tmp)); - vec_count = ssplit(tmp, " \t", vec, SZ(vec), 1, 1); + vec_count = ssplit(tmp, " \t", vec, SZ(vec)); if ((vec_count != 1) && (vec_count != 2)) { diff --git a/ssplit.c b/ssplit.c index cea26608..b0da4516 100644 --- a/ssplit.c +++ b/ssplit.c @@ -1,4 +1,4 @@ -const char ssplit_rcs[] = "$Id: ssplit.c,v 1.12 2011/09/04 11:10:56 fabiankeil Exp $"; +const char ssplit_rcs[] = "$Id: ssplit.c,v 1.13 2012/03/09 16:23:50 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/ssplit.c,v $ @@ -62,11 +62,6 @@ const char ssplit_h_rcs[] = SSPLIT_H_VERSION; * 2 : delim = array of delimiters (if NULL, uses " \t"). * 3 : vec[] = results vector (aka. array) [out] * 4 : vec_len = number of usable slots in the vector (aka. array size) - * 5 : dont_save_empty_fields = zero if consecutive delimiters - * give a null output field(s), nonzero if they are just - * to be considered as single delimeter - * 6 : ignore_leading = nonzero to ignore leading field - * separators. * * Returns : -1 => Error: vec_len is too small to hold all the * data, or str == NULL. @@ -74,8 +69,7 @@ const char ssplit_h_rcs[] = SSPLIT_H_VERSION; * On error, vec and str may still have been overwritten. * *********************************************************************/ -int ssplit(char *str, const char *delim, char *vec[], size_t vec_len, - int dont_save_empty_fields, int ignore_leading) +int ssplit(char *str, const char *delim, char *vec[], size_t vec_len) { unsigned char is_delim[256]; unsigned char char_type; @@ -107,24 +101,18 @@ int ssplit(char *str, const char *delim, char *vec[], size_t vec_len, /* Parse string */ - if (ignore_leading) + /* Skip leading separators. XXX: Why do they matter? */ + while (is_delim[(unsigned)(unsigned char)*str] == 1) { - /* skip leading separators */ - while (is_delim[(unsigned)(unsigned char)*str] == 1) - { - str++; - } + str++; } - /* first pointer is the beginning of string */ - /* Check if we want to save this field */ - if ((!dont_save_empty_fields) - || (is_delim[(unsigned)(unsigned char)*str] == 0)) - { + /* The first pointer is the beginning of string */ + if (is_delim[(unsigned)(unsigned char)*str] == 0) + { /* - * We want empty fields, or the first character in this - * field is not a delimiter or the end of string. - * So save it. + * The first character in this field is not a + * delimiter or the end of string, so save it. */ if (vec_count >= vec_len) { @@ -143,13 +131,11 @@ int ssplit(char *str, const char *delim, char *vec[], size_t vec_len, *str++ = '\0'; /* Check if we want to save this field */ - if ((!dont_save_empty_fields) - || (is_delim[(unsigned)(unsigned char)*str] == 0)) - { + if (is_delim[(unsigned)(unsigned char)*str] == 0) + { /* - * We want empty fields, or the first character in this - * field is not a delimiter or the end of string. - * So save it. + * The first character in this field is not a + * delimiter or the end of string. So save it. */ if (vec_count >= vec_len) { diff --git a/ssplit.h b/ssplit.h index b388c646..99335dbd 100644 --- a/ssplit.h +++ b/ssplit.h @@ -1,6 +1,6 @@ #ifndef SSPLIT_H_INCLUDED #define SSPLIT_H_INCLUDED -#define SSPLIT_H_VERSION "$Id: ssplit.h,v 1.9 2011/05/22 10:20:05 fabiankeil Exp $" +#define SSPLIT_H_VERSION "$Id: ssplit.h,v 1.10 2011/09/04 11:10:56 fabiankeil Exp $" /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/ssplit.h,v $ @@ -39,8 +39,7 @@ extern "C" { #endif -extern int ssplit(char *str, const char *delim, char *vec[], size_t vec_len, - int dont_save_empty_fields, int ignore_leading); +extern int ssplit(char *str, const char *delim, char *vec[], size_t vec_len); /* Revision control strings from this header and associated .c file */ extern const char ssplit_rcs[]; diff --git a/urlmatch.c b/urlmatch.c index 3a9c8657..cb0f4163 100644 --- a/urlmatch.c +++ b/urlmatch.c @@ -1,4 +1,4 @@ -const char urlmatch_rcs[] = "$Id: urlmatch.c,v 1.69 2012/03/09 16:24:36 fabiankeil Exp $"; +const char urlmatch_rcs[] = "$Id: urlmatch.c,v 1.70 2012/03/09 17:55:50 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/urlmatch.c,v $ @@ -139,7 +139,7 @@ jb_err init_domain_components(struct http_request *http) } /* split the domain name into components */ - http->dcount = ssplit(http->dbuffer, ".", vec, SZ(vec), 1, 1); + http->dcount = ssplit(http->dbuffer, ".", vec, SZ(vec)); if (http->dcount <= 0) { @@ -530,7 +530,7 @@ jb_err parse_http_request(const char *req, struct http_request *http) return JB_ERR_MEMORY; } - n = ssplit(buf, " \r\n", v, SZ(v), 1, 1); + n = ssplit(buf, " \r\n", v, SZ(v)); if (n != 3) { freez(buf); @@ -847,7 +847,7 @@ static jb_err compile_host_pattern(struct url_spec *url, const char *host_patter /* * Split the domain name into components */ - url->dcount = ssplit(url->dbuffer, ".", v, SZ(v), 1, 1); + url->dcount = ssplit(url->dbuffer, ".", v, SZ(v)); if (url->dcount < 0) { -- 2.39.2