masqmail

diff src/expand.c @ 10:26e34ae9a3e3

changed indention and line wrapping to a more consistent style
author meillo@marmaro.de
date Mon, 27 Oct 2008 16:23:10 +0100
parents 08114f7dcc23
children f671821d8222
line diff
     1.1 --- a/src/expand.c	Mon Oct 27 16:21:27 2008 +0100
     1.2 +++ b/src/expand.c	Mon Oct 27 16:23:10 2008 +0100
     1.3 @@ -20,106 +20,110 @@
     1.4  
     1.5  #define MAX_VAR 50
     1.6  
     1.7 -GList *var_table_rcpt(GList *var_table, address *rcpt)
     1.8 +GList*
     1.9 +var_table_rcpt(GList * var_table, address * rcpt)
    1.10  {
    1.11 -    gchar *tmp_str;
    1.12 -    
    1.13 -    var_table = g_list_prepend(var_table, create_pair_string("rcpt_local", rcpt->local_part));
    1.14 -    var_table = g_list_prepend(var_table, create_pair_string("rcpt_domain", rcpt->domain));
    1.15 -    
    1.16 -    tmp_str = g_strdup_printf("%s@%s", rcpt->local_part, rcpt->domain);
    1.17 -    var_table = g_list_prepend(var_table, create_pair_string("rcpt", tmp_str));
    1.18 -    g_free(tmp_str);
    1.19 +	gchar *tmp_str;
    1.20  
    1.21 -    return var_table;
    1.22 +	var_table = g_list_prepend(var_table, create_pair_string("rcpt_local", rcpt->local_part));
    1.23 +	var_table = g_list_prepend(var_table, create_pair_string("rcpt_domain", rcpt->domain));
    1.24 +
    1.25 +	tmp_str = g_strdup_printf("%s@%s", rcpt->local_part, rcpt->domain);
    1.26 +	var_table = g_list_prepend(var_table, create_pair_string("rcpt", tmp_str));
    1.27 +	g_free(tmp_str);
    1.28 +
    1.29 +	return var_table;
    1.30  }
    1.31  
    1.32 -GList *var_table_msg(GList *var_table, message *msg)
    1.33 +GList*
    1.34 +var_table_msg(GList * var_table, message * msg)
    1.35  {
    1.36 -    address *ret_path = msg->return_path;
    1.37 -    gchar *tmp_str;
    1.38 -    
    1.39 -    var_table = g_list_prepend(var_table, create_pair_string("uid", msg->uid));
    1.40 -    var_table = g_list_prepend(var_table, create_pair_string("received_host",
    1.41 -							    msg->received_host ? msg->received_host : ""));
    1.42 -    var_table = g_list_prepend(var_table, create_pair_string("ident", msg->ident ? msg->ident : ""));
    1.43 -    var_table = g_list_prepend(var_table, create_pair_string("return_path_local", ret_path->local_part));
    1.44 -    var_table = g_list_prepend(var_table, create_pair_string("return_path_domain", ret_path->domain));
    1.45 -    
    1.46 -    tmp_str = g_strdup_printf("%s@%s", ret_path->local_part, ret_path->domain);
    1.47 -    var_table = g_list_prepend(var_table, create_pair_string("return_path", tmp_str));
    1.48 -    g_free(tmp_str);
    1.49 +	address *ret_path = msg->return_path;
    1.50 +	gchar *tmp_str;
    1.51  
    1.52 -    return var_table;
    1.53 +	var_table = g_list_prepend(var_table, create_pair_string("uid", msg->uid));
    1.54 +	var_table = g_list_prepend(var_table, create_pair_string("received_host", msg->received_host ? msg->received_host : ""));
    1.55 +	var_table = g_list_prepend(var_table, create_pair_string("ident", msg->ident ? msg->ident : ""));
    1.56 +	var_table = g_list_prepend(var_table, create_pair_string("return_path_local", ret_path->local_part));
    1.57 +	var_table = g_list_prepend(var_table, create_pair_string("return_path_domain", ret_path->domain));
    1.58 +
    1.59 +	tmp_str = g_strdup_printf("%s@%s", ret_path->local_part, ret_path->domain);
    1.60 +	var_table = g_list_prepend(var_table, create_pair_string("return_path", tmp_str));
    1.61 +	g_free(tmp_str);
    1.62 +
    1.63 +	return var_table;
    1.64  }
    1.65  
    1.66 -GList *var_table_conf(GList *var_table)
    1.67 +GList*
    1.68 +var_table_conf(GList * var_table)
    1.69  {
    1.70 -    var_table = g_list_prepend(var_table, create_pair_string("host_name", conf.host_name));
    1.71 -    var_table = g_list_prepend(var_table, create_pair_string("package", PACKAGE));
    1.72 -    var_table = g_list_prepend(var_table, create_pair_string("version", VERSION));
    1.73 +	var_table = g_list_prepend(var_table, create_pair_string("host_name", conf.host_name));
    1.74 +	var_table = g_list_prepend(var_table, create_pair_string("package", PACKAGE));
    1.75 +	var_table = g_list_prepend(var_table, create_pair_string("version", VERSION));
    1.76  
    1.77 -    return var_table;
    1.78 +	return var_table;
    1.79  }
    1.80  
    1.81 -gint expand(GList *var_list, gchar *format, gchar *result, gint result_len)
    1.82 +gint
    1.83 +expand(GList * var_list, gchar * format, gchar * result, gint result_len)
    1.84  {
    1.85 -  gchar *p = format, *q = result;
    1.86 -  gchar *vq;
    1.87 -  gint i = 0;
    1.88 -  gboolean escape = FALSE;
    1.89 +	gchar *p = format, *q = result;
    1.90 +	gchar *vq;
    1.91 +	gint i = 0;
    1.92 +	gboolean escape = FALSE;
    1.93  
    1.94 -  while(*p && (i < (result_len -1))){
    1.95 -    if((*p == '$') && !escape){
    1.96 -      gchar *value;
    1.97 -      gchar var[MAX_VAR+1];
    1.98 -      int j = 0;
    1.99 +	while (*p && (i < (result_len - 1))) {
   1.100 +		if ((*p == '$') && !escape) {
   1.101 +			gchar *value;
   1.102 +			gchar var[MAX_VAR + 1];
   1.103 +			int j = 0;
   1.104  
   1.105 -      p++; /* skip '$' */
   1.106 -      vq = var;
   1.107 +			p++;  /* skip '$' */
   1.108 +			vq = var;
   1.109  
   1.110 -      if(*p == '{'){
   1.111 -	/* ${var} style */
   1.112 -	p++; /* skip '{' */
   1.113 -	while(*p && (*p != '}') && (j < MAX_VAR)){
   1.114 -	  *(vq++) = *(p++);
   1.115 -	  j++;
   1.116 +			if (*p == '{') {
   1.117 +				/* ${var} style */
   1.118 +				p++;  /* skip '{' */
   1.119 +				while (*p && (*p != '}') && (j < MAX_VAR)) {
   1.120 +					*(vq++) = *(p++);
   1.121 +					j++;
   1.122 +				}
   1.123 +				p++;
   1.124 +			} else {
   1.125 +				/* $var style */
   1.126 +				while (*p && (isalnum(*p) || (*p == '_') || (*p == '-')) && (j < MAX_VAR)) {
   1.127 +					*(vq++) = *(p++);
   1.128 +					j++;
   1.129 +				}
   1.130 +			}
   1.131 +			*vq = 0;
   1.132 +
   1.133 +			if (j < MAX_VAR) {
   1.134 +				/* search var */
   1.135 +				value = (gchar *) table_find(var_list, var);
   1.136 +				if (value) {
   1.137 +					gchar *vp = value;
   1.138 +					while (*vp && (i < (result_len - 1))) {
   1.139 +						*(q++) = *(vp++);
   1.140 +						i++;
   1.141 +					}
   1.142 +				}
   1.143 +			}
   1.144 +		} else {
   1.145 +			if ((*p == '\\') && (!escape)) {
   1.146 +				escape = TRUE;
   1.147 +			} else {
   1.148 +				*(q++) = *p;
   1.149 +				i++;
   1.150 +				escape = FALSE;
   1.151 +			}
   1.152 +			p++;
   1.153 +		}
   1.154  	}
   1.155 -	p++;
   1.156 -      }else{
   1.157 -	/* $var style */
   1.158 -	while(*p && (isalnum(*p) || (*p == '_') || (*p == '-')) && (j < MAX_VAR)){
   1.159 -	  *(vq++) = *(p++);
   1.160 -	  j++;
   1.161 -	}
   1.162 -      }
   1.163 -      *vq = 0;
   1.164 +	*q = 0;
   1.165  
   1.166 -      if(j < MAX_VAR){
   1.167 -	/* search var */
   1.168 -	value = (gchar *)table_find(var_list, var);
   1.169 -	if(value){
   1.170 -	  gchar *vp = value;
   1.171 -	  while(*vp && (i < (result_len -1))){
   1.172 -	    *(q++) = *(vp++); i++;
   1.173 -	  }
   1.174 -	}
   1.175 -      }
   1.176 -    }else{
   1.177 -      if((*p == '\\') && (!escape)){
   1.178 -	escape = TRUE;
   1.179 -      }else{
   1.180 -	*(q++) = *p; i++;
   1.181 -	escape = FALSE;
   1.182 -      }
   1.183 -      p++;
   1.184 -    }
   1.185 -  }
   1.186 -  *q = 0;
   1.187 +	if (i >= (result_len - 1))
   1.188 +		return -3;
   1.189  
   1.190 -  if(i >= (result_len -1))
   1.191 -    return -3;
   1.192 -
   1.193 -  return i;
   1.194 +	return i;
   1.195  }
   1.196 -