int config_parse_file(const char *filename, ice_config_t *configuration) { xmlDocPtr doc; xmlNodePtr node; if (filename == NULL || strcmp(filename, "") == 0) return CONFIG_EINSANE; doc = xmlParseFile(filename); if (doc == NULL) { return CONFIG_EPARSE; } node = xmlDocGetRootElement(doc); if (node == NULL) { xmlFreeDoc(doc); xmlCleanupParser(); return CONFIG_ENOROOT; } if (xmlStrcmp(node->name, XMLSTR("icecast")) != 0) { xmlFreeDoc(doc); xmlCleanupParser(); return CONFIG_EBADROOT; } config_init_configuration(configuration); configuration->config_filename = (char *)strdup(filename); _parse_root (node, configuration); xmlFreeDoc(doc); return 0; }
/* Get long name for file, if possible (assumed to be absolute). */ BOOL win32_get_long_filename (char * name, char * buf, int size) { char * o = buf; char * p; char * q; char full[ MAX_PATH ]; int len; len = strlen (name); if (len >= MAX_PATH) return FALSE; /* Use local copy for destructive modification. */ memcpy (full, name, len+1); unixtodos_filename (full); /* Copy root part verbatim. */ len = _parse_root (full, &p); memcpy (o, full, len); o += len; size -= len; do { q = p; p = strchr (q, '\\'); if (p) *p = '\0'; len = get_long_basename (full, o, size); if (len > 0) { o += len; size -= len; if (p != NULL) { *p++ = '\\'; if (size < 2) return FALSE; *o++ = '\\'; size--; *o = '\0'; } } else return FALSE; } while (p != NULL && *p); return TRUE; }
int config_read(const char *fn) { xmlDocPtr doc; xmlNodePtr node; if (fn == NULL || strcmp(fn, "") == 0) return -1; doc = xmlParseFile(fn); if (doc == NULL) return -1; node = xmlDocGetRootElement(doc); if (node == NULL || strcmp(node->name, "ices") != 0) { xmlFreeDoc(doc); return 0; } _parse_root(ices_config, doc, node->xmlChildrenNode); xmlFreeDoc(doc); return 1; }