]> code.citadel.org Git - citadel.git/blobdiff - libcitadel/lib/urlhandling.c
Make the swap buffer content function publically available.
[citadel.git] / libcitadel / lib / urlhandling.c
index 131cafa6ec4efed449a330320a661b8ea4baf7d6..8896770eea84ce4755eaf3aad5864d78b070091f 100644 (file)
@@ -26,6 +26,8 @@ void FreeURL(ParsedURL** Url)
                FreeStrBuf(&(*Url)->URL);
                FreeStrBuf(&(*Url)->UrlWithoutCred);
                FreeStrBuf(&(*Url)->CurlCreds);
+               FreeStrBuf(&(*Url)->UsrName);
+               FreeStrBuf(&(*Url)->Password);
                if ((*Url)->Next != NULL)
                        FreeURL(&(*Url)->Next);
                free(*Url);
@@ -42,7 +44,7 @@ void FreeURL(ParsedURL** 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));
 
@@ -67,10 +69,10 @@ int ParseURL(ParsedURL **Url, StrBuf *UrlStr, unsigned short DefaultPort)
                }
        }
        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)
@@ -87,9 +89,12 @@ int ParseURL(ParsedURL **Url, StrBuf *UrlStr, unsigned short DefaultPort)
                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) {
@@ -130,7 +135,22 @@ int ParseURL(ParsedURL **Url, StrBuf *UrlStr, unsigned short DefaultPort)
                ((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;
 }