瀏覽代碼

HPCC-19208 CSmartSocketFactory ctor parse out http[s]://

Signed-off-by: Mark Kelly <mark.kelly@lexisnexisrisk.com>
Mark Kelly 6 年之前
父節點
當前提交
7939e7aa86
共有 1 個文件被更改,包括 21 次插入3 次删除
  1. 21 3
      system/jlib/jsmartsock.cpp

+ 21 - 3
system/jlib/jsmartsock.cpp

@@ -45,9 +45,27 @@ public:
         unsigned port = defport;
 
         char *saveptr;
-        char *ip = strtok_r(copyFullText, "|", &saveptr);
-        while (ip != NULL)
+        char *hostportstr = strtok_r(copyFullText, "|", &saveptr);
+        while (hostportstr != nullptr)
         {
+            // strip off http[s]://
+            // is strcasestr/stristr available ?
+            char *ip = strstr(hostportstr, "http://");
+            if (ip == nullptr)
+                ip = strstr(hostportstr, "HTTP://");
+            if (ip != nullptr)
+                ip += 7;
+            else
+            {
+                ip = strstr(hostportstr, "https://");
+                if (ip == nullptr)
+                    ip = strstr(hostportstr, "HTTPS://");
+                if (ip != nullptr)
+                    ip += 8;
+            }
+            if (ip == nullptr)
+                ip = hostportstr;
+
             char *p = strchr(ip, ':');
 
             if (p)
@@ -83,7 +101,7 @@ public:
             {
                 array.append(new SmartSocketEndpoint(ip, port));
             }
-            ip = strtok_r(NULL, "|", &saveptr);
+            hostportstr = strtok_r(NULL, "|", &saveptr);
         }
 
         free(copyFullText);