Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
54 lines (47 sloc) 1.25 KB
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <libxml/parser.h>
#include "na.h"
#include "config.h"
void parse_config(struct session *session)
{
xmlDocPtr doc;
xmlNodePtr current;
xmlChar *mail, *pass, *browser;
if (!session || !session->config_file)
return;
if (access(session->config_file, R_OK) < 0)
return;
doc = xmlParseFile(session->config_file);
if (!doc)
return;
current = xmlDocGetRootElement(doc);
if (!current)
goto finish;
if (xmlStrcmp(current->name, (const xmlChar *)"na"))
goto finish;
current = current->xmlChildrenNode;
while (current != NULL) {
if (!xmlStrcmp(current->name, (const xmlChar *)"mail")) {
mail = xmlNodeListGetString(doc,
current->xmlChildrenNode, 1);
session->mail = strdup((char *)mail);
xmlFree(mail);
} else if (!xmlStrcmp(current->name, (const xmlChar *)"pass")) {
pass = xmlNodeListGetString(doc,
current->xmlChildrenNode, 1);
session->pass = strdup((char *)pass);
xmlFree(pass);
} else if (!xmlStrcmp(current->name,
(const xmlChar *)"browser")) {
browser = xmlNodeListGetString(doc,
current->xmlChildrenNode, 1);
session->browser = strdup((char *)browser);
xmlFree(browser);
}
current = current->next;
}
finish:
xmlFreeDoc(doc);
}