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"
45 //---------------------------------------------------------------------------
46 int ParseAns(void * data, const char *el, const char **attr)
48 if (strcasecmp(attr[1], "ok") == 0)
52 if (strcasecmp(attr[1], "error") == 0)
56 if (strcasecmp(attr[1], "err") == 0)
62 //---------------------------------------------------------------------------
63 void StartElement(void *data, const char *el, const char **attr)
68 if (ParseAns(data, el, attr) < 0)
70 printf("Unexpected token\n");
71 exit(UNKNOWN_ERR_CODE);
73 if (ParseAns(data, el, attr) == 1)
75 printf("User not found\n");
76 exit(USER_NOT_FOUND_ERR_CODE);
81 //-----------------------------------------------------------------------------
82 void EndElement(void *data, const char *el)
86 //---------------------------------------------------------------------------
87 int ParseReply(void * data, list<string> * ans)
92 parser = XML_ParserCreate(NULL);
96 printf("Couldn't allocate memory for parser\n");
97 exit(UNKNOWN_ERR_CODE);
100 XML_ParserReset(parser, NULL);
101 XML_SetElementHandler(parser, StartElement, EndElement);
103 list<string>::iterator n = ans->begin();
104 while (n != ans->end())
106 size_t len = strlen(n->c_str());
108 if (++n == ans->end())
112 if (XML_Parse(parser, n->c_str(), len, done) == XML_STATUS_ERROR)
114 printf("Parse error at line %d:\n%s\n",
115 XML_GetCurrentLineNumber(parser),
116 XML_ErrorString(XML_GetErrorCode(parser)));
117 exit(UNKNOWN_ERR_CODE);
123 XML_ParserFree(parser);
126 //-----------------------------------------------------------------------------