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

Diff of /smsdaemon/Util.cpp

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

revision 158 by torben, Mon Dec 8 21:49:49 2008 UTC revision 678 by torben, Tue Apr 27 21:06:53 2010 UTC
# Line 10  Line 10 
10  #include <stdexcept>  #include <stdexcept>
11  #include <time.h>  #include <time.h>
12  #include <sys/time.h>  #include <sys/time.h>
13    #include <sys/types.h>
14    #include <sys/wait.h>
15    #include <errno.h>
16  #include <stdlib.h>  #include <stdlib.h>
17    
18  #include <cstring>  #include <cstring>
# Line 146  namespace Util Line 149  namespace Util
149                  return str;                  return str;
150          }          }
151    
152    
153            vector<string>  str_split(string input)
154            {
155                    string buf;
156                    stringstream ss(input);
157                    vector<string> tokens;
158                    while (ss >> buf)
159                            tokens.push_back(buf);
160                    return tokens;
161            }
162    
163    
164          vector<string> str_split(string input, string delimiter)          vector<string> str_split(string input, string delimiter)
165          {          {
166                  vector<string> retval;                  vector<string> retval;
# Line 168  namespace Util Line 183  namespace Util
183                  return retval;                  return retval;
184          }          }
185    
186          char my_toupper(char ch)          char danish_map[3][2] = { {198,230}, {216,248}, {197,229} }; // aelig, oslash, aring
187    
188            unsigned char my_toupper(unsigned char ch)
189          {          {
190                  if (ch == 'æ')                  if (ch == 230)
191                          return 'Æ';                          return 198;
192                  if (ch == 'ø')                  if (ch == 248)
193                          return 'Ø';                          return 216;
194                  if (ch == 'å')                  if (ch == 229)
195                          return 'Å';                          return 197;
196    
197                  return ::toupper(ch);                  return ::toupper(ch);
198          }          }
199    
200          char my_tolower(char ch)          unsigned char my_tolower(unsigned char ch)
201          {          {
202                  if (ch == 'Æ')                  if (ch == 198)
203                          return 'æ';                          return 230;
204                  if (ch == 'Ø')                  if (ch == 216)
205                          return 'ø';                          return 248;
206                  if (ch == 'Å')                  if (ch == 197)
207                          return 'å';                          return 229;
208    
209                  return ::tolower(ch);                  return ::tolower(ch);
210          }          }
# Line 223  namespace Util Line 240  namespace Util
240                  string rep;                  string rep;
241                  rep.append(1,197);                  rep.append(1,197);
242                  str = str_replace(str, "&#197;", rep);                  str = str_replace(str, "&#197;", rep);
243                    str = str_replace(str, "&Aring;", rep);
244    
245                  rep.at(0) = 198;                  rep.at(0) = 198;
246                  str = str_replace(str, "&#198;", rep);                  str = str_replace(str, "&#198;", rep);
247                    str = str_replace(str, "&AElig;", rep);
248    
249                  rep.at(0) = 216;                  rep.at(0) = 216;
250                  str = str_replace(str, "&#216;", rep);                  str = str_replace(str, "&#216;", rep);
251                    str = str_replace(str, "&Oslash;", rep);
252    
253    
254                  rep.at(0) = 229;                  rep.at(0) = 229;
255                  str = str_replace(str, "&#229;", rep);                  str = str_replace(str, "&#229;", rep);
256                    str = str_replace(str, "&aring;", rep);
257    
258                  rep.at(0) = 230;                  rep.at(0) = 230;
259                  str = str_replace(str, "&#230;", rep);                  str = str_replace(str, "&#230;", rep);
260                    str = str_replace(str, "&aelig;", rep);
261    
262                  rep.at(0) = 248;                  rep.at(0) = 248;
263                  str = str_replace(str, "&#248;", rep);                  str = str_replace(str, "&#248;", rep);
264                    str = str_replace(str, "&oslash;", rep);
265    
266                  return str;                  return str;
267          }          }
# Line 246  namespace Util Line 269  namespace Util
269    
270          string str_gsm2latin(string str)          string str_gsm2latin(string str)
271          {          {
272                  for (unsigned i=0; i<str.size(); i++) {                  for (unsigned i=0; i<str.size(); i++)
273                    {
274                          str.at(i) = char_def_alphabet_decode(str.at(i));                          str.at(i) = char_def_alphabet_decode(str.at(i));
275                  }                  }
276                  return str;                  return str;
# Line 254  namespace Util Line 278  namespace Util
278    
279          string str_latin2gsm(string str)          string str_latin2gsm(string str)
280          {          {
281                  for (unsigned i=0; i<str.size(); i++) {                  for (unsigned i=0; i<str.size(); i++)
282                    {
283                          str.at(i) = char_def_alphabet_encode(str.at(i));                          str.at(i) = char_def_alphabet_encode(str.at(i));
284                  }                  }
285                  return str;                  return str;
286          }          }
287    
288            /* deprecated, use HttpClient instead
289          string readUrl(string url, string tempfile)          string readUrl(string url, string tempfile)
290          {          {
291                  char buf[128000];                  char buf[128000];
# Line 294  namespace Util Line 320  namespace Util
320                  unlink(tempfile.c_str());                  unlink(tempfile.c_str());
321    
322                  return document;                  return document;
323          }          }*/
324    
325    
326    
# Line 397  namespace Util Line 423  namespace Util
423                  return (pclose(p));                  return (pclose(p));
424          }          }
425    
426            int my_system2 (const char *command)
427            {
428                    int pid, status;
429    
430                    if (command == 0)
431                            return 1;
432            //      printf("forking ...\n");
433                    pid = fork();
434                    if (pid == -1)
435                            return -1;
436                    if (pid == 0)
437                    {
438                            char *argv[4];
439                            argv[0] = (char*) "sh";
440                            argv[1] = (char*) "-c";
441                            argv[2] = (char *) command;
442                            argv[3] = 0;
443            //              printf("chaining ...\n");
444                            execve("/bin/sh", argv, environ);
445            //              printf("Chaining failed!\n");
446                            exit(127);
447                    }
448                    do
449                    {
450            //              printf("Waiting on PID: %d\n",pid);
451                            if (waitpid(pid, &status, 0) == -1)
452                            {
453            //                      printf("erc: %d\n",errno);
454                                    if (errno != EINTR)
455                                            return -1;
456                            }
457                            else
458                            {
459            //                      printf("status: %d\n",status);
460                                    return status;
461                            }
462                    }
463                    while (1);
464            }
465    
466    
467          string readfile(string filename)          string readfile(string filename)
468          {          {
469                  string str;                  string str;

Legend:
Removed from v.158  
changed lines
  Added in v.678

  ViewVC Help
Powered by ViewVC 1.1.20