1// Sun, 18 Jun 2000 2// Y.Takagi 3 4#include <cstring> 5#include <stdlib.h> 6#include "URL.h" 7 8URL::URL(const char *spec) 9{ 10// __protocol = "http"; 11// __host = "localhost"; 12// __file = "/"; 13 __port = -1; 14 15 if (spec) { 16 char *temp_spec = new char[strlen(spec) + 1]; 17 strcpy(temp_spec, spec); 18 19 char *p1; 20 char *p2; 21 char *p3; 22 char *p4; 23 24 p1 = strstr(temp_spec, "//"); 25 if (p1) { 26 *p1 = '\0'; 27 p1 += 2; 28 __protocol = temp_spec; 29 } else { 30 p1 = temp_spec; 31 } 32 33 p3 = strstr(p1, "/"); 34 if (p3) { 35 p4 = strstr(p3, "#"); 36 if (p4) { 37 __ref = p4 + 1; 38 *p4 = '\0'; 39 } 40 __file = p3; 41 *p3 = '\0'; 42 } else { 43 __file = "/"; 44 } 45 46 p2 = strstr(p1, ":"); 47 if (p2) { 48 __port = atoi(p2 + 1); 49 *p2 = '\0'; 50 } 51 52 __host = p1; 53 delete [] temp_spec; 54 } 55 56// if (__port == -1) { 57// if (__protocol == "http") { 58// __port = 80; 59// } else if (__protocol == "ipp") { 60// __port = 631; 61// } 62// } 63} 64 65URL::URL(const char *protocol, const char *host, int port, const char *file) 66{ 67 __protocol = protocol; 68 __host = host; 69 __file = file; 70 __port = port; 71} 72 73URL::URL(const char *protocol, const char *host, const char *file) 74{ 75 __protocol = protocol; 76 __host = host; 77 __file = file; 78} 79 80URL::URL(const URL &url) 81{ 82 __protocol = url.__protocol; 83 __host = url.__host; 84 __file = url.__file; 85 __ref = url.__ref; 86 __port = url.__port; 87} 88 89URL &URL::operator = (const URL &url) 90{ 91 __protocol = url.__protocol; 92 __host = url.__host; 93 __file = url.__file; 94 __ref = url.__ref; 95 __port = url.__port; 96 return *this; 97} 98 99bool URL::operator == (const URL &url) 100{ 101 return (__protocol == url.__protocol) && (__host == url.__host) && (__file == url.__file) && 102 (__ref == url.__ref) && (__port == url.__port); 103} 104