#include <fcntl.h>
#include <sys/types.h>
#include "libcitadel.h"
+#include <sys/socket.h>
/**
* @defgroup URLHandling ParsedURL object to handle connection data
FreeStrBuf(&(*Url)->URL);
FreeStrBuf(&(*Url)->UrlWithoutCred);
FreeStrBuf(&(*Url)->CurlCreds);
+ FreeStrBuf(&(*Url)->UsrName);
+ FreeStrBuf(&(*Url)->Password);
if ((*Url)->Next != NULL)
FreeURL(&(*Url)->Next);
free(*Url);
*/
int ParseURL(ParsedURL **Url, StrBuf *UrlStr, unsigned short DefaultPort)
{
- const char *pch, *pEndHost, *pPort, *pCredEnd, *pUserEnd;
+ const char *pch, *pPort, *pCredEnd, *pUserEnd;
ParsedURL *url = (ParsedURL *)malloc(sizeof(ParsedURL));
memset(url, 0, sizeof(ParsedURL));
}
}
if (url->LocalPart == NULL) {
- url->LocalPart = pch + StrLength(url->URL);
+ url->LocalPart = ChrPtr(url->URL) + StrLength(url->URL);
}
- pCredEnd = strchr(pch, '@');
+ pCredEnd = strrchr(ChrPtr(url->URL), '@');
if (pCredEnd >= url->LocalPart)
pCredEnd = NULL;
if (pCredEnd != NULL)
StrBufPeek(url->URL, pUserEnd, 0, '\0');
StrBufPeek(url->URL, pCredEnd, 0, '\0');
}
+ else
+ pUserEnd = NULL;
pPort = NULL;
if (*url->Host == '[') {
+ const char *pEndHost;
url->Host ++;
pEndHost = strchr(url->Host, ']');
if (pEndHost == NULL) {
((struct sockaddr_in *)&(url->Addr))->sin_port = htons(url->Port);
((struct sockaddr_in *)&(url->Addr))->sin_family = AF_INET;
}
- }
+ }
+
+ if (url->User != NULL) {
+ url->UsrName = NewStrBufPlain(url->User, pUserEnd - url->User);
+ StrBufUnescape(url->UsrName, 0);
+ url->User = ChrPtr(url->UsrName);
+ }
+
+ if (url->Pass != NULL) {
+ url->Password = NewStrBufPlain(url->Pass, pCredEnd - url->Pass);
+ StrBufUnescape(url->Password, 0);
+ url->Pass = ChrPtr(url->Password);
+ }
+
+ if (*Url != NULL)
+ url->Next = *Url;
*Url = url;
return 1;
}