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.
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.
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
18 * Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
24 $Date: 2008/05/11 08:15:07 $
36 #include "stg/common.h"
37 #include "stg/netunit.h"
38 #include "stg/request.h"
42 //---------------------------------------------------------------------------
43 int ParseAns(void * data, const char *el, const char **attr)
45 if (strcasecmp(attr[1], "ok") == 0)
49 if (strcasecmp(attr[1], "error") == 0)
53 if (strcasecmp(attr[1], "err") == 0)
59 //---------------------------------------------------------------------------
60 void StartElement(void *data, const char *el, const char **attr)
65 if (ParseAns(data, el, attr) < 0)
67 printf("Unexpected token\n");
68 exit(UNKNOWN_ERR_CODE);
70 if (ParseAns(data, el, attr) == 1)
72 printf("User not found\n");
73 exit(USER_NOT_FOUND_ERR_CODE);
78 //-----------------------------------------------------------------------------
79 void EndElement(void *data, const char *el)
83 //---------------------------------------------------------------------------
84 int ParseReply(void * data, list<string> * ans)
89 parser = XML_ParserCreate(NULL);
93 printf("Couldn't allocate memory for parser\n");
94 exit(UNKNOWN_ERR_CODE);
97 XML_ParserReset(parser, NULL);
98 XML_SetElementHandler(parser, StartElement, EndElement);
100 list<string>::iterator n = ans->begin();
101 while (n != ans->end())
103 size_t len = strlen(n->c_str());
105 if (++n == ans->end())
109 if (XML_Parse(parser, n->c_str(), len, done) == XML_STATUS_ERROR)
111 printf("Parse error at line %d:\n%s\n",
112 XML_GetCurrentLineNumber(parser),
113 XML_ErrorString(XML_GetErrorCode(parser)));
114 exit(UNKNOWN_ERR_CODE);
120 XML_ParserFree(parser);
123 //-----------------------------------------------------------------------------