/* * The entry point for the parser. * Returns nonzero if there was an error during parsing. */ static int xml_parseConfiguration(char *buf, int len) { XMLCDocumentHandler handler; WOXMLEdits config; XMLCParser *parser; int error = 0, i; /* initialize the config struct */ config.current_element = NULL; config.new_apps = wolist_new(16); config.current_app = NULL; config.current_app_instances = NULL; config.current_instance = NULL; config.new_app_instances = wolist_new(16); config.error = 0; config.errorLocation = buf; if (len == 0) return 1; /* no content is considered an error */ /* Set up a new document handler struct for the parser */ memcpy(&handler, &_document, sizeof(XMLCDocumentHandler)); handler.document = (XMLCDocument *)(&config); /* set up and invoke the xml parser */ parser = xmlcParserInit(); xmlcTokenizerSetBuffer(parser->tokenizer, buf, len); xmlcParserSetPreserveWhiteSpace(parser, 0); error = (int)xmlcParserParse(parser, &handler); if (error != 0) { /* config error */ WOLog(WO_ERR,"Error parsing configuration: %s", xmlcParserErrorDescription(error)); if ((intptr_t)config.errorLocation < (intptr_t)buf + len) { char *badconfig = WOMALLOC((len+1)*sizeof(char)); strncpy(badconfig, buf, len); badconfig[len] = '\0'; WOLog(WO_ERR,"Error near:\n%s", config.errorLocation); WOFREE(badconfig); } } else { /* * load the new settings... */ if (config.new_apps) for (i=0; i<wolist_count(config.new_apps); i++) ac_updateApplication((strtbl *)wolist_elementAt(config.new_apps, i), (list *)wolist_elementAt(config.new_app_instances, i)); } /* clean up and return */ freeWOXMLEdits(&config); xmlcParserDealloc(parser); return error; }
/* * Called from the xml parser. * Here is where we begin parsing <application>... or <instance>... * or <adaptor>... */ static void createElement(XMLCDocument *document, const XMLCCharacter *name, const unsigned int length) { WOXMLEdits *config = (WOXMLEdits *)document; if (config->error != 0) /* would be nice to tell parser to stop */ return; config->errorLocation = name; if (length == 7 && strncasecmp(name, "adaptor", length) == 0) { /* do nothing; don't generate a warning */ } else if (length == 11 && strncasecmp(name, "application", length) == 0) { /* begin <application> */ if (config->current_element != NULL) { WOLog(WO_ERR,"Error parsing config: found unexpected <application> tag"); config->error = 1; return; } /* create new app settings dictionary, instance list, and set current_element to the app dictionary*/ config->current_app = st_new(8); wolist_add(config->new_apps, config->current_app); config->current_app_instances = wolist_new(8); wolist_add(config->new_app_instances, config->current_app_instances); config->current_element = config->current_app; } else if (length == 8 && strncasecmp(name, "instance", length) == 0) { /* begin <instance> */ if (config->current_element != config->current_app || config->current_app == NULL) { WOLog(WO_ERR,"Error parsing config: found unexpected <instance> tag"); config->error = 1; return; } /* create new instance settings dictionary and set current_element to point to it */ config->current_instance = st_new(8); wolist_add(config->current_app_instances, config->current_instance); config->current_element = config->current_instance; } else { /* Got something unexpected. Ignore the tag. */ char *buffer = WOMALLOC(length+1); strncpy(buffer,name,length); buffer[length] = '\0'; WOLog(WO_WARN,"Unknown tag in XML: \"%s\"",buffer); config->current_element = NULL; WOFREE(buffer); } return; }
void *sha_setLocalDataForKey(ShmemArray *array, unsigned int elementNumber, const char *key, void *data, sha_clearLocalDataCallback clearCallback) { void *oldValue = NULL; if (elementNumber < array->elementCount) { if (!array->elements[elementNumber].localData) array->elements[elementNumber].localData = sd_new(1); oldValue = sd_add(array->elements[elementNumber].localData, key, data); if (clearCallback != NULL) { if (!array->elements[elementNumber].localDataCleanupCallbacks) array->elements[elementNumber].localDataCleanupCallbacks = wolist_new(1); if (wolist_indexOf(array->elements[elementNumber].localDataCleanupCallbacks, (void *)clearCallback) == wolist_elementNotFound) wolist_add(array->elements[elementNumber].localDataCleanupCallbacks, (void *)clearCallback); } } return oldValue; }