ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hey... I'm trying to make some utility func, to interpret headers. I've haven't really been able to find any libraries that have the ability to process http headers, so I'm making my own (ne1 know any?)
Here my problem in a nutshell
My delimter is "\r\n\r\n" and i don't need anything else from this point forward.
This is probably a "must know" question, but I've not been able to figure out sscanf with a string as a delimiter. Any information will be greatly appriciated.
Thanks jlliagre.. this will work, but I don't understand your syntax (it works though). I would really like to use sscanf, if possible. Ne1 know what is wrong with my syntax?
It does work, but can you try to explain it further? Or if there's another way to do this. I also thought og readoing the buffer one char at a time, and look for the combination "\r\n\r\n" and return the index. With that number you could just read the nessary header information with the index number. Which would take less time/resources. The function will only be called 1 time pr. request, so I don't know if this will have any impact.
Anyway please do elaborate your ideas
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789
Rep:
Here's a commented code, I guess it says it all:
Code:
char *getHTTPHeader(char *s)
{
char *trailer=strstr(s,"\r\n\r\n");
// trailer points now to the first occurrence of an empty CRLF terminated line.
char *header;
int len=trailer-s; // len is the HTTP header length
header=(char *)malloc(len+1); // allocate memory for the reply
strncpy(header,s,len); // copy the header part to the reply string
header[len]='\0'; // terminate the string
return(header); // that's it
}
main() // test the function
{
printf("%s\n",
getHTTPHeader("include1\r\ninclude2\r\ninclude3\r\n\r\ndonotinclude"));
}
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.