Subversion Repositories Kolibri OS

Rev

Rev 7283 | Rev 8319 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7283 Rev 8305
Line 70... Line 70...
70
        dword   content_received;
70
	dword   content_received;
71
        char    http_header;
71
	char    http_header;
72
};
72
};
Line -... Line 73...
-
 
73
 
-
 
74
 
-
 
75
#define URL_SIZE 4000
-
 
76
//===================================================//
-
 
77
//                                                   //
-
 
78
//                       HTTP                        //
-
 
79
//                                                   //
-
 
80
//===================================================//
-
 
81
 
-
 
82
struct _http
-
 
83
{
-
 
84
	dword cur_url;
-
 
85
	dword transfer;
-
 
86
	dword content_length;
-
 
87
	dword content_received;
-
 
88
	dword status_code;
-
 
89
	dword receive_result;
-
 
90
	dword content_pointer;
-
 
91
 
-
 
92
	dword get();
-
 
93
	bool stop();
-
 
94
	void hfree();
-
 
95
	void receive();
-
 
96
	dword header_field();
-
 
97
};
-
 
98
 
-
 
99
dword _http::get(dword _url)
-
 
100
{
-
 
101
	cur_url = _url;
-
 
102
	http_get stdcall (_url, 0, 0, #accept_language);
-
 
103
	transfer = EAX;
-
 
104
	return transfer;
-
 
105
}
-
 
106
 
-
 
107
void _http::hfree()
-
 
108
{
-
 
109
	http_free stdcall (transfer);
-
 
110
	transfer=0;
-
 
111
}
-
 
112
 
-
 
113
bool _http::stop()
-
 
114
{
-
 
115
	if (transfer)
-
 
116
	{
-
 
117
		EAX = transfer;
-
 
118
		EAX = EAX.http_msg.content_ptr;         // get pointer to data
-
 
119
		$push   EAX                                                     // save it on the stack
-
 
120
		http_free stdcall (transfer);   // abort connection
-
 
121
		$pop    EAX                                                     
-
 
122
		free(EAX);                                              // free data
-
 
123
		transfer=0;
-
 
124
		return true;    
-
 
125
	}
-
 
126
	return false;
-
 
127
}
-
 
128
 
-
 
129
void _http::receive()
-
 
130
{
-
 
131
	http_receive stdcall (transfer);
-
 
132
	receive_result = EAX;
-
 
133
 
-
 
134
	EDI = transfer;
-
 
135
	if (!EAX) {
-
 
136
		status_code = EDI.http_msg.status;
-
 
137
		content_pointer = EDI.http_msg.content_ptr;
-
 
138
	}
-
 
139
	content_length = EDI.http_msg.content_length;
-
 
140
	content_received = EDI.http_msg.content_received;
-
 
141
}
-
 
142
 
-
 
143
:dword _http::header_field(dword _header_field, _dst, _size)
-
 
144
{
-
 
145
	http_find_header_field stdcall (transfer, _header_field);
-
 
146
	if (EAX!=0) {
-
 
147
		ESI = EAX;
-
 
148
		EDI = _dst;
-
 
149
		EDX = _size;
-
 
150
		do {
-
 
151
			$lodsb;
-
 
152
			$stosb;
-
 
153
			$dec edx
-
 
154
		} while (AL != 0) && (AL != 13) && (AL != 10) && (EDX>0);
-
 
155
		DSBYTE[EDI-1]='\0';
-
 
156
		debugln(_dst);
-
 
157
		return _dst;
-
 
158
	}
-
 
159
	return NULL;
-
 
160
}
-
 
161
 
-
 
162
 
-
 
163
//===================================================//
-
 
164
//                                                   //
-
 
165
//                 CHECK PATH TYPE                   //
-
 
166
//                                                   //
-
 
167
//===================================================//
-
 
168
 
-
 
169
:int check_is_the_adress_local(dword _in)
-
 
170
{
-
 
171
	if (ESBYTE[_in]!='/') return false;
-
 
172
	_in++;
-
 
173
	if(!strncmp(_in,"rd/",3)) return true;
-
 
174
	if(!strncmp(_in,"fd/",3)) return true;
-
 
175
	if(!strncmp(_in,"hd",2)) return true;
-
 
176
	if(!strncmp(_in,"bd",2)) return true;
-
 
177
	if(!strncmp(_in,"cd",2)) return true;
-
 
178
	if(!strncmp(_in,"sys/",4)) return true;
-
 
179
	if(!strncmp(_in,"tmp",3)) return true;
-
 
180
	if(!strncmp(_in,"usbhd",5)) return true;
-
 
181
	if(!strncmp(_in,"kolibrios",9)) return true;
-
 
182
	return false;
-
 
183
}
-
 
184
 
-
 
185
:int check_is_the_url_absolute(dword _in)
-
 
186
{
-
 
187
	if(!strncmp(_in,"ftp:",4)) return true;
-
 
188
	if(!strncmp(_in,"http:",5)) return true;
-
 
189
	if(!strncmp(_in,"https:",6)) return true;
-
 
190
	if(!strncmp(_in,"mailto:",7)) return true;
-
 
191
	if(!strncmp(_in,"tel:",4)) return true;
-
 
192
	if(!strncmp(_in,"#",1)) return true;
-
 
193
	if(!strncmp(_in,"WebView:",8)) return true;
-
 
194
	if(check_is_the_adress_local(_in)) return true;
-
 
195
	return false;
-
 
196
}
-
 
197
 
-
 
198
:dword get_absolute_url(dword new_URL, base_URL)
-
 
199
{
-
 
200
	int i;
-
 
201
	dword orig_URL = new_URL;
-
 
202
	char newurl[URL_SIZE+1];
-
 
203
	strcpy(#newurl, base_URL);
-
 
204
 
-
 
205
	while (i=strstr(new_URL, "&")) strcpy(i+1, i+5);
-
 
206
 
-
 
207
	if (check_is_the_url_absolute(new_URL)) return orig_URL;
-
 
208
 
-
 
209
	IF (!strncmp(new_URL,"//", 2)) 
-
 
210
	{
-
 
211
		strcpy(#newurl, "http:");
-
 
212
		strcat(#newurl, new_URL);
-
 
213
		strcpy(orig_URL, #newurl);
-
 
214
		return orig_URL;
-
 
215
	}
-
 
216
	
-
 
217
	IF (!strncmp(new_URL,"./", 2)) new_URL+=2;
-
 
218
 
-
 
219
	if (ESBYTE[new_URL] == '/') //remove everything after site domain name
-
 
220
	{
-
 
221
		i = strchr(#newurl+8, '/');
-
 
222
		if (i) ESBYTE[i]=0;
-
 
223
		new_URL+=1;
-
 
224
	}
-
 
225
		
-
 
226
	_CUT_ST_LEVEL_MARK:
-
 
227
		
-
 
228
	if (newurl[strrchr(#newurl, '/')-2]<>'/')
-
 
229
	{
-
 
230
		newurl[strrchr(#newurl, '/')] = 0x00;
-
 
231
	}
-
 
232
	
-
 
233
	IF (!strncmp(new_URL,"../",3))
-
 
234
	{
-
 
235
		new_URL+=3;
-
 
236
		newurl[strrchr(#newurl, '/')-1] = 0x00;
-
 
237
		goto _CUT_ST_LEVEL_MARK;
-
 
238
	}
-
 
239
	
-
 
240
	if (newurl[strlen(#newurl)-1]<>'/') strcat(#newurl, "/"); 
-
 
241
	
-
 
242
	strcat(#newurl, new_URL);
-
 
243
	strcpy(orig_URL, #newurl);
-
 
244
	return orig_URL;
-
 
245
}
73
 
246
 
74
 
247