Skip to content

Instantly share code, notes, and snippets.

@ajpen
Created June 2, 2015 12:16
Show Gist options
  • Save ajpen/c1f7853e1a954abb73c6 to your computer and use it in GitHub Desktop.
Save ajpen/c1f7853e1a954abb73c6 to your computer and use it in GitHub Desktop.
extracts query, absolute path and address line
const char* qextract(char* line) {
//get target line with query in it
const char* target = textract(line, 0);
int len = strlen(target);
char mtarget[len+1];
// make a more mallible copy
memcpy(mtarget, target,len);
// extract query
char * query = strtok(mtarget, "?");
query = strtok(NULL, "?");
// query is not present
if (query == NULL)
return "";
//make sure query isnt empty
char* test = strchr(target, '?');
if (test != NULL && strcmp(test+1, "\0") == 0)
return "";
//query is good, so return it
return query;
}
const char* textract(char* line, int type) {
// copy string to prevent modifying the old one
int len = strlen(line);
char lcopy[len+1];
memcpy(lcopy, line, len);
// default
// move to target string
char * request=strtok(lcopy, " ");
request = strtok(NULL, " ");
//address line requested
if (type == 1) {
if (strchr(lcopy, '?') != NULL) {
char * address = strtok(request,"?");
if (address != NULL)
return address;
}
else
return request;
}
return request;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment