X-Git-Url: https://code.citadel.org/?p=citadel.git;a=blobdiff_plain;f=libcitadel%2Flib%2Furlhandling.c;h=db879dcaf971f3185b574d7cb6580d0039704e3d;hp=7d53f9bdb83701b20f597ae7e49304335bbdea3d;hb=28c9012d1e3ab1d460fdda87d4b0a16423dda99a;hpb=d72c8680f895706d045668a0f4bc5a1edadb467c diff --git a/libcitadel/lib/urlhandling.c b/libcitadel/lib/urlhandling.c index 7d53f9bdb..db879dcaf 100644 --- a/libcitadel/lib/urlhandling.c +++ b/libcitadel/lib/urlhandling.c @@ -13,17 +13,9 @@ #include "libcitadel.h" #include -/** - * @defgroup URLHandling ParsedURL object to handle connection data - */ - -/** - * @ingroup URLHandling - * @brief frees a linked list of ParsedURL - * @param Url (list) of ParsedURL to be freet; Pointer is NULL'ed for the caller. - */ -void FreeURL(ParsedURL** Url) -{ +// frees a linked list of ParsedURL +// Url (list) of ParsedURL to be freet; Pointer is NULL'ed for the caller. +void FreeURL(ParsedURL** Url) { if (*Url != NULL) { FreeStrBuf(&(*Url)->URL); FreeStrBuf(&(*Url)->UrlWithoutCred); @@ -37,30 +29,23 @@ void FreeURL(ParsedURL** Url) } } -/** - * @ingroup URLHandling - * @brief parses the string provided with UrlStr into *Url - * @param Url on success this contains the parsed object; needs to be free'd by caller. - * @param UrlStr String we should parse into parts - * @param DefaultPort Which is the default port here? - */ -int ParseURL(ParsedURL **Url, StrBuf *UrlStr, unsigned short DefaultPort) -{ +// parses the string provided with UrlStr into *Url +// Url on success this contains the parsed object; needs to be free'd by caller. +// UrlStr String we should parse into parts +// DefaultPort Which is the default port here? +int ParseURL(ParsedURL **Url, StrBuf *UrlStr, unsigned short DefaultPort) { const char *pch, *pPort, *pCredEnd, *pUserEnd; ParsedURL *url = (ParsedURL *)malloc(sizeof(ParsedURL)); memset(url, 0, sizeof(ParsedURL)); url->af = AF_INET; url->Port = DefaultPort; - /* - * http://username:passvoid@[ipv6]:port/url - */ - url->URL = NewStrBufDup(UrlStr); + url->URL = NewStrBufDup(UrlStr); // http://username:password@[ipv6]:port/url url->Host = pch = ChrPtr(url->URL); url->LocalPart = strchr(pch, '/'); if (url->LocalPart != NULL) { if ((*(url->LocalPart + 1) == '/') && - (*(url->LocalPart - 1) == ':')) { /* TODO: find default port for this protocol... */ + (*(url->LocalPart - 1) == ':')) { url->Host = url->LocalPart + 2; url->LocalPart = strchr(url->Host, '/'); if (url->LocalPart != NULL) @@ -77,8 +62,7 @@ int ParseURL(ParsedURL **Url, StrBuf *UrlStr, unsigned short DefaultPort) pCredEnd = strrchr(ChrPtr(url->URL), '@'); if (pCredEnd >= url->LocalPart) pCredEnd = NULL; - if (pCredEnd != NULL) - { + if (pCredEnd != NULL) { url->User = url->Host; url->Host = pCredEnd + 1; pUserEnd = strchr(url->User, ':'); @@ -120,20 +104,16 @@ int ParseURL(ParsedURL **Url, StrBuf *UrlStr, unsigned short DefaultPort) } if (pPort != NULL) url->Port = atol(pPort); - if (url->IPv6) - { + if (url->IPv6) { url->IsIP = inet_pton(AF_INET6, url->Host, &url->Addr.sin6_addr); - if (url->IsIP) - { + if (url->IsIP) { url->Addr.sin6_port = htons(url->Port); url->Addr.sin6_port = AF_INET6; } } - else - { + else { url->IsIP = inet_pton(AF_INET, url->Host, &((struct sockaddr_in *)&(url->Addr))->sin_addr); - if (url->IsIP) - { + if (url->IsIP) { ((struct sockaddr_in *)&(url->Addr))->sin_port = htons(url->Port); ((struct sockaddr_in *)&(url->Addr))->sin_family = AF_INET; } @@ -157,8 +137,7 @@ int ParseURL(ParsedURL **Url, StrBuf *UrlStr, unsigned short DefaultPort) return 1; } -void CurlPrepareURL(ParsedURL *Url) -{ +void CurlPrepareURL(ParsedURL *Url) { if (!strcmp(ChrPtr(Url->URL), "http")) Url->UrlWithoutCred = NewStrBufPlain(ChrPtr(Url->URL), -1); else @@ -170,12 +149,10 @@ void CurlPrepareURL(ParsedURL *Url) StrBufAppendPrintf(Url->UrlWithoutCred, "%u", Url->Port); StrBufAppendBufPlain(Url->UrlWithoutCred, HKEY("/"), 0); - if (Url->LocalPart) - { + if (Url->LocalPart) { StrBufAppendBufPlain(Url->UrlWithoutCred, Url->LocalPart, -1, 0); } - if (Url->User != NULL) - { + if (Url->User != NULL) { Url->CurlCreds = NewStrBufPlain(Url->User, -1); StrBufAppendBufPlain(Url->CurlCreds, HKEY(":"), 0); if (Url->Pass != NULL)