/[projects]/smsdaemon/Util.cpp
ViewVC logotype

Diff of /smsdaemon/Util.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 79 by torben, Sun Jun 15 16:05:14 2008 UTC revision 114 by torben, Sun Nov 2 20:14:20 2008 UTC
# Line 9  Line 9 
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    #include <stdlib.h>
14    
15    #include <cstring>
16  #include "util.h"  #include "util.h"
17    
18  using namespace std;  using namespace std;
# Line 104  namespace Util Line 107  namespace Util
107                  return retval;                  return retval;
108          }          }
109    
110            char my_toupper(char ch)
111            {
112                    if (ch == 'æ')
113                            return 'Æ';
114                    if (ch == 'ø')
115                            return 'Ø';
116                    if (ch == 'å')
117                            return 'Å';
118    
119                    return ::toupper(ch);
120            }
121    
122            char my_tolower(char ch)
123            {
124                    if (ch == 'Æ')
125                            return 'æ';
126                    if (ch == 'Ø')
127                            return 'ø';
128                    if (ch == 'Å')
129                            return 'å';
130    
131                    return ::tolower(ch);
132            }
133      string str_toupper(string str)      string str_toupper(string str)
134          {          {
135                  for (unsigned i=0; i<str.length(); ++i)                  for (unsigned i=0; i<str.length(); ++i)
136                  {                  {
137                          str.replace(i, 1 ,1, ::toupper(str.at(i)));                          str.replace(i, 1 ,1, my_toupper(str.at(i)));
138                  }                  }
139                  return str;                  return str;
140          }          }
# Line 118  namespace Util Line 143  namespace Util
143          {          {
144                  for (unsigned i=0; i<str.length(); ++i)                  for (unsigned i=0; i<str.length(); ++i)
145                  {                  {
146                          str.replace(i, 1 ,1, ::tolower(str.at(i)));                          str.replace(i, 1 ,1, my_tolower(str.at(i)));
147                  }                  }
148                  return str;                  return str;
149          }          }
# Line 189  namespace Util Line 214  namespace Util
214                                    
215                  ostringstream command;                  ostringstream command;
216                  command << "wget -O " << tempfile << " --tries=1 --timeout=15 -o /dev/null  \"" << url << "\"";                  command << "wget -O " << tempfile << " --tries=1 --timeout=15 -o /dev/null  \"" << url << "\"";
217                  int res = system( command.str().c_str() );                  int res = my_system( command.str().c_str() );
218    
219  /*              if (res)                  if (res<0)
220                  {                  {
221                          throw std::runtime_error("Command time out");                          throw( std::runtime_error("Error retrieving document"));
222                  }*/                  }
223    
224                    if (res>0)
225                    {
226                            throw std::runtime_error("Command time out or document not found");
227                    }
228    
229                  ifstream in( tempfile.c_str() );                  ifstream in( tempfile.c_str() );
230    
# Line 280  namespace Util Line 310  namespace Util
310    
311          int mTimeDiff(const timeval& then, const timeval& now)          int mTimeDiff(const timeval& then, const timeval& now)
312          {          {
313                  return uTimeDiff(then,now) / 1000;                  return ( (now.tv_sec - then.tv_sec)*1000) +
314                                    ((now.tv_usec-then.tv_usec)/1000);
315            }
316    
317    
318            timeval GetTimeOfDay()
319            {
320                    timeval now;
321                    gettimeofday(&now,0);
322                    return now;
323            }
324    
325            int my_system(const char* cmd, std::string* response)
326            {
327                    FILE* p;
328                    if ((p = popen(cmd,"r")) == NULL)
329                            return (-1);
330    
331                    if (response)
332                    {
333                            std::string output;
334                            char buf[256];
335                            while(!feof(p))
336                            {
337                                    int len = fread(buf,1,255, p);
338                                    buf[len] = 0;
339                                    output += buf;
340                            }
341                            *response = output;
342                    }
343    
344                    return (pclose(p));
345          }          }
346    
347  }  }

Legend:
Removed from v.79  
changed lines
  Added in v.114

  ViewVC Help
Powered by ViewVC 1.1.20