Hi all. Ok, i got such php script:
<?php
header('Location: http://localhost/current/');
?>
Now i am sending GET request to this script with my C app and receiving following header:
HTTP/1.1 302 Found
Date: Sat, 20 Feb 2010 18:50:17 GMT
Server: Apache/2.2.9 (Ubuntu) PHP/5.2.6-2ubuntu4.5 with Suhosin-Patch
X-Powered-By: PHP/5.2.6-2ubuntu4.5
Location: http://localhost/current/
Vary: Accept-Encoding
Content-Length: 0
Connection: close
Content-Type: text/html
So my question is, how to implement at this moment redirection to this new uri? Parse header, extract this uri and call same function from itself? Or use
goto
? By the way i was trying to parse it this way:
char *red = strstr(recvbuffer, "Location:");
if(red != NULL){
char *found, *uri;
t = strtok(red,"\n");
for(i = 0; t; t = strtok(NULL,"\n"), i++) token[i] = t;
found = cut_it(token[0], " ");
found = (found+8);
puts(found);
uri = strstr(found, "/");
if(uri != NULL){
printf("h: %s, p: %s\n", found, uri);
}
}
It should print at the end:
"h: localhost, p: /current/"
but instead it prints: ", p: /current/urrent/".
What is wrong with this code?
Here is my cut_it function:
char *cut_it( char *xx, char *yy){
if ( !*yy ) return xx;
for ( ; *xx; ++xx ){
if ( *xx == *yy ){
char *h, *n;
for ( h = xx, n = yy; *h && *n; ++h, ++n ){
if ( *h != *n )break;
}
if ( !*n ){
return xx;
}}}
return 0;
}
And i cannot use any 3rd party libs for parsing header - it should be in pure C. (I am working on Linux).
Thanks in advance