[Serdev] Issue in a while statement with str values

Ezequiel Colombo ecolombo at arcotel.net
Tue Aug 24 19:06:56 UTC 2004


Skipped content of type multipart/alternative-------------- next part --------------

// this function querys a db to get the TO_URI field, then
// it parses it and at last, pass this value to main funtion
// in the param _to_uri (struct sip_uri*)

int function get_data1(... struct sip_uri* _to_uri)
{
	.
	...
	......
	
	1) definition of all parameters for db_query(); 
		// it objetive is to give us the "to_uri" 
		// field of a table to parse it later 
		// in step 3), 
	
	2) exec of db_query;
	
	if (db_query result has data) then
		3) parse_uri; 
			// with params 1 and 2 equal to a field of 
			// db_query result in step 2), the third 
			// param is _to_uri;

			/* example
			to_be_parsed.s = (char*)ROW_VALUES(row_data)[1].val.string_val;
			to_be_parsed.len = strlen(to_be_parsed.s);
			if (parse_uri(to_be_parsed.s, to_be_parsed.len, _to_uri) < 0) {
			        LOG(L_ERR, "get_msg(): Error while parsing To URI\n");
			        return -5;
			}
			*/

	else	
		4) return 0;
	end if;
	
	return -5; 
	
	......
	...
	.	
}

// this function querys a db to get properties of a row that  
// matches with the param _to_uri passed to the funtion,
// then fill a structure whit the properties founded.

int function get_data2(struct test* tt, struct sip_uri _to_uri)
{
	.
	...
	......
	
	1) definition of all parameters for db_query();
		// it objetive is to give us a row in a table
		// that matches the _to_uri userpart param
		
	2) exec of db_query;
	
	if (db_query result has data) then
		3) struct test assignament;
			// fill the structure test with the data matched
			// in the table
		   return 1;
	else
		4) return 0;
	end if;
	
	return -5
	
	......
	...
	.
}

// main function. call to get_data1 to get a parsed TO_URI, 
// then tries to obtein a BEST MATCH in a table of DB, using the
// function get_data2 whit the param _to_uri passed by get_data1
// in the first loop, if any row matches with "_to_uri" userpart 
// param, the main function loops again with the lenght of "_to_uri" 
// decremented by one, and so on... if the lenght of the passed
// param to get_data2 reaches 0 (zero) the function stop.

int function main(...)
{
struct sip_uri to_uri
struct test ttt
	.
	...
	......
	
	if (get_data1(&to_uri) = 1) then
		// RECORD FOUND, to_uri parsed!!!
		match = 0
		while ((to_uri.user.len > 0) and (match == 0)) {
			result = get_data2(&ttt, to_uri.user);
			if (result == 1) {
				// 1 ROW FOUND
				match = 1;
			} else if (result == 0) {
				// NO ROWS FOUND. DEREMENT param 
				// lenght for the next match.
				to_uri.user.len--;
			} else {
				//ERROR QUERYNG IN get_data2
				return -5 
			}
		}
	} else { // ROW NOT FOUND, 
		return -5;
	}
	return 1;
	
	......
	...
	.
}


I have the fallowing issue with this implementation:

The returned value (to uri parsed) for the function get_data1 (_to_uri), 
is transformed in the second loop of the while to a memory location,
after doing db_query inside get_data2().
I solved it if I fix the to_uri (in get_data1), (example:
to_uri = "sip:8888 at domain.xxx.dd") and after it I pass this value
to the parse_uri function. But I need use the value matched in
the table.

I test it doing simgles db_querys (not inside a loop) before it, 
and the db_query doesn`t transform the value of the param.



More information about the Serdev mailing list