main.c
/**
 * @brief Given in-memory XML, find the timezone information
 *
 * @param data The in-memory XML document
 * @param ptr A destination pointer to place the null-terminated timezone
 *
 * @return A non-zero value on success
 */
@brief Given in-memory XML, find the timezone information
@param data The in-memory XML document
@param ptr A destination pointer to place the null-terminated timezone

@return A non-zero value on success
@brief Given in - memory XML find the timezone information @param data The in - memory XML document @param ptr A destination pointer to place the null - terminated timezone @return A non - zero value on success
static int parse_tz(smem_t *data, char **ptr) {
  assert(data && ptr);
  xmlDocPtr doc;
  if (!(doc = xmlParseDoc((unsigned char *) data->mem))) {
    fprintf(stderr, "Failed to parse XML\n");
    return 0;
  }
  xmlXPathContextPtr xpathCtx;
  if(!(xpathCtx = xmlXPathNewContext(doc))) {
    fprintf(stderr, "Failed to create new XPath context\n");
    xmlFreeDoc(doc);
    return 0;
  }
  xmlXPathObjectPtr xpathObj =
    xmlXPathEvalExpression((unsigned char *) XPATH_EXPR, xpathCtx);
  assert(xpathObj);
  int ret = 1;
  xmlNodeSetPtr nodes = xpathObj->nodesetval;
  if(!nodes->nodeNr) {
    fprintf(stderr, "Failed to find timezone information\n");
    ret = 0;
  }
  else {
    char *value = (char *) nodes->nodeTab[0]->content;
    *ptr = malloc(strlen(value));
    strcpy(*ptr, value);
    printf("Timezone detected: %s\n", value);
  }
  xmlXPathFreeObject(xpathObj);
  xmlXPathFreeContext(xpathCtx);
  xmlFreeDoc(doc);
  return ret;
}
static int parse_tz ( smem_t * data , char * * ptr ) { assert ( data && ptr ) ; xmlDocPtr doc ; if ( ! ( doc = xmlParseDoc ( ( unsigned char * ) data -> mem ) ) ) { fprintf ( stderr , " \n " ) ; return 0 ; } xmlXPathContextPtr xpathCtx ; if ( ! ( xpathCtx = xmlXPathNewContext ( doc ) ) ) { fprintf ( stderr , " \n " ) ; xmlFreeDoc ( doc ) ; return 0 ; } xmlXPathObjectPtr xpathObj = xmlXPathEvalExpression ( ( unsigned char * ) XPATH_EXPR , xpathCtx ) ; assert ( xpathObj ) ; int ret = 1 ; xmlNodeSetPtr nodes = xpathObj -> nodesetval ; if ( ! nodes -> nodeNr ) { fprintf ( stderr , " \n " ) ; ret = 0 ; } else { char * value = ( char * ) nodes -> nodeTab [ 0 ] -> content ; * ptr = malloc ( strlen ( value ) ) ; strcpy ( * ptr , value ) ; printf ( " \n " , value ) ; } xmlXPathFreeObject ( xpathObj ) ; xmlXPathFreeContext ( xpathCtx ) ; xmlFreeDoc ( doc ) ; return ret ; }
@brief Given in-memory XML, find the timezone information
 @param data The in-memory XML document
 @param ptr A destination pointer to place the null-terminated timezone
@brief Given in - memory XML find the timezone information @param data The in - memory XML document @param ptr A destination pointer to place the null - terminated timezone
// Load the document from memory // Create a context for XPath // Find appropriate nodes // Get the timezone in the XML // Parse the XML // Give some information // Cleanup