9 |
#include <iconv.h> |
#include <iconv.h> |
10 |
#include <stdexcept> |
#include <stdexcept> |
11 |
#include <time.h> |
#include <time.h> |
12 |
|
#include <sys/time.h> |
13 |
|
|
14 |
#include "util.h" |
#include "util.h" |
15 |
|
|
54 |
return str; |
return str; |
55 |
} |
} |
56 |
|
|
57 |
|
bool my_isspace(char ch) |
58 |
|
{ |
59 |
|
return (isspace(ch) || ch == 0); |
60 |
|
} |
61 |
|
|
62 |
string str_trim(string str) |
string str_trim(string str) |
63 |
{ |
{ |
64 |
while (str.length() > 0 && isspace(str.at(0))) |
while (str.length() > 0 && my_isspace(str.at(0))) |
65 |
str.erase(0,1); |
str.erase(0,1); |
66 |
while (str.length() > 0 && isspace(str.at(str.length()-1))) |
while (str.length() > 0 && my_isspace(str.at(str.length()-1))) |
67 |
str.erase(str.length()-1,1); |
str.erase(str.length()-1,1); |
68 |
return str; |
return str; |
69 |
} |
} |
190 |
|
|
191 |
ostringstream command; |
ostringstream command; |
192 |
command << "wget -O " << tempfile << " --tries=1 --timeout=15 -o /dev/null \"" << url << "\""; |
command << "wget -O " << tempfile << " --tries=1 --timeout=15 -o /dev/null \"" << url << "\""; |
193 |
int res = system( command.str().c_str() ); |
int res = my_system( command.str().c_str() ); |
194 |
if (res) |
|
195 |
throw std::runtime_error("Command time out"); |
if (res<0) |
196 |
|
{ |
197 |
|
throw( std::runtime_error("Error retrieving document")); |
198 |
|
} |
199 |
|
|
200 |
|
if (res>0) |
201 |
|
{ |
202 |
|
throw std::runtime_error("Command time out or document not found"); |
203 |
|
} |
204 |
|
|
205 |
ifstream in( tempfile.c_str() ); |
ifstream in( tempfile.c_str() ); |
206 |
|
|
286 |
|
|
287 |
int mTimeDiff(const timeval& then, const timeval& now) |
int mTimeDiff(const timeval& then, const timeval& now) |
288 |
{ |
{ |
289 |
return uTimeDiff(then,now) / 1000; |
return ( (now.tv_sec - then.tv_sec)*1000) + |
290 |
|
((now.tv_usec-then.tv_usec)/1000); |
291 |
|
} |
292 |
|
|
293 |
|
|
294 |
|
timeval GetTimeOfDay() |
295 |
|
{ |
296 |
|
timeval now; |
297 |
|
gettimeofday(&now,0); |
298 |
|
return now; |
299 |
|
} |
300 |
|
|
301 |
|
int my_system(const char* cmd) |
302 |
|
{ |
303 |
|
FILE* p; |
304 |
|
if ((p = popen(cmd,"w")) == NULL) |
305 |
|
return (-1); |
306 |
|
return (pclose(p)); |
307 |
} |
} |
308 |
|
|
309 |
} |
} |