X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/afb00c045e0ea58e39c0d7a7921bedbf26d1860d..862223ebc00e6153adb8f02f9c3b117547d16314:/projects/sgconf_xml/main.cpp diff --git a/projects/sgconf_xml/main.cpp b/projects/sgconf_xml/main.cpp index 751a7537..d43efea4 100644 --- a/projects/sgconf_xml/main.cpp +++ b/projects/sgconf_xml/main.cpp @@ -24,6 +24,10 @@ $Author: nobunaga $ $Date: 2008/01/05 12:11:34 $ */ +#include "stg/common.h" +#include "stg/netunit.h" +#include "request.h" + #include #include #include @@ -33,16 +37,11 @@ $Date: 2008/01/05 12:11:34 $ #include #include -#include "request.h" -#include "common.h" -#include "netunit.h" - #define FN_LEN (512) #define REQ_STR_LEN (300) char fileName[FN_LEN]; char strReq[2048]; -//int ParseReply(void * data, SLIST * ans); int ParseReply(void * data, list * ans); struct option long_options[] = { @@ -105,19 +104,17 @@ return pass; //----------------------------------------------------------------------------- void CreateRequest(REQUEST * req, char * r) { -char str[10024]; r[0] = 0; -if (!req->strReq.res_empty()) +if (!req->strReq.empty()) { + char str[10024]; sprintf(str, "%s", req->strReq.const_data().c_str()); strcat(r, str); return; } else { - FILE *f; - f = NULL; - f = fopen(fileName, "rt"); + FILE *f = fopen(fileName, "rt"); if (!f) { printf("Can't open request file\n"); @@ -135,13 +132,12 @@ if (!req->strReq.res_empty()) //----------------------------------------------------------------------------- int Process(REQUEST * r) { -char errorMsg[MAX_ERR_STR_LEN]; int ret; char str[2048]; NETTRANSACT nt; nt.SetServer(r->server.const_data().c_str()); -nt.SetServerPort(r->port); +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); @@ -150,20 +146,17 @@ CreateRequest(r, str); if ((ret = nt.Connect()) != st_ok) { - strncpy(errorMsg, nt.GetError(), MAX_ERR_STR_LEN); - printf("%s", errorMsg); + printf("%s\n", nt.GetError().c_str()); return ret; } if ((ret = nt.Transact(str)) != st_ok) { - strncpy(errorMsg, nt.GetError(), MAX_ERR_STR_LEN); - printf("%s", errorMsg); + printf("%s\n", nt.GetError().c_str()); return ret; } if ((ret = nt.Disconnect()) != st_ok) { - strncpy(errorMsg, nt.GetError(), MAX_ERR_STR_LEN); - printf("%s", errorMsg); + printf("%s\n", nt.GetError().c_str()); return ret; } @@ -173,13 +166,13 @@ return 0; //----------------------------------------------------------------------------- int CheckParameters(REQUEST * req) { -int a = !req->admLogin.res_empty() - && !req->admPasswd.res_empty() - && !req->server.res_empty() - && !req->port.res_empty(); +int a = !req->admLogin.empty() + && !req->admPasswd.empty() + && !req->server.empty() + && !req->port.empty(); -int b = !req->fileReq.res_empty() - || !req->strReq.res_empty(); +int b = !req->fileReq.empty() + || !req->strReq.empty(); return a && b; } @@ -250,18 +243,15 @@ printf(" \n\n"); printf(" \n"); } //--------------------------------------------------------------------------- -int main (int argc, char **argv) +int main(int argc, char **argv) { -int c; -//int digit_optind = 0; REQUEST req; while (1) { - //int this_option_optind = optind ? optind : 1; int option_index = -1; - c = getopt_long(argc, argv, "s:p:a:w:f:r:", long_options, &option_index); + int c = getopt_long(argc, argv, "s:p:a:w:f:r:", long_options, &option_index); if (c == -1) break; @@ -273,7 +263,6 @@ while (1) case 'p': //port req.port = ParseServerPort(optarg); - //req.portReq = 1; break; case 'a': //admin @@ -294,7 +283,6 @@ while (1) break; case '?': - //printf ("Unknown option \n"); break; default: @@ -313,7 +301,6 @@ if (optind < argc) if (CheckParameters(&req) == 0) { - //printf("Parameter needed\n"); Usage(); exit(PARAMETER_PARSING_ERR_CODE); }