]> git.stg.codes - stg.git/blob - projects/sgconf/sginfo.cpp
Судя по всем файл sginfo.cpp консольного конфигуратора не используется,
[stg.git] / projects / sgconf / sginfo.cpp
1 /*
2  *    This program is free software; you can redistribute it and/or modify
3  *    it under the terms of the GNU General Public License as published by
4  *    the Free Software Foundation; either version 2 of the License, or
5  *    (at your option) any later version.
6  *
7  *    This program is distributed in the hope that it will be useful,
8  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
9  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  *    GNU General Public License for more details.
11  *
12  *    You should have received a copy of the GNU General Public License
13  *    along with this program; if not, write to the Free Software
14  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15  */
16
17 /*
18  *    Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
19  */
20
21  /*
22  $Author: faust $
23  $Revision: 1.3 $
24  $Date: 2009/06/22 15:57:49 $
25  */
26
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <getopt.h>
30 #include <sys/types.h>
31 #include <sys/socket.h>
32 #include <netinet/in.h>
33 #include <arpa/inet.h>
34 #include <string.h>
35 #include <iconv.h>
36 #include <string>
37 #include <list>
38 #include <errno.h>
39
40 #include "request.h"
41 #include "common.h"
42 #include "netunit.h"
43 #include "common_sg.h"
44 #include "sg_error_codes.h"
45
46 using namespace std;
47
48 time_t stgTime;
49
50 int ParseReplyGet(void * data, list<string> * ans);
51 int ParseReplySet(void * data, list<string> * ans);
52
53 struct option long_options_get[] = {
54 {"server",      1, 0, 's'},  //Server
55 {"port",        1, 0, 'p'},  //Port
56 {"admin",       1, 0, 'a'},  //Admin
57 {"admin_pass",  1, 0, 'w'},  //passWord
58 {"user",        1, 0, 'u'},  //User
59 {"addcash",     0, 0, 'c'},  //Add Cash
60 //{"setcash",     0, 0, 'v'},  //Set Cash
61 {"credit",      0, 0, 'r'},  //cRedit
62 {"tariff",      0, 0, 't'},  //Tariff
63 {"message",     0, 0, 'm'},  //message
64 {"password",    0, 0, 'o'},  //password
65 {"down",        0, 0, 'd'},  //down
66 {"passive",     0, 0, 'i'},  //passive
67 {"u0",          0, 0, 500},  //U0
68 {"u1",          0, 0, 501},  //U1
69 {"u2",          0, 0, 502},  //U2
70 {"u3",          0, 0, 503},  //U3
71 {"u4",          0, 0, 504},  //U4
72 {"u5",          0, 0, 505},  //U5
73 {"u6",          0, 0, 506},  //U6
74 {"u7",          0, 0, 507},  //U7
75 {"u8",          0, 0, 508},  //U8
76 {"u9",          0, 0, 509},  //U9
77 {"d0",          0, 0, 600},  //D0
78 {"d1",          0, 0, 601},  //D1
79 {"d2",          0, 0, 602},  //D2
80 {"d3",          0, 0, 603},  //D3
81 {"d4",          0, 0, 604},  //D4
82 {"d5",          0, 0, 605},  //D5
83 {"d6",          0, 0, 606},  //D6
84 {"d7",          0, 0, 607},  //D7
85 {"d8",          0, 0, 608},  //D8
86 {"d9",          0, 0, 609},  //D9
87
88 {"ud0",         0, 0, 700},  //UserData0
89 {"ud1",         0, 0, 701},  //UserData1
90 {"ud2",         0, 0, 702},  //UserData2
91 {"ud3",         0, 0, 703},  //UserData3
92 {"ud4",         0, 0, 704},  //UserData4
93 {"ud5",         0, 0, 705},  //UserData5
94 {"ud6",         0, 0, 706},  //UserData6
95 {"ud7",         0, 0, 707},  //UserData7
96 {"ud8",         0, 0, 708},  //UserData8
97 {"ud9",         0, 0, 709},  //UserData9
98
99 {"prepaid",     0, 0, 'e'},  //prepaid traff
100 {"create",      0, 0, 'n'},  //create
101 {"delete",      0, 0, 'l'},  //delete
102
103 {"note",        0, 0, 'N'},  //Note
104 {"name",        0, 0, 'A'},  //nAme
105 {"address",     0, 0, 'D'},  //aDdress
106 {"email",       0, 0, 'L'},  //emaiL
107 {"phone",       0, 0, 'P'},  //phone
108 {"group",       0, 0, 'G'},  //Group
109
110 {0, 0, 0, 0}};
111
112 struct option long_options_set[] = {
113 {"server",      1, 0, 's'},  //Server
114 {"port",        1, 0, 'p'},  //Port
115 {"admin",       1, 0, 'a'},  //Admin
116 {"admin_pass",  1, 0, 'w'},  //passWord
117 {"user",        1, 0, 'u'},  //User
118 {"addcash",     1, 0, 'c'},  //Add Cash
119 {"setcash",     1, 0, 'v'},  //Set Cash
120 {"credit",      1, 0, 'r'},  //cRedit
121 {"tariff",      1, 0, 't'},  //Tariff
122 {"message",     1, 0, 'm'},  //message
123 {"password",    1, 0, 'o'},  //password
124 {"down",        1, 0, 'd'},  //down
125 {"passive",     1, 0, 'i'},  //passive
126 {"u0",          1, 0, 500},  //U0
127 {"u1",          1, 0, 501},  //U1
128 {"u2",          1, 0, 502},  //U2
129 {"u3",          1, 0, 503},  //U3
130 {"u4",          1, 0, 504},  //U4
131 {"u5",          1, 0, 505},  //U5
132 {"u6",          1, 0, 506},  //U6
133 {"u7",          1, 0, 507},  //U7
134 {"u8",          1, 0, 508},  //U8
135 {"u9",          1, 0, 509},  //U9
136 {"d0",          1, 0, 600},  //D0
137 {"d1",          1, 0, 601},  //D1
138 {"d2",          1, 0, 602},  //D2
139 {"d3",          1, 0, 603},  //D3
140 {"d4",          1, 0, 604},  //D4
141 {"d5",          1, 0, 605},  //D5
142 {"d6",          1, 0, 606},  //D6
143 {"d7",          1, 0, 607},  //D7
144 {"d8",          1, 0, 608},  //D8
145 {"d9",          1, 0, 609},  //D9
146
147 {"ud0",         1, 0, 700},  //UserData
148 {"ud1",         1, 0, 701},  //UserData1
149 {"ud2",         1, 0, 702},  //UserData2
150 {"ud3",         1, 0, 703},  //UserData3
151 {"ud4",         1, 0, 704},  //UserData4
152 {"ud5",         1, 0, 705},  //UserData5
153 {"ud6",         1, 0, 706},  //UserData6
154 {"ud7",         1, 0, 707},  //UserData7
155 {"ud8",         1, 0, 708},  //UserData8
156 {"ud9",         1, 0, 709},  //UserData9
157
158 {"prepaid",     1, 0, 'e'},  //prepaid traff
159 {"create",      1, 0, 'n'},  //create
160 {"delete",      1, 0, 'l'},  //delete
161
162 {"note",        1, 0, 'N'},  //Note
163 {"name",        1, 0, 'A'},  //nAme
164 {"address",     1, 0, 'D'},  //aDdress
165 {"email",       1, 0, 'L'},  //emaiL
166 {"phone",       1, 0, 'P'},  //phone
167 {"group",       1, 0, 'G'},  //Group
168
169 {0, 0, 0, 0}};
170
171 //-----------------------------------------------------------------------------
172 void CreateRequestGet(REQUEST * req, char * r)
173 {
174 string r1;
175 r1 = "<GetUser login=\"" + req->login.const_data() + "\"/>\n";
176 strcpy(r, r1.c_str());
177 }
178 //-----------------------------------------------------------------------------
179 double ParseCash(const char * c, string * message)
180 {
181 //-c 123.45:log message
182 double cash;
183 char * msg;
184 char * str;
185 str = new char[strlen(c) + 1];
186
187 strncpy(str, c, strlen(c));
188 msg = strchr(str, ':');
189
190 if (msg)
191     {
192     *message =  msg + 1;
193     str[msg - str] = 0;
194     }
195 else
196     *message = "";
197
198 if (strtodouble2(str, cash) != 0)
199     {
200     printf("Incorrect cash value %s\n", c);
201     exit(PARAMETER_PARSING_ERR_CODE);
202     }
203
204 delete[] str;
205 return cash;
206 }
207 //-----------------------------------------------------------------------------
208 double ParseCredit(const char * c)
209 {
210 double credit;
211 if (strtodouble2(c, credit) != 0)
212     {
213     printf("Incorrect credit value %s\n", c);
214     exit(PARAMETER_PARSING_ERR_CODE);
215     }
216
217 return credit;
218 }
219 //-----------------------------------------------------------------------------
220 double ParsePrepaidTraffic(const char * c)
221 {
222 double credit;
223 if (strtodouble2(c, credit) != 0)
224     {
225     printf("Incorrect prepaid traffic value %s\n", c);
226     exit(PARAMETER_PARSING_ERR_CODE);
227     }
228
229 return credit;
230 }
231 //-----------------------------------------------------------------------------
232 int64_t ParseTraff(const char * c)
233 {
234 int64_t traff;
235 if (str2x(c, traff) != 0)
236     {
237     printf("Incorrect credit value %s\n", c);
238     exit(PARAMETER_PARSING_ERR_CODE);
239     }
240
241 return traff;
242 }
243 //-----------------------------------------------------------------------------
244 bool ParseDownPassive(const char * dp)
245 {
246 if (!(dp[1] == 0 && (dp[0] == '1' || dp[0] == '0')))
247     {
248     printf("Incorrect value %s\n", dp);
249     exit(PARAMETER_PARSING_ERR_CODE);
250     }
251
252 return dp[0] - '0';
253 }
254 //-----------------------------------------------------------------------------
255 string ParseTariff(const char * t, int &chgType)
256 {
257 int l = strlen(t);
258 char * s;
259 s = new char[l];
260 char * s1, * s2;
261 string ss;
262
263 strcpy(s, t);
264
265 s1 = strtok(s, ":");
266
267 if (strlen(s1) >= TARIFF_NAME_LEN)
268     {
269     printf("Tariff name too big %s\n", s1);
270     exit(PARAMETER_PARSING_ERR_CODE);
271     }
272
273 //*tariff = s;
274
275 if (CheckLogin(s1))
276     {
277     printf("Incorrect tariff value %s\n", t);
278     exit(PARAMETER_PARSING_ERR_CODE);
279     }
280
281 s2 = strtok(NULL, ":");
282
283 chgType = -1;
284
285 if (s2 == NULL)
286     {
287     chgType = TARIFF_NOW;
288     ss = s;
289     delete[] s;
290     return ss;
291     }
292
293
294 if (strcmp(s2, "now") == 0)
295     chgType = TARIFF_NOW;
296
297 if (strcmp(s2, "delayed") == 0)
298     chgType = TARIFF_DEL;
299
300 if (strcmp(s2, "recalc") == 0)
301     chgType = TARIFF_REC;
302
303 if (chgType < 0)
304     {
305     printf("Incorrect tariff value %s\n", t);
306     exit(PARAMETER_PARSING_ERR_CODE);
307     }
308
309 ss = s;
310 delete[] s;
311 return ss;
312 }
313 //-----------------------------------------------------------------------------
314 void ParseAnyString(const char * c, string * msg)
315 {
316 iconv_t cd;
317 char * ob = new char[strlen(c) + 1];
318 char * ib = new char[strlen(c) + 1];
319
320 strcpy(ib, c);
321
322 char * outbuf = ob;
323 char * inbuf = ib;
324
325 setlocale(LC_ALL, "");
326
327 char charsetF[255];
328 strncpy(charsetF, nl_langinfo(CODESET), 255);
329
330 char * charsetT = "koi8-r";
331
332 size_t nconv = 1;
333
334 size_t insize = strlen(ib);
335 size_t outsize = strlen(ib);
336
337 insize = strlen(c);
338
339 cd = iconv_open(charsetT, charsetF);
340 if (cd == (iconv_t) -1)
341     {
342     if (errno == EINVAL)
343         {
344         printf("Warning: iconv from %s to %s failed\n", charsetF, charsetT);
345         *msg = c;
346         return;
347         }
348     else
349         printf("error iconv_open\n");
350
351     exit(ICONV_ERR_CODE);
352     }
353
354 nconv = iconv (cd, &inbuf, &insize, &outbuf, &outsize);
355 //printf("nconv=%d outsize=%d\n", nconv, outsize);
356 if (nconv == (size_t) -1)
357     {
358     if (errno != EINVAL)
359         {
360         printf("iconv error\n");
361         exit(ICONV_ERR_CODE);
362         }
363     }
364
365 *outbuf = L'\0';
366
367 iconv_close(cd);
368 *msg = ob;
369
370 delete[] ob;
371 delete[] ib;
372 }
373 //-----------------------------------------------------------------------------
374 void CreateRequestSet(REQUEST * req, char * r)
375 {
376 const int strLen = 10024;
377 char str[strLen];
378 memset(str, 0, strLen);
379
380 r[0] = 0;
381
382 if (!req->usrMsg.res_empty())
383     {
384     int len = req->usrMsg.const_data().length() * 2 + 1;
385     char * msg = new char[len];
386     memset(msg, 0, len);
387     Encode12(msg, req->usrMsg.const_data().c_str(), req->usrMsg.const_data().length());
388
389     sprintf(str, "<Message login=\"%s\" msgver=\"1\" msgtype=\"1\" repeat=\"0\" repeatperiod=\"0\" showtime=\"0\" text=\"%s\"/>", req->login.const_data().c_str(), msg);
390     //sprintf(str, "<message login=\"%s\" priority=\"0\" text=\"%s\"/>\n", req->login, msg);
391     strcat(r, str);
392
393     delete[] msg;
394     return;
395     }
396
397 if (req->deleteUser)
398     {
399     sprintf(str, "<DelUser login=\"%s\"/>", req->login.const_data().c_str());
400     strcat(r, str);
401     //printf("%s\n", r);
402     return;
403     }
404
405 if (req->createUser)
406     {
407     sprintf(str, "<AddUser> <login value=\"%s\"/> </AddUser>", req->login.const_data().c_str());
408     strcat(r, str);
409     //printf("%s\n", r);
410     return;
411     }
412
413 strcat(r, "<SetUser>\n");
414 sprintf(str, "<login value=\"%s\"/>\n", req->login.const_data().c_str());
415 strcat(r, str);
416 if (!req->credit.res_empty())
417     {
418     sprintf(str, "<credit value=\"%f\"/>\n", req->credit.const_data());
419     strcat(r, str);
420     }
421
422 if (!req->prepaidTraff.res_empty())
423     {
424     sprintf(str, "<FreeMb value=\"%f\"/>\n", req->prepaidTraff.const_data());
425     strcat(r, str);
426     }
427
428 if (!req->cash.res_empty())
429     {
430     int len = req->message.length() * 2 + 1;
431     char * msg = new char[len];
432     memset(msg, 0, len);
433
434     Encode12(msg, req->message.c_str(), req->message.length());
435     sprintf(str, "<cash add=\"%f\" msg=\"%s\"/>\n", req->cash.const_data(), msg);
436     strcat(r, str);
437     delete[] msg;
438     }
439
440 if (!req->setCash.res_empty())
441     {
442     int len = req->message.length() * 2 + 1;
443     char * msg = new char[len];
444     memset(msg, 0, len);
445     Encode12(msg, req->message.c_str(), req->message.length());
446     sprintf(str, "<cash set=\"%f\" msg=\"%s\"/>\n", req->setCash.const_data(), msg);
447     strcat(r, str);
448     delete[] msg;
449     }
450
451 if (!req->usrPasswd.res_empty())
452     {
453     sprintf(str, "<password value=\"%s\" />\n", req->usrPasswd.const_data().c_str());
454     strcat(r, str);
455     }
456
457 if (!req->down.res_empty())
458     {
459     sprintf(str, "<down value=\"%d\" />\n", req->down.const_data());
460     strcat(r, str);
461     }
462
463 if (!req->passive.res_empty())
464     {
465     sprintf(str, "<passive value=\"%d\" />\n", req->passive.const_data());
466     strcat(r, str);
467     }
468
469 int uPresent = false;
470 int dPresent = false;
471 for (int i = 0; i < DIR_NUM; i++)
472     {
473     if (!req->u[i].res_empty())
474         {
475         if (!uPresent && !dPresent)
476             {
477             sprintf(str, "<traff ");
478             strcat(r, str);
479             uPresent = true;
480             }
481
482         stringstream ss;
483         ss << req->u[i].const_data();
484         //sprintf(str, "MU%d=\"%lld\" ", i, req->u[i].const_data());
485         sprintf(str, "MU%d=\"%s\" ", i, ss.str().c_str());
486         strcat(r, str);
487         }
488     if (!req->d[i].res_empty())
489         {
490         if (!uPresent && !dPresent)
491             {
492             sprintf(str, "<traff ");
493             strcat(r, str);
494             dPresent = true;
495             }
496
497         stringstream ss;
498         ss << req->d[i].const_data();
499         sprintf(str, "MD%d=\"%s\" ", i, ss.str().c_str());
500         strcat(r, str);
501         }
502     }
503 if (uPresent || dPresent)
504     {
505     strcat(r, "/>");
506     }
507
508 //printf("%s\n", r);
509
510 if (!req->tariff.res_empty())
511     {
512     switch (req->chgTariff)
513         {
514         case TARIFF_NOW:
515             sprintf(str, "<tariff now=\"%s\"/>\n", req->tariff.const_data().c_str());
516             strcat(r, str);
517             break;
518         case TARIFF_REC:
519             sprintf(str, "<tariff recalc=\"%s\"/>\n", req->tariff.const_data().c_str());
520             strcat(r, str);
521             break;
522         case TARIFF_DEL:
523             sprintf(str, "<tariff delayed=\"%s\"/>\n", req->tariff.const_data().c_str());
524             strcat(r, str);
525             break;
526         }
527
528     }
529
530 if (!req->note.res_empty())
531     {
532     int len = req->note.const_data().length() * 2 + 1;
533     char * note = new char[len];
534     memset(note, 0, len);
535
536     Encode12(note, req->note.const_data().c_str(), req->note.const_data().length());
537
538     sprintf(str, "<note value=\"%s\"/>", note);
539     strcat(r, str);
540     delete[] note;
541     }
542
543 if (!req->name.res_empty())
544     {
545     int len = req->note.const_data().length() * 2 + 1;
546     char * name = new char[len];
547     memset(name, 0, len);
548
549     Encode12(name, req->name.const_data().c_str(), req->name.const_data().length());
550
551     sprintf(str, "<name value=\"%s\"/>", name);
552     strcat(r, str);
553     delete[] name;
554     }
555
556 if (!req->address.res_empty())
557     {
558     int len = req->note.const_data().length() * 2 + 1;
559     char * address = new char[len];
560     memset(address, 0, len);
561
562     Encode12(address, req->address.const_data().c_str(), req->address.const_data().length());
563
564     sprintf(str, "<address value=\"%s\"/>", address);
565     strcat(r, str);
566     delete[] address;
567     }
568
569 if (!req->email.res_empty())
570     {
571     int len = req->note.const_data().length() * 2 + 1;
572     char * email = new char[len];
573     memset(email, 0, len);
574
575     Encode12(email, req->email.const_data().c_str(), req->email.const_data().length());
576
577     sprintf(str, "<email value=\"%s\"/>", email);
578     strcat(r, str);
579     delete[] email;
580     }
581
582 if (!req->phone.res_empty())
583     {
584     int len = req->note.const_data().length() * 2 + 1;
585     char * phone = new char[len];
586     memset(phone, 0, len);
587
588     Encode12(phone, req->phone.const_data().c_str(), req->phone.const_data().length());
589
590     sprintf(str, "<phone value=\"%s\"/>", phone);
591     strcat(r, str);
592     delete[] phone;
593     }
594
595 if (!req->group.res_empty())
596     {
597     int len = req->note.const_data().length() * 2 + 1;
598     char * group = new char[len];
599     memset(group, 0, len);
600
601     Encode12(group, req->group.const_data().c_str(), req->group.const_data().length());
602
603     sprintf(str, "<group value=\"%s\"/>", group);
604     strcat(r, str);
605     delete[] group;
606     }
607
608 for (int i = 0; i < USERDATA_NUM; i++)
609     {
610     if (!req->ud[i].res_empty())
611         {
612         int len = req->ud[i].const_data().length() * 2 + 1;
613         char * ud = new char[len];
614         memset(ud, 0, len);
615
616         Encode12(ud, req->ud[i].const_data().c_str(), req->ud[i].const_data().length());
617
618         sprintf(str, "<userdata%d value=\"%s\"/>", i, ud);
619         strcat(r, str);
620         delete[] ud;
621         }
622     }
623
624 strcat(r, "</SetUser>\n");
625 }
626 //-----------------------------------------------------------------------------
627 int CheckParameters(REQUEST * req)
628 {
629 int u = false;
630 int d = false;
631 int ud = false;
632 int a = !req->admLogin.res_empty()
633     && !req->admPasswd.res_empty()
634     && !req->server.res_empty()
635     && !req->port.res_empty()
636     && !req->login.res_empty();
637
638 int b = !req->cash.res_empty()
639     || !req->setCash.res_empty()
640     || !req->credit.res_empty()
641     || !req->prepaidTraff.res_empty()
642     || !req->tariff.res_empty()
643     || !req->usrMsg.res_empty()
644     || !req->usrPasswd.res_empty()
645
646     || !req->note.res_empty()
647     || !req->name.res_empty()
648     || !req->address.res_empty()
649     || !req->email.res_empty()
650     || !req->phone.res_empty()
651     || !req->group.res_empty();
652
653 for (int i = 0; i < DIR_NUM; i++)
654     {
655     if (req->u[i].res_empty())
656         {
657         u = true;
658         break;
659         }
660     }
661
662 for (int i = 0; i < DIR_NUM; i++)
663     {
664     if (req->d[i].res_empty())
665         {
666         d = true;
667         break;
668         }
669     }
670
671 for (int i = 0; i < DIR_NUM; i++)
672     {
673     if (req->ud[i].res_empty())
674         {
675         ud = true;
676         break;
677         }
678     }
679
680
681 //printf("a=%d, b=%d, u=%d, d=%d ud=%d\n", a, b, u, d, ud);
682 return a && (b || u || d || ud);
683 }
684 //-----------------------------------------------------------------------------
685 int CheckParametersGet(REQUEST * req)
686 {
687 return CheckParameters(req);
688 }
689 //-----------------------------------------------------------------------------
690 int CheckParametersSet(REQUEST * req)
691 {
692 return CheckParameters(req);
693 }
694 //-----------------------------------------------------------------------------
695 int mainGet(int argc, char **argv)
696 {
697 int c;
698 REQUEST req;
699 RESETABLE<string>   t1;
700
701 char * short_options_get = "s:p:a:w:u:crtmodieNADLPG";
702 int option_index = -1;
703
704 while (1)
705     {
706     option_index = -1;
707     c = getopt_long(argc, argv, short_options_get, long_options_get, &option_index);
708     if (c == -1)
709         break;
710
711     switch (c)
712         {
713         case 's': //server
714             req.server = optarg;
715             break;
716
717         case 'p': //port
718             req.port = ParseServerPort(optarg);
719             //req.portReq = 1;
720             break;
721
722         case 'a': //admin
723             req.admLogin = ParseAdminLogin(optarg);
724             break;
725
726         case 'w': //admin password
727             req.admPasswd = ParsePassword(optarg);
728             break;
729
730         case 'o': //change user password
731             req.usrPasswd = ParsePassword(optarg);
732             break;
733
734         case 'u': //user
735             req.login = ParseUser(optarg);
736             break;
737
738         case 'c': //get cash
739             req.cash = 1;
740             break;
741
742         case 'r': //credit
743             req.credit = 1;
744             break;
745
746         case 'd': //down
747             req.down = 1;
748             break;
749
750         case 'i': //passive
751             req.passive = 1;
752             break;
753
754         case 't': //tariff
755             req.tariff = " ";
756             break;
757
758         case 'e': //Prepaid Traffic
759             req.prepaidTraff = 1;
760             break;
761
762         case 'N': //Note
763             req.note = " ";
764             break;
765
766         case 'A': //nAme
767             req.name = " ";
768             break;
769
770         case 'D': //aDdress
771             req.address =" ";
772             break;
773
774         case 'L': //emaiL
775             req.email = " ";
776             break;
777
778         case 'P': //phone
779             req.phone = " ";
780             break;
781
782         case 'G': //Group
783             req.group = " ";
784             break;
785
786         case 500: //U
787         case 501:
788         case 502:
789         case 503:
790         case 504:
791         case 505:
792         case 506:
793         case 507:
794         case 508:
795         case 509:
796             //printf("U%d\n", c - 500);
797             req.u[c - 500] = 1;
798             break;
799
800         case 600: //D
801         case 601:
802         case 602:
803         case 603:
804         case 604:
805         case 605:
806         case 606:
807         case 607:
808         case 608:
809         case 609:
810             //printf("D%d\n", c - 600);
811             req.d[c - 600] = 1;
812             break;
813
814         case 700: //UserData
815         case 701:
816         case 702:
817         case 703:
818         case 704:
819         case 705:
820         case 706:
821         case 707:
822         case 708:
823         case 709:
824             //printf("UD%d\n", c - 700);
825             req.ud[c - 700] = " ";
826             break;
827
828         case '?':
829             //printf ("Unknown option \n");
830             break;
831
832         default:
833             printf ("?? getopt returned character code 0%o ??\n", c);
834         }
835     }
836
837 if (optind < argc)
838     {
839     printf ("non-option ARGV-elements: ");
840     while (optind < argc)
841         printf ("%s ", argv[optind++]);
842     UsageInfo();
843     exit(PARAMETER_PARSING_ERR_CODE);
844     }
845
846 if (CheckParametersGet(&req) == 0)
847     {
848     //printf("Parameter needed\n");
849     UsageInfo();
850     exit(PARAMETER_PARSING_ERR_CODE);
851     }
852
853
854 const int rLen = 20000;
855 char rstr[rLen];
856 memset(rstr, 0, rLen);
857
858 CreateRequestGet(&req, rstr);
859 Process(req.server, req.port, req.admLogin, req.admPasswd, rstr, ParseReplyGet);
860
861 return 0;
862 }
863 //-----------------------------------------------------------------------------
864 int mainSet(int argc, char **argv)
865 {
866 string str;
867
868 int c;
869 REQUEST req;
870
871 RESETABLE<string>   t1;
872
873 char * short_options_set = "s:p:a:w:u:c:r:t:m:o:d:i:e:v:nlN:A:D:L:P:G:";
874
875 while (1)
876     {
877     int option_index = -1;
878
879     c = getopt_long(argc, argv, short_options_set, long_options_set, &option_index);
880     if (c == -1)
881         break;
882
883     switch (c)
884         {
885         case 's': //server
886             req.server = optarg;
887             break;
888
889         case 'p': //port
890             req.port = ParseServerPort(optarg);
891             //req.portReq = 1;
892             break;
893
894         case 'a': //admin
895             req.admLogin = ParseAdminLogin(optarg);
896             break;
897
898         case 'w': //admin password
899             req.admPasswd = ParsePassword(optarg);
900             break;
901
902         case 'o': //change user password
903             req.usrPasswd = ParsePassword(optarg);
904             break;
905
906         case 'u': //user
907             req.login = ParseUser(optarg);
908             break;
909
910         case 'c': //add cash
911             req.cash = ParseCash(optarg, &req.message);
912             break;
913
914         case 'v': //set cash
915             req.setCash = ParseCash(optarg, &req.message);
916             break;
917
918         case 'r': //credit
919             req.credit = ParseCredit(optarg);
920             break;
921
922         case 'd': //down
923             req.down = ParseDownPassive(optarg);
924             break;
925
926         case 'i': //passive
927             req.passive = ParseDownPassive(optarg);
928             break;
929
930         case 't': //tariff
931             req.tariff = ParseTariff(optarg, req.chgTariff);
932             break;
933
934         case 'm': //message
935             //ParseMessage(optarg, &req.usrMsg);
936             req.usrMsg = optarg;
937             break;
938
939         case 'e': //Prepaid Traffic
940             req.prepaidTraff = ParsePrepaidTraffic(optarg);
941             break;
942
943         case 'n': //Create User
944             req.createUser = true;
945             break;
946
947         case 'l': //Delete User
948             req.deleteUser = true;
949             break;
950
951         case 'N': //Note
952             ParseAnyString(optarg, &str);
953             req.note = str;
954             break;
955
956         case 'A': //nAme
957             ParseAnyString(optarg, &str);
958             req.name = str;
959             break;
960
961         case 'D': //aDdress
962             ParseAnyString(optarg, &str);
963             req.address = str;
964             break;
965
966         case 'L': //emaiL
967             ParseAnyString(optarg, &str);
968             req.email = str;
969             break;
970
971         case 'P': //phone
972             ParseAnyString(optarg, &str);
973             req.phone = str;
974             break;
975
976         case 'G': //Group
977             ParseAnyString(optarg, &str);
978             req.group = str;
979             break;
980
981         case 500: //U
982         case 501:
983         case 502:
984         case 503:
985         case 504:
986         case 505:
987         case 506:
988         case 507:
989         case 508:
990         case 509:
991             //printf("U%d\n", c - 500);
992             req.u[c - 500] = ParseTraff(optarg);
993             break;
994
995         case 600: //D
996         case 601:
997         case 602:
998         case 603:
999         case 604:
1000         case 605:
1001         case 606:
1002         case 607:
1003         case 608:
1004         case 609:
1005             //printf("D%d\n", c - 600);
1006             req.d[c - 600] = ParseTraff(optarg);
1007             break;
1008
1009         case 700: //UserData
1010         case 701:
1011         case 702:
1012         case 703:
1013         case 704:
1014         case 705:
1015         case 706:
1016         case 707:
1017         case 708:
1018         case 709:
1019             ParseAnyString(optarg, &str);
1020             //printf("UD%d\n", c - 700);
1021             req.ud[c - 700] = str;
1022             break;
1023
1024         case '?':
1025             //printf ("Unknown option \n");
1026             break;
1027
1028         default:
1029             printf ("?? getopt returned character code 0%o ??\n", c);
1030         }
1031     }
1032
1033 if (optind < argc)
1034     {
1035     printf ("non-option ARGV-elements: ");
1036     while (optind < argc)
1037         printf ("%s ", argv[optind++]);
1038     UsageConf();
1039     exit(PARAMETER_PARSING_ERR_CODE);
1040     }
1041
1042 if (CheckParametersSet(&req) == 0)
1043     {
1044     //printf("Parameter needed\n");
1045     UsageConf();
1046     exit(PARAMETER_PARSING_ERR_CODE);
1047     }
1048
1049 const int rLen = 20000;
1050 char rstr[rLen];
1051 memset(rstr, 0, rLen);
1052
1053 CreateRequestGet(&req, rstr);
1054 Process(req.server, req.port, req.admLogin, req.admPasswd, rstr, ParseReplySet);
1055 //Process(&req);
1056
1057 return 0;
1058 }
1059 //-----------------------------------------------------------------------------
1060 int main(int argc, char **argv)
1061 {
1062 if (argc <= 2)
1063     {
1064     UsageConf();
1065     exit(PARAMETER_PARSING_ERR_CODE);
1066     }
1067
1068 if (strcmp(argv[1], "get"))
1069     {
1070     return mainGet(argc - 1, argv + 1);
1071     }
1072 else if (strcmp(argv[1], "set"))
1073     {
1074     return mainGet(argc - 1, argv + 1);
1075     }
1076 else
1077     {
1078     UsageConf();
1079     exit(PARAMETER_PARSING_ERR_CODE);
1080     }
1081 return UNKNOWN_ERR_CODE;
1082 }
1083 //-----------------------------------------------------------------------------
1084