7 const int pt_mega = 1024 * 1024;
 
   8 //-----------------------------------------------------------------------------
 
  10 //-----------------------------------------------------------------------------
 
  11 int PARSER_GET_TARIFFS::ParseStart(void *, const char *el, const char **)
 
  13 if (strcasecmp(el, "GetTariffs") == 0)
 
  19 //-----------------------------------------------------------------------------
 
  20 int PARSER_GET_TARIFFS::ParseEnd(void *, const char *el)
 
  22 if (strcasecmp(el, "GetTariffs") == 0)
 
  29 //-----------------------------------------------------------------------------
 
  30 void PARSER_GET_TARIFFS::CreateAnswer()
 
  36 //answerList->clear();
 
  37 answerList->erase(answerList->begin(), answerList->end());
 
  39 answerList->push_back("<Tariffs>");
 
  40 int h = tariffs->OpenSearch();
 
  43 while (tariffs->SearchNext(h, &td) == 0)
 
  45     s = "<tariff name=\"" + td.tariffConf.name + "\">";
 
  46     //printfd(__FILE__, "%s\n", s.c_str());
 
  47     answerList->push_back(s);
 
  49     for (int j = 0; j < DIR_NUM; j++)
 
  51         hd = td.dirPrice[j].hDay;
 
  52         md = td.dirPrice[j].mDay;
 
  54         hn = td.dirPrice[j].hNight;
 
  55         mn = td.dirPrice[j].mNight;
 
  57         strprintf(&s, "<Time%d value=\"%d:%d-%d:%d\"/>", j, hd, md, hn, mn);
 
  58         answerList->push_back(s);
 
  61     strprintf(&s, "    <PriceDayA value=\"");
 
  62     for (int i = 0; i < DIR_NUM; i++)
 
  64         snprintf(vs, 100, "%.5f%s", td.dirPrice[i].priceDayA * pt_mega, i+1 == DIR_NUM?"":"/");
 
  68     answerList->push_back(s);
 
  70     strprintf(&s, "    <PriceDayB value=\"");
 
  71     for (int i = 0; i < DIR_NUM; i++)
 
  73         snprintf(vs, 100, "%.5f%s", td.dirPrice[i].priceDayB * pt_mega, i+1 == DIR_NUM?"":"/");
 
  77     answerList->push_back(s);
 
  79     strprintf(&s, "    <PriceNightA value=\"");
 
  80     for (int i = 0; i < DIR_NUM; i++)
 
  82         snprintf(vs, 100, "%.5f%s", td.dirPrice[i].priceNightA * pt_mega, i+1 == DIR_NUM?"":"/");
 
  86     answerList->push_back(s);
 
  88     strprintf(&s, "    <PriceNightB value=\"");
 
  89     for (int i = 0; i < DIR_NUM; i++)
 
  91         snprintf(vs, 100, "%.5f%s", td.dirPrice[i].priceNightB * pt_mega, i+1 == DIR_NUM?"":"/");
 
  95     answerList->push_back(s);
 
  97     strprintf(&s, "    <Threshold value=\"");
 
  98     for (int i = 0; i < DIR_NUM; i++)
 
 100         snprintf(vs, 100, "%d%s", td.dirPrice[i].threshold, i+1 == DIR_NUM?"":"/");
 
 104     answerList->push_back(s);
 
 106     strprintf(&s, "    <SinglePrice value=\"");
 
 107     for (int i = 0; i < DIR_NUM; i++)
 
 109         snprintf(vs, 100, "%d%s", td.dirPrice[i].singlePrice, i+1 == DIR_NUM?"":"/");
 
 113     answerList->push_back(s);
 
 115     strprintf(&s, "    <NoDiscount value=\"");
 
 116     for (int i = 0; i < DIR_NUM; i++)
 
 118         snprintf(vs, 100, "%d%s", td.dirPrice[i].noDiscount, i+1 == DIR_NUM?"":"/");
 
 122     answerList->push_back(s);
 
 124     strprintf(&s, "    <Fee value=\"%.5f\"/>", td.tariffConf.fee);
 
 125     answerList->push_back(s);
 
 126     //printfd(__FILE__, "%s\n", s.c_str());
 
 128     strprintf(&s, "    <PassiveCost value=\"%.5f\"/>", td.tariffConf.passiveCost);
 
 129     answerList->push_back(s);
 
 131     strprintf(&s, "    <Free value=\"%.5f\"/>", td.tariffConf.free);
 
 132     answerList->push_back(s);
 
 134     switch (td.tariffConf.traffType)
 
 137             answerList->push_back("<TraffType value=\"up\"/>");
 
 140             answerList->push_back("<TraffType value=\"down\"/>");
 
 143             answerList->push_back("<TraffType value=\"up+down\"/>");
 
 146             answerList->push_back("<TraffType value=\"max\"/>");
 
 150     answerList->push_back("</tariff>");
 
 152 tariffs->CloseSearch(h);
 
 153 answerList->push_back("</Tariffs>");
 
 155 //-----------------------------------------------------------------------------
 
 157 //-----------------------------------------------------------------------------
 
 158 int PARSER_ADD_TARIFF::ParseStart(void *, const char *el, const char **attr)
 
 160 if (strcasecmp(el, "AddTariff") == 0)
 
 164         tariffToAdd = attr[1];
 
 170 //-----------------------------------------------------------------------------
 
 171 int PARSER_ADD_TARIFF::ParseEnd(void *, const char *el)
 
 173 if (strcasecmp(el, "AddTariff") == 0)
 
 180 //-----------------------------------------------------------------------------
 
 181 void PARSER_ADD_TARIFF::CreateAnswer()
 
 183 //answerList->clear();
 
 184 answerList->erase(answerList->begin(), answerList->end());
 
 186 if (tariffs->Add(tariffToAdd, *currAdmin) == 0)
 
 188     answerList->push_back("<AddTariff Result=\"Ok\"/>");
 
 193     strprintf(&s, "<AddTariff Result=\"Error. %s\"/>", tariffs->GetStrError().c_str());
 
 194     answerList->push_back(s);
 
 197 //-----------------------------------------------------------------------------
 
 199 //-----------------------------------------------------------------------------
 
 200 int PARSER_DEL_TARIFF::ParseStart(void *, const char *el, const char **attr)
 
 203 if (strcasecmp(el, "DelTariff") == 0)
 
 205     tariffToDel = attr[1];
 
 210 //-----------------------------------------------------------------------------
 
 211 int PARSER_DEL_TARIFF::ParseEnd(void *, const char *el)
 
 213 if (strcasecmp(el, "DelTariff") == 0)
 
 220 //-----------------------------------------------------------------------------
 
 221 void PARSER_DEL_TARIFF::CreateAnswer()
 
 223 //answerList->clear();
 
 224 answerList->erase(answerList->begin(), answerList->end());
 
 226 if (tariffs->Del(tariffToDel, *currAdmin) == 0)
 
 228     answerList->push_back("<DelTariff Result=\"Ok\"/>");
 
 233     strprintf(&s, "<DelTariff Result=\"Error. %s\"/>", tariffs->GetStrError().c_str());
 
 234     answerList->push_back(s);
 
 237 //-----------------------------------------------------------------------------
 
 238 //-----------------------------------------------------------------------------
 
 240 //-----------------------------------------------------------------------------
 
 241 //-----------------------------------------------------------------------------
 
 242 int PARSER_CHG_TARIFF::ParseSlashedIntParams(int paramsNum, const string & s, int * params)
 
 244 char * str = new char[s.size() + 1];
 
 246 strcpy(str, s.c_str());
 
 247 p = strtok(str, "/");
 
 249 for (int i = 0; i < paramsNum; i++)
 
 257     if (str2x(p, params[i]) != 0)
 
 263     p = strtok(NULL, "/");
 
 269 //-----------------------------------------------------------------------------
 
 270 int PARSER_CHG_TARIFF::ParseSlashedDoubleParams(int paramsNum, const string & s, double * params)
 
 272 char * str = new char[s.size() + 1];
 
 274 strcpy(str, s.c_str());
 
 275 p = strtok(str, "/");
 
 277 for (int i = 0; i < paramsNum; i++)
 
 285     if (strtodouble2(p, params[i]) != 0)
 
 291     p = strtok(NULL, "/");
 
 297 //-----------------------------------------------------------------------------
 
 298 int PARSER_CHG_TARIFF::ParseStart(void *, const char *el, const char **attr)
 
 301 double price[DIR_NUM];
 
 307     if (strcasecmp(el, "SetTariff") == 0)
 
 309         td.tariffConf.name = attr[1];
 
 317     if (strcasecmp(el, "PriceDayA") == 0)
 
 320         if (ParseSlashedDoubleParams(DIR_NUM, s, price) == 0)
 
 321             for (int j = 0; j < DIR_NUM; j++)
 
 322                 td.dirPrice[j].priceDayA = price[j] / pt_mega;
 
 326     if (strcasecmp(el, "PriceDayB") == 0)
 
 329         if (ParseSlashedDoubleParams(DIR_NUM, s, price) == 0)
 
 330             for (int j = 0; j < DIR_NUM; j++)
 
 331                 td.dirPrice[j].priceDayB = price[j] / pt_mega;
 
 336     if (strcasecmp(el, "PriceNightA") == 0)
 
 339         if (ParseSlashedDoubleParams(DIR_NUM, s, price) == 0)
 
 340             for (int j = 0; j < DIR_NUM; j++)
 
 341                 td.dirPrice[j].priceNightA = price[j] / pt_mega;
 
 345     if (strcasecmp(el, "PriceNightB") == 0)
 
 348         if (ParseSlashedDoubleParams(DIR_NUM, s, price) == 0)
 
 349             for (int j = 0; j < DIR_NUM; j++)
 
 350                 td.dirPrice[j].priceNightB = price[j] / pt_mega;
 
 354     if (strcasecmp(el, "Threshold") == 0)
 
 357         if (ParseSlashedIntParams(DIR_NUM, s, t) == 0)
 
 358             for (int j = 0; j < DIR_NUM; j++)
 
 359                 td.dirPrice[j].threshold = t[j];
 
 363     if (strcasecmp(el, "SinglePrice") == 0)
 
 366         if (ParseSlashedIntParams(DIR_NUM, s, t) == 0)
 
 367             for (int j = 0; j < DIR_NUM; j++)
 
 368                 td.dirPrice[j].singlePrice = t[j];
 
 372     if (strcasecmp(el, "NoDiscount") == 0)
 
 375         if (ParseSlashedIntParams(DIR_NUM, s, t) == 0)
 
 376             for (int j = 0; j < DIR_NUM; j++)
 
 377                 td.dirPrice[j].noDiscount = t[j];
 
 381     for (int j = 0; j < DIR_NUM; j++)
 
 383         snprintf(st, 50, "Time%d", j);
 
 384         if (strcasecmp(el, st) == 0)
 
 387             if (ParseTariffTimeStr(attr[1], h1, m1, h2, m2) == 0)
 
 389                 td.dirPrice[j].hDay = h1;
 
 390                 td.dirPrice[j].mDay = m1;
 
 391                 td.dirPrice[j].hNight = h2;
 
 392                 td.dirPrice[j].mNight = m2;
 
 398     if (strcasecmp(el, "Fee") == 0)
 
 401         if (strtodouble2(attr[1], fee) == 0)
 
 402             td.tariffConf.fee = fee;
 
 406     if (strcasecmp(el, "PassiveCost") == 0)
 
 409         if (strtodouble2(attr[1], pc) == 0)
 
 410             td.tariffConf.passiveCost = pc;
 
 413     if (strcasecmp(el, "Free") == 0)
 
 416         if (strtodouble2(attr[1], free) == 0)
 
 417             td.tariffConf.free = free;
 
 421     if (strcasecmp(el, "TraffType") == 0)
 
 423         if (strcasecmp(attr[1], "up") == 0)
 
 425             td.tariffConf.traffType = TRAFF_UP;
 
 429         if (strcasecmp(attr[1], "down") == 0)
 
 431             td.tariffConf.traffType = TRAFF_DOWN;
 
 434         if (strcasecmp(attr[1], "up+down") == 0)
 
 436             td.tariffConf.traffType = TRAFF_UP_DOWN;
 
 439         if (strcasecmp(attr[1], "max") == 0)
 
 441             td.tariffConf.traffType = TRAFF_MAX;
 
 449 //-----------------------------------------------------------------------------
 
 450 int PARSER_CHG_TARIFF::ParseEnd(void *, const char *el)
 
 454     if (strcasecmp(el, "SetTariff") == 0)
 
 465 //-----------------------------------------------------------------------------
 
 466 void PARSER_CHG_TARIFF::CreateAnswer()
 
 468 answerList->erase(answerList->begin(), answerList->end());
 
 470 if (!td.tariffConf.name.data().empty())
 
 472     TARIFF_DATA tariffData = td.GetData();
 
 473     if (tariffs->Chg(tariffData, *currAdmin) == 0)
 
 475         answerList->push_back("<SetTariff Result=\"ok\"/>");
 
 481         strprintf(&s, "<SetTariff Result=\"Change tariff error! %s\"/>", tariffs->GetStrError().c_str());
 
 482         answerList->push_back(s);
 
 486 answerList->push_back("<SetTariff Result=\"Change tariff error!\"/>");
 
 488 //-----------------------------------------------------------------------------