X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/8c6fa3fbaccc22127280bf77a48fab5a3ee0716e..46b0747592074017ff0ea4b33d4a7194235886e5:/projects/sgconf_xml/main.cpp diff --git a/projects/sgconf_xml/main.cpp b/projects/sgconf_xml/main.cpp deleted file mode 100644 index d43efea4..00000000 --- a/projects/sgconf_xml/main.cpp +++ /dev/null @@ -1,313 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* - * Author : Boris Mikhailenko - */ - -/* -$Revision: 1.2 $ -$Author: nobunaga $ -$Date: 2008/01/05 12:11:34 $ -*/ - -#include "stg/common.h" -#include "stg/netunit.h" -#include "request.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -#define FN_LEN (512) -#define REQ_STR_LEN (300) -char fileName[FN_LEN]; -char strReq[2048]; - -int ParseReply(void * data, list * ans); - -struct option long_options[] = { -{"server", 1, 0, 's'}, //Server -{"port", 1, 0, 'p'}, //Port -{"admin", 1, 0, 'a'}, //Admin -{"admin_pass", 1, 0, 'w'}, //passWord -{"file", 1, 0, 'f'}, //File -{"strreq", 1, 0, 'r'}, //String request -{0, 0, 0, 0}}; - -//----------------------------------------------------------------------------- -int CheckLogin(const char * login) -{ -for (int i = 0; i < (int)strlen(login); i++) - { - if (!(( login[i] >= 'a' && login[i] <= 'z') - || (login[i] >= 'A' && login[i] <= 'Z') - || (login[i] >= '0' && login[i] <= '9') - || login[i] == '_' - || login[i] == '-')) - { - return 1; - } - } -return 0; -} -//----------------------------------------------------------------------------- -short int ParseServerPort(const char * p) -{ -int port; -if (str2x(p, port) != 0) - { - printf("Incorresct server port %s\n", p); - exit(NETWORK_ERR_CODE); - } -return(short)port; -} -//----------------------------------------------------------------------------- -char * ParseAdminLogin(char * adm) -{ -if (CheckLogin(adm)) - { - printf("Incorrect admin login %s\n", adm); - exit(PARAMETER_PARSING_ERR_CODE); - } -return adm; -} -//----------------------------------------------------------------------------- -char * ParsePassword(char * pass) -{ -if (strlen(pass) >= ADM_PASSWD_LEN) - { - printf("Password too big %s\n", pass); - exit(PARAMETER_PARSING_ERR_CODE); - } - -return pass; -} -//----------------------------------------------------------------------------- -void CreateRequest(REQUEST * req, char * r) -{ -r[0] = 0; - -if (!req->strReq.empty()) - { - char str[10024]; - sprintf(str, "%s", req->strReq.const_data().c_str()); - strcat(r, str); - return; - } else - { - FILE *f = fopen(fileName, "rt"); - if (!f) - { - printf("Can't open request file\n"); - exit(PARAMETER_PARSING_ERR_CODE); - } - - char ts[REQ_STR_LEN]; - while (fgets(ts, REQ_STR_LEN, f)) - { - strncat(r, ts, REQ_STR_LEN); - } - fclose(f); - } -} -//----------------------------------------------------------------------------- -int Process(REQUEST * r) -{ -int ret; -char str[2048]; - -NETTRANSACT nt; -nt.SetServer(r->server.const_data().c_str()); -nt.SetServerPort(r->port.const_data()); -nt.SetLogin(r->admLogin.const_data().c_str()); -nt.SetPassword(r->admPasswd.const_data().c_str()); -nt.SetRxCallback(NULL, ParseReply); - -CreateRequest(r, str); - -if ((ret = nt.Connect()) != st_ok) - { - printf("%s\n", nt.GetError().c_str()); - return ret; - } -if ((ret = nt.Transact(str)) != st_ok) - { - printf("%s\n", nt.GetError().c_str()); - return ret; - } -if ((ret = nt.Disconnect()) != st_ok) - { - printf("%s\n", nt.GetError().c_str()); - return ret; - } - -printf("\n"); -return 0; -} -//----------------------------------------------------------------------------- -int CheckParameters(REQUEST * req) -{ -int a = !req->admLogin.empty() - && !req->admPasswd.empty() - && !req->server.empty() - && !req->port.empty(); - -int b = !req->fileReq.empty() - || !req->strReq.empty(); - -return a && b; -} -//----------------------------------------------------------------------------- -void Usage() -{ -printf("Sgconf version: 1.05.9_XML\n\n"); - -printf("Use: sgconf -s -p -a -w -r \n"); -printf("Use: sgconf -s -p -a -w -f \n\n"); - -printf("Request file or string content:\n\n"); - -printf(" \n\n"); - -printf(" \n"); -printf(" \n"); -printf(" \n\n"); - -printf(" \n"); -printf(" Day-Night time for each DIR\n"); -printf(" \n"); -printf(" \n"); -printf(" \n"); -printf(" \n"); -printf(" \n"); -printf(" \n"); -printf(" \n"); -printf(" \n"); -printf(" \n"); -printf(" \n"); -printf(" New TraffType value: [up|down|up+down|max]\n"); -printf(" \n\n"); - -printf(" \n"); -printf(" \n"); -printf(" \n"); -printf(" \n\n"); - -printf(" \n"); -printf(" \n"); -printf(" \n"); -printf(" \n"); -printf(" Checking login and password in database. Return Ok or Err.\n\n"); - -printf(" \n"); -printf(" \n"); -printf(" \n"); -printf(" \n"); -printf(" delayed - change tariff from 1st day of new month; now - change tariff NOW.\n"); -printf(" Encode12() -> value\n"); -printf(" Encode12() -> value\n"); -printf("
Encode12() -> value\n"); -printf(" Encode12() -> value\n"); -printf(" Encode12() -> value\n"); -printf(" Encode12() -> value\n"); -printf(" Encode12() -> value\n"); -printf(" add - add money on account; set - set money on account; Message - message for log\n"); -printf(" \n"); -printf(" \n"); -printf(" \n"); -printf(" 1 - turn ON AlwaysOnline; 0 - turn OFF AlwaysOnline\n"); -printf(" 1 - turn ON Down; 0 - turn OFF Down\n"); -printf(" 1 - turn ON Passive; 0 - turn OFF Passive\n"); -printf(" MU[0...9] - Set upload traffic value; MU[0...9] - Set download traffic value; \n"); -printf(" \n\n"); - -printf(" \n"); -} -//--------------------------------------------------------------------------- -int main(int argc, char **argv) -{ -REQUEST req; - -while (1) - { - int option_index = -1; - - int c = getopt_long(argc, argv, "s:p:a:w:f:r:", long_options, &option_index); - if (c == -1) - break; - - switch (c) - { - case 's': //server - req.server = optarg; - break; - - case 'p': //port - req.port = ParseServerPort(optarg); - break; - - case 'a': //admin - req.admLogin = ParseAdminLogin(optarg); - break; - - case 'w': //admin password - req.admPasswd = ParsePassword(optarg); - break; - - case 'f': //file - strcpy(fileName,optarg); - req.fileReq = 1; - break; - - case 'r': //string request - req.strReq = optarg; - break; - - case '?': - break; - - default: - printf ("?? getopt returned character code 0%o ??\n", c); - } - } - -if (optind < argc) - { - printf ("non-option ARGV-elements: "); - while (optind < argc) - printf ("%s ", argv[optind++]); - printf ("\n"); - exit(PARAMETER_PARSING_ERR_CODE); - } - -if (CheckParameters(&req) == 0) - { - Usage(); - exit(PARAMETER_PARSING_ERR_CODE); - } - -Process(&req); - -return 0; -} -//----------------------------------------------------------------------------- -