Hi,
I just tried to modify and copied an existing function (Octstr
*http_get_header_parameter(Octstr *value, Octstr *parameter);) to a new
function (Octstr *http_cgipost_variable(Octstr *value, Octstr
*parameter);) to parse CGI Vars (var1=value1&var2=value2) in POST method
in HTTP SMSC. It still don't work. I need some hand to check it out.
TIA.
Octstr *http_cgipost_variable(Octstr *value, Octstr *parameter)
{
long pos, c, len, end;
int found = 0;
Octstr *result = NULL;
len = octstr_len(value);
for (pos = 0; pos < len; pos++) {
c = octstr_get_char(value, pos);
if (c == '&')
break;
}
if (pos >= len)
return NULL;
for (pos++; pos > 0 && pos < len && found == 0; pos++) {
Octstr *key = NULL;
Octstr *val = NULL;
end = octstr_search_char(value, '=', pos);
if (end < 0)
end = octstr_search_char(value, '&', pos);
if (end < 0)
end = octstr_len(value);
key = octstr_copy(value, pos, end - pos);
octstr_strip_blanks(key);
pos = end;
if (octstr_get_char(value, pos) == '=') {
pos++;
while (isspace(octstr_get_char(value, pos)))
pos++;
end = octstr_search_char(value, '&', pos);
if (end < 0)
end = octstr_len(value);
val = octstr_copy(value, pos, end - pos);
octstr_strip_blanks(val);
pos = end;
pos = octstr_search_char(value, '&', pos);
}
if (octstr_case_compare(key, parameter) == 0) {
found++;
result = octstr_duplicate(val);
}
octstr_destroy(key);
octstr_destroy(val);
}
return result;
}
called with:
static void telco_receive_sms(SMSCConn *conn, HTTPClient *client,
List *headers, Octstr *body, List *cgivars)
{
tmp = octstr_duplicate(body);
text = http_cgipost_variable(tmp, octstr_imm("text"));
...
}
Willy