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

Diff of /smsdaemon/util.cpp

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

revision 42 by torben, Tue Jun 10 22:22:19 2008 UTC revision 59 by torben, Wed Jun 11 19:42:24 2008 UTC
# Line 7  Line 7 
7  #include <iostream>  #include <iostream>
8  #include <fstream>  #include <fstream>
9  #include <iconv.h>  #include <iconv.h>
10    #include <stdexcept>
11  #include <time.h>  #include <time.h>
12    
13  #include "util.h"  #include "util.h"
# Line 101  namespace Util Line 101  namespace Util
101                  return retval;                  return retval;
102          }          }
103    
104    
105        string str_toupper(string str)
106            {
107                    for (unsigned i=0; i<str.length(); ++i)
108                    {
109                            str.replace(i, 1 ,1, ::toupper(str.at(i)));
110                    }
111                    return str;
112            }
113    
114            string str_tolower(string str)
115            {
116                    for (unsigned i=0; i<str.length(); ++i)
117                    {
118                            str.replace(i, 1 ,1, ::tolower(str.at(i)));
119                    }
120                    return str;
121            }
122    
123    
124            string str_formatint(int i)
125            {
126                    std::ostringstream os;
127                    os << i;
128                    return os.str();
129            }
130    
131    
132          string str_characters(string str)          string str_characters(string str)
133          {          {
134                  string rep;                  string rep;
# Line 127  namespace Util Line 155  namespace Util
155          }          }
156    
157    
158          string str_gsm2latin1(string str)          string str_gsm2latin(string str)
159          {          {
160                  str = str_replace_char(str, 0x1c, 198); //AE                  str = str_replace_char(str, 0x1c, 198); //AE
161                  str = str_replace_char(str, 0x0b, 216); //OE                  str = str_replace_char(str, 0x0b, 216); //OE
# Line 139  namespace Util Line 167  namespace Util
167                  return str;                  return str;
168          }          }
169    
170            string str_latin2gsm(string str)
171            {
172                    str = str_replace_char(str, 198, 0x1c); //AE
173                    str = str_replace_char(str, 216, 0x0b); //OE
174                    str = str_replace_char(str, 197, 0x0e); //AA
175    
176                    str = str_replace_char(str, 230, 0x1d); //ae
177                    str = str_replace_char(str, 248, 0x0c); //oe
178                    str = str_replace_char(str, 229, 0x0f); //aa
179                    return str;
180            }
181    
182          string readUrl(string url, string tempfile)          string readUrl(string url, string tempfile)
183          {          {
184                  char buf[128000];                  char buf[128000];
185                  string document;                  string document;
186                                    
187                  ostringstream command;                  ostringstream command;
188                  command << "wget -O " << tempfile << " -o /dev/null \"" << url << "\"";                  command << "wget -O " << tempfile << " --tries=1 --timeout=15 -o /dev/null  \"" << url << "\"";
189                  system( command.str().c_str() );                  int res = system( command.str().c_str() );
190                    if (res)
191                            throw std::runtime_error("Command time out");
192    
193                  ifstream in( tempfile.c_str() );                  ifstream in( tempfile.c_str() );
194    

Legend:
Removed from v.42  
changed lines
  Added in v.59

  ViewVC Help
Powered by ViewVC 1.1.20