diff options
| -rw-r--r-- | src/atcmd.c | 76 | ||||
| -rw-r--r-- | src/sms_main.c | 6 | 
2 files changed, 72 insertions, 10 deletions
| diff --git a/src/atcmd.c b/src/atcmd.c index 95d86dc..5c59a4d 100644 --- a/src/atcmd.c +++ b/src/atcmd.c @@ -475,7 +475,8 @@ char *atcmd_value_tok(char **str)  	begin += strspn(begin, " \t"); -	if (*begin == '\"') { +	switch (*begin) { +	case '\"':  		next = ++begin;  		next = strchr(next, '\"'); @@ -489,21 +490,45 @@ char *atcmd_value_tok(char **str)  		if (next) {  			*next++ = '\0';  		} -	} else if (*begin == '(') { + +		break; +	case '(':  		next = ++begin; -		next = strchr(next, ')'); -		if (!next) { -			log_notice("unterminated group"); -			return NULL; +		int count = 0; + +		while (1) { +			switch (*next) { +			case ')': +				if (!count) { +					goto found; +				} +				count--; + +				break; +			case '(': +				count++; + +				break; +			case '\0': +				log_notice("unterminated group"); +				return NULL; +			} + +			next++;  		} + +		found: +  		*next++ = '\0';  		next = strchr(next, ',');  		if (next) {  			*next++ = '\0';  		} -	} else { + +		break; +	default:  		next = begin;  		next = strchr(next, ','); @@ -827,6 +852,13 @@ int atcmd_plus_cpms_test(int fd, struct store_locations *read_loc,  		if (!token) {  			break;  		} +		if (i == 0 && *token == '(') { +			save = token; +			token = atcmd_value_tok(&save); +			if (!token) { +				break; +			} +		}  		choices = token;  		for (j = 0; j < STORE_LOCATIONS_MAX; j++) { @@ -1079,6 +1111,19 @@ int atcmd_init(int fd, int read_timeout)  	return 0;  } +static int msg_store_choice(struct msg_store *store, const char *name) +{ +	int i; + +	for (i = 0; i < store->choices.nr_locations; i++) { +		if(!strcmp(store->choices.names[i], name)) { +			return true; +		} +	} + +	return false; +} +  static int sms_atcmd_init(int fd)  {  	int tmp; @@ -1107,6 +1152,23 @@ static int sms_atcmd_init(int fd)  			&send_store.selected, &new_store.selected);  	if (Global.core.msg_store_read && Global.core.msg_store_send &&  		Global.core.msg_store_new) { + +		if (!msg_store_choice(&read_store, Global.core.msg_store_read)) { +			log_error("message storage location %s is not a choice", +					Global.core.msg_store_read); +			return -1; +		} +		if (!msg_store_choice(&send_store, Global.core.msg_store_send)) { +			log_error("message storage location %s is not a choice", +					Global.core.msg_store_send); +			return -1; +		} +		if (!msg_store_choice(&new_store, Global.core.msg_store_new)) { +			log_error("message storage location %s is not a choice", +					Global.core.msg_store_new); +			return -1; +		} +  		tmp = atcmd_plus_cpms_write(fd, Global.core.msg_store_read,  				Global.core.msg_store_send, Global.core.msg_store_new);  		if (tmp < 0) { diff --git a/src/sms_main.c b/src/sms_main.c index 4a955b8..92c831f 100644 --- a/src/sms_main.c +++ b/src/sms_main.c @@ -55,9 +55,9 @@ static int global_init(void)  	Global.core.baud_rate = B115200;  	Global.core.read_timeout = 5000;  	Global.core.device = strdup(DEFAULT_DEVICE); -	Global.core.msg_store_read = strdup("MT"); -	Global.core.msg_store_send = strdup("MT"); -	Global.core.msg_store_new = strdup("MT"); +	Global.core.msg_store_read = strdup("ME"); +	Global.core.msg_store_send = strdup("ME"); +	Global.core.msg_store_new = strdup("ME");  	Global.core.pb_store = strdup("ME");  	Global.core.editor = strdup("vi");  	Global.core.edit_file = strdup("${HOME}/.smsmsg"); | 
