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

Diff of /smsdaemon/Util.cpp

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

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

Legend:
Removed from v.84  
changed lines
  Added in v.108

  ViewVC Help
Powered by ViewVC 1.1.20