]> code.citadel.org Git - citadel.git/blobdiff - libcitadel/lib/urlhandling.c
URL-Handling: bugfixes
[citadel.git] / libcitadel / lib / urlhandling.c
index cfadf345f5cf154eb1b9f4582afa36b6688465a0..f350ea7d403fb41c9570c7df5157009bd28f44fa 100644 (file)
@@ -9,6 +9,7 @@
 #include <fcntl.h>
 #include <sys/types.h>
 #include "libcitadel.h"
+#include <sys/socket.h>
 
 /**
  * @defgroup URLHandling ParsedURL object to handle connection data
@@ -52,12 +53,12 @@ int ParseURL(ParsedURL **Url, StrBuf *UrlStr, unsigned short DefaultPort)
         */
        url->URL = NewStrBufDup(UrlStr);
        url->Host = pch = ChrPtr(url->URL);
-       url->LocalPart = strchr(pch, '/');
+       pEndHost = url->LocalPart = strchr(pch, '/');
        if (url->LocalPart != NULL) {
                if ((*(url->LocalPart + 1) == '/') && 
                    (*(url->LocalPart - 1) == ':')) { /* TODO: find default port for this protocol... */
                        url->Host = url->LocalPart + 2;
-                       url->LocalPart = strchr(url->Host, '/');
+                       pEndHost = url->LocalPart = strchr(url->Host, '/');
                        if (url->LocalPart != NULL)
                        {
                            StrBufPeek(url->URL, url->LocalPart, 0, '\0');
@@ -66,10 +67,10 @@ int ParseURL(ParsedURL **Url, StrBuf *UrlStr, unsigned short DefaultPort)
                }
        }
        if (url->LocalPart == NULL) {
-               url->LocalPart = pch + StrLength(url->URL);
+               pEndHost = 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)
@@ -129,7 +130,9 @@ 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 != NULL)
+               url->Next = *Url;
        *Url = url;
        return 1;
 }