1
2 method str str.ihead( buf data )
3 {
4 uint i
5
6 this.clear()
7
8 while !"\00D\00A".eqlen( data.ptr() + i )
9 {
10 i = data->str.findchfrom( 0x0A, i ) + 1
11 if i >= data.use : return this
12 }
13 this.copy( data.ptr(), i + 2 )
14 data.del( 0, i + 2 )
15
16 return this
17 }
18
19 method uint str.iurl( str host port path )
20 {
21 arrstr names
22 arrstr hosts
23 str stemp = this
24 uint ret = $INET_HTTP
25
26 if !*this : return ret
27 if "http://".eqlenign( stemp.ptr()) : stemp.del( 0, 7 )
28 elif "ftp://".eqlenign( stemp.ptr())
29 {
30 stemp.del( 0, 6 )
31 ret = $INET_FTP
32 }
33 stemp.split( names, '/', $SPLIT_FIRST )
34 names[0].split( hosts, ':', $SPLIT_FIRST )
35 host = hosts[0]
36 if *hosts > 1 : port = hosts[1]
37 if *names > 1 : path = names[1]
38
39 return ret
40 }
41
42 method uint str.ihttpinfo( httpinfo hi )
43 {
44 uint i
45 arrstr month
46 arrstr day
47 arrstr val
48 arrstr lines
49
50 this.split( lines, 0xA, $SPLIT_NOSYS )
51 if !*lines || !"HTTP".eqlenign( this.ptr() ) : return 0
52 lines[0].split( val, ' ', $SPLIT_NOSYS )
53 hi.code = uint( val[1] )
54
55 month += "Jan"; month += "Feb"; month += "Mar"; month += "Apr"
56 month += "May"; month += "Jun"; month += "Jul"; month += "Aug"
57 month += "Sep"; month += "Oct"; month += "Nov"; month += "Dec"
58
59 day += "Sun"; day += "Mon"; day += "Tue"; day += "Wed"
60 day += "Thu"; day += "Fri"; day += "Sat"
61
62 foreach cur, lines
63 {
64 cur.split( val, ':', $SPLIT_NOSYS | $SPLIT_FIRST )
65
66 if *val == 1 : continue
67 switch val[0]
68 {
69 case "Content-Length" : hi.size = val[1]
70 case "Location" : hi.location = val[1]
71 case "Last-Modified"
72 {
73 uint mode tmode
74 arrstr dtime
75 str stemp
76 /* 0 - RFC 1123 1 - RFC 850 2 - ASCTIME */
77 ( stemp = val[1] ).split( val, ' ', $SPLIT_NOSYS )
78 if *val < 4 : continue
79 if !val[0].islast( ',' ) : mode = 2
80 elif *val[0] > 4 : mode = 1
81
82 fornum i = 0, *day
83 {
84 if day[i].eqlenign( val[0] )
85 {
86 hi.dt.dayofweek = i
87 break
88 }
89 }
90 switch mode
91 {
92 case 0
93 {
94 hi.dt.day = uint( val[1] )
95 stemp = val[2]
96 hi.dt.year = uint( val[ 3 ] )
97 tmode = 4
98 }
99 case 1
100 {
101 val[1].split( dtime, '-', $SPLIT_NOSYS )
102 hi.dt.day = uint( dtime[ 0 ] )
103 stemp = dtime[1]
104 hi.dt.year = uint( dtime[ 2 ] ) + 1900
105 if hi.dt.year < 1970 : hi.dt.year += 100
106 tmode = 2
107 }
108 case 2
109 {
110 hi.dt.day = uint( val[2] )
111 hi.dt.year = uint( val[ 4 ] )
112 stemp = val[1]
113 tmode = 3
114 }
115 }
116 fornum i = 0, *month
117 {
118 if stemp %== month[i]
119 {
120 hi.dt.month = i + 1
121 break
122 }
123 }
124 val[ tmode ].split( dtime, ':', $SPLIT_NOSYS )
125 hi.dt.hour = uint( dtime[0] )
126 hi.dt.minute = uint( dtime[1] )
127 hi.dt.second = uint( dtime[2] )
128 }
129 }
130 }
131 return 1
132 }
133
134 method str str.iencoding( str src )
135 {
136 uint i
137
138 fornum i, *src
139 {
140 switch src[i]
141 {
142 case '%', '&', 0x27, '+', '=', '?'
143 {
144 this.appendch('%')
145 //hex2stru( this, src[i] )
146 this.hexu( src[i] )
147 }
148 case ' ' : this.appendch('+')
149 default : this.appendch( src[i] )
150 }
151 }
152 return this
153 }