<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<TITLE>Message</TITLE>
<META content="MSHTML 6.00.2800.1400" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><SPAN class=490434614-26072004><FONT face=Arial color=#0000ff size=2>Yes, I
did :-)</FONT></SPAN></DIV>
<DIV><SPAN class=490434614-26072004><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=490434614-26072004><FONT face=Arial color=#0000ff size=2>This
function basically modifies the source string to place \0 at the proper places
and changes the pointers in your struct to appropriate start points. If a part
is not present, that pointer will point to an empty string (also inside the
source string b.t.w.). </FONT></SPAN></DIV>
<DIV><SPAN class=490434614-26072004><FONT color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=490434614-26072004><FONT color=#0000ff size=2>Hope it
helps,</FONT></SPAN></DIV>
<DIV><SPAN class=490434614-26072004><FONT color=#0000ff
size=2>Michel</FONT></SPAN></DIV>
<DIV><SPAN class=490434614-26072004><FONT face=Arial color=#0000ff
size=2></FONT></SPAN><SPAN class=490434614-26072004><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=490434614-26072004><FONT face=Arial color=#ff0000 size=2>H
File:</FONT></SPAN></DIV>
<DIV><SPAN class=490434614-26072004><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=490434614-26072004><FONT face=Arial color=#0000ff
size=2>typedef struct _TUrlParts<BR>{<BR> char *szHost;<BR> char
*szPort;<BR> char *szUri;<BR>} TUrlParts;<BR></FONT></SPAN></DIV>
<DIV><SPAN class=490434614-26072004><FONT face=Arial color=#ff0000 size=2>C
File:</FONT></SPAN></DIV>
<DIV><SPAN class=490434614-26072004><FONT face=Arial color=#0000ff
size=2> </DIV></FONT></SPAN>
<DIV><SPAN class=490434614-26072004><FONT face=Arial color=#0000ff
size=2>/*!<BR> * \brief Break a Url down in parts<BR> *<BR> *
\note Modifies the source string!<BR> *<BR> * \param szUrl URL to
parse<BR> * \param tUrlParts Pointer to where the pointers are
written <BR> *<BR></FONT></SPAN><SPAN class=490434614-26072004><FONT
face=Arial color=#0000ff size=2> * The hostname, port and URI pointers
are<BR> * set to the appropriate locations or an empty string<BR> * if
not present.<BR> *<BR> * \param szUrl Url to parse<BR> */<BR>void
HttpParseUrl(CONST char *szUrl, TUrlParts *tUrlParts)<BR>{<BR>
char *szStart; /* Points to the first character of
the part */<BR> char
*szEnd; /* Points to the last
character of the part */</FONT></SPAN></DIV>
<DIV><FONT face=Arial color=#0000ff size=2></FONT> </DIV>
<DIV><SPAN class=490434614-26072004><FONT face=Arial color=#0000ff
size=2> /*<BR> * In case we don't find
a Host, port or URI, point<BR> * to empty
string<BR> */<BR> tUrlParts->szHost
= tUrlParts->szPort = tUrlParts->szUri = (char *)(szUrl +
strlen(szUrl));</FONT></SPAN></DIV>
<DIV><FONT face=Arial color=#0000ff size=2></FONT> </DIV>
<DIV><SPAN class=490434614-26072004><FONT face=Arial color=#0000ff
size=2> /*<BR> * skip the
prefix<BR> */<BR> szStart =
strstr(szUrl, "://");<BR> if (szStart !=
NULL)<BR> {<BR>
szStart += 3;<BR> }<BR>
else<BR> {<BR>
/*<BR> * Apparently there is no
prefix<BR>
*/<BR> szStart = (char
*)szUrl;<BR> }</FONT></SPAN></DIV>
<DIV> </DIV>
<DIV><SPAN class=490434614-26072004><FONT face=Arial color=#0000ff
size=2> /*<BR> * We have found the
hostname<BR> */<BR>
tUrlParts->szHost = szStart;</FONT></SPAN></DIV>
<DIV><FONT face=Arial color=#0000ff size=2></FONT> </DIV>
<DIV><SPAN class=490434614-26072004><FONT face=Arial color=#0000ff
size=2> /*<BR> * Find the end of the
hostname<BR> * End of it is indicated by ':' or
'/'<BR> * If neither are found, assume we have a URL in
<BR> * the form
'http://demeterkast.net'<BR> */<BR>
szEnd = strchr(szStart, ':');<BR> if (szEnd !=
NULL)<BR> {<BR>
/*<BR> * There is a port
specification, get it now<BR>
*/<BR> *szEnd =
'\0'; /* Terminate the
previous part */<BR> szStart = szEnd +
1; /* point to the portnumber
*/<BR> tUrlParts->szPort =
szStart;<BR> }</FONT></SPAN></DIV>
<DIV> </DIV>
<DIV><SPAN class=490434614-26072004><FONT face=Arial color=#0000ff
size=2> szEnd = strchr(szStart, '/');<BR> if
(szEnd != NULL)<BR>
{<BR>
/*<BR> * There is a URI
specification, get it now<BR>
*/<BR> *szEnd =
'\0'; /* Terminate the
previous part */<BR>
tUrlParts->szUri = szEnd + 1; /* point to the URI
*/<BR> }<BR>}</FONT></SPAN></DIV>
<DIV><FONT face=Arial color=#0000ff size=2></FONT> </DIV>
<DIV><SPAN class=490434614-26072004><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<DIV></DIV>
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left><FONT
face=Tahoma size=2>-----Original Message-----<BR><B>From:</B>
en-nut-discussion-bounces@egnite.de
[mailto:en-nut-discussion-bounces@egnite.de] <B>On Behalf Of
</B>iVesWorking<BR><B>Sent:</B> maandag 26 juli 2004 15:00<BR><B>To:</B>
en-nut-discussion@egnite.de<BR><B>Subject:</B> [En-Nut-Discussion] Need Help
on URL Parse<BR><BR></FONT></DIV>
<DIV><FONT face=Arial size=2>I using strtok_r to parse the URL, But i facing
memory leak with strtok_r</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>this is what show on below </FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2> char *cp; <BR> char
*url;</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2> char *temp;</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2> url = NutHeapAlloc(128); <BR>
temp = NutHeapAlloc(128); <BR>
strcpy(temp,"192.168.125.0:800/index.html");<BR> cp =
strtok_r(temp,":",&url);<BR>
printf("IP%s\n",cp);</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2> NutHeapFree(url);<BR>
NutHeapFree(temp);<BR></FONT></DIV>
<DIV><FONT face=Arial size=2>This program will loss around 20-30Byte of the
memory everytime it execute.</FONT></DIV>
<DIV><FONT face=Arial size=2>Any idea how to solve this problem ?</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>or any people have ready function that did
URL split to Host,Port,Path ?</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2><FONT
color=#0000ff></FONT> </DIV></BLOCKQUOTE></FONT></BODY></HTML>