12 //---------------------------------------------------------------------------
13 int ParseAns(void *, const char *el, const char **attr)
15 if (strcasecmp(el, "ServerInfo") == 0 || strcasecmp(el, "Tariffs") == 0 || strcasecmp(el, "Admins") == 0 || strcasecmp(el, "Users") == 0 || strcasecmp(el, "user") == 0)
19 if (strcasecmp(attr[1], "ok") == 0)
23 if (strcasecmp(attr[1], "error") == 0)
27 if (strcasecmp(attr[1], "err") == 0)
33 //---------------------------------------------------------------------------
34 void StartElement(void *data, const char *el, const char **attr)
36 if (strcasecmp(el, "ServerInfo") == 0 || strcasecmp(el, "Tariffs") == 0 || strcasecmp(el, "Admins") == 0 || strcasecmp(el, "Users") == 0)
38 printf ("<%s>\n", el);
42 if (strcasecmp(el, "tariff") == 0)
44 if (strcasecmp(attr[0], "name") == 0)
46 printf ("<%s %s=\"%s\">\n", el, attr[0], attr[1]);
47 printf ("<%s>%s</%s>\n", attr[0], attr[1], attr[0]);
51 printf ("<%s>%s", el, attr[1]);
56 if (strcasecmp(el, "admin") == 0)
58 printf ("<%s %s=\"%s\">\n", el, attr[0], attr[1]);
62 printf ("<%s>%s</%s>\n", attr[i], attr[i+1], attr[i]);
65 printf ("</admin>\n");
69 if (strcasecmp(el, "user") == 0)
71 if (strcasecmp(attr[0], "login") == 0)
73 printf ("<%s %s=\"%s\">\n", el, attr[0], attr[1]);
74 printf ("<%s>%s</%s>\n", attr[0], attr[1], attr[0]);
78 printf ("<%s>\n", el);
83 if (strncasecmp(el, "dir_name_", 9) == 0 || strcasecmp(el, "address") == 0 || strcasecmp(el, "email") == 0 || strcasecmp(el, "group") == 0 || strcasecmp(el, "note") == 0 || strcasecmp(el, "phone") == 0 || strcasecmp(el, "name") == 0 || strncasecmp(el, "UserData", 8) == 0)
86 str_tmp = new char[strlen(attr[1]) + 1];
87 Decode21(str_tmp, attr[1]);
88 printf ("<%s>%s</%s>\n", el, str_tmp, el);
93 if (strcasecmp(el, "traff") == 0)
95 // printf ("<traff>\n");
101 printf ("<%s>%lld</%s>\n", attr[j], t, attr[j]);
104 // printf ("</traff>\n");
109 printf ("<%s>%s</%s>\n", el, attr[1], el);
114 if (parse_depth == 1)
116 if (ParseAns(data, el, attr) < 0)
118 printf("Unexpected token\n");
119 exit(UNKNOWN_ERR_CODE);
121 if (ParseAns(data, el, attr) == 1)
123 printf("User not found\n");
124 exit(USER_NOT_FOUND_ERR_CODE);
129 //-----------------------------------------------------------------------------
130 void EndElement(void *, const char *el)
133 if (strcasecmp(el, "ServerInfo") == 0 || strcasecmp(el, "Tariffs") == 0 || strcasecmp(el, "Admins") == 0 || strcasecmp(el, "Users") == 0 || strcasecmp(el, "tariff") == 0 || strcasecmp(el, "user") == 0)
135 printf ("</%s>\n", el);
138 //---------------------------------------------------------------------------
139 int ParseReply(void *, list<string> * ans)
140 //int ParseReply(void * data, SLIST * ans)
142 //char answ[ENC_MSG_LEN + 1];
147 parser = XML_ParserCreate(NULL);
151 printf("Couldn't allocate memory for parser\n");
152 exit(UNKNOWN_ERR_CODE);
155 XML_ParserReset(parser, NULL);
156 XML_SetElementHandler(parser, StartElement, EndElement);
158 list<string>::iterator n = ans->begin();
159 while (n != ans->end())
161 len = strlen(n->c_str());
163 if (++n == ans->end())
167 if (XML_Parse(parser, n->c_str(), len, done) == XML_STATUS_ERROR)
170 printf(s, "Parse error at line %d: %s",
171 XML_GetCurrentLineNumber(parser),
172 XML_ErrorString(XML_GetErrorCode(parser)));
173 return st_xml_parse_error;
178 XML_ParserFree(parser);
181 //-----------------------------------------------------------------------------