예제 #1
0
void clish_xmlnode_print(clish_xmlnode_t *node, FILE *out)
{
	node_t *roxn;
	char *name;

	roxn = xmlnode_to_node(node);
	name = roxml_get_name(roxn, NULL, 0);
	if (name) {
		fprintf(out, "<%s", name);
		roxml_release(name);
		if (roxml_get_attr_nb(roxn)) {
			int attr_count = roxml_get_attr_nb(roxn);
			int attr_pos;
			for (attr_pos = 0; attr_pos < attr_count; ++attr_pos) {
				node_t *attr = roxml_get_attr(roxn, NULL, attr_pos);
				char *n = roxml_get_name(attr, NULL, 0);
				char *v = roxml_get_content(attr, NULL, 0, NULL);
				if (n && v) {
					fprintf(out, " %s='%s'", n, v);
				}
				if (v) 
					roxml_release(v);
				if (n) 
					roxml_release(n);
			}
		}
		fprintf(out, ">");
	}
}
예제 #2
0
int XHCPcmd_LISTGLOBALS (int sockd, int argc, char **argv)
{
    node_t **globalsLst;
    char buffer[XHCP_BUFFER_SZ];
    int sz_buffer;
    int i, nb;
    
    XHCP_printXHCPResponse (sockd, RES_LSTGLVFOL ); // List of global variables follows
    
    if ( (globalsLst = roxml_xpath (rootConfig, "//global", &nb )) !=NULL )
    {
        for (i=0; i<nb; i++)
        {
            char *champ1 = roxml_get_content ( roxml_get_attr (globalsLst[i], "name", 0), buffer, XHCP_BUFFER_SZ, &sz_buffer );
            char *champ2 = roxml_get_content ( roxml_get_attr (globalsLst[i], "value", 0), champ1 + sz_buffer + 1, XHCP_BUFFER_SZ, &sz_buffer );
            
            XHCP_print (sockd, "%s=%s", champ1, champ2);
        }
    }
    
    XHCP_print (sockd, ".");
    return XHCP_EXE_SUCCESS;
}
예제 #3
0
int XHCPcmd_LISTRULES (int sockd, int argc, char **argv)
{
    node_t **rulesNodesLst;
    char buffer[XHCP_BUFFER_SZ];
    int sz_buffer;
    int i, nb;
    
    XHCP_printXHCPResponse (sockd, RES_LSTDTRFOL ); // List of Determinator Rules follows
    
    if ( (rulesNodesLst = roxml_xpath (rootConfig, "//determinator", &nb )) !=NULL )
    {
        for (i=0; i<nb; i++)
        {
            char *champ1 = roxml_get_content ( roxml_get_attr (rulesNodesLst[i], "guid", 0), buffer, XHCP_BUFFER_SZ, &sz_buffer );
            char *champ2 = roxml_get_content ( roxml_get_attr (rulesNodesLst[i], "name", 0), champ1 + sz_buffer + 1, XHCP_BUFFER_SZ, &sz_buffer );
            char *champ3 = roxml_get_content ( roxml_get_attr (rulesNodesLst[i], "enabled", 0), champ2 + sz_buffer + 1, XHCP_BUFFER_SZ, &sz_buffer );
            
            XHCP_print (sockd, "%s\t%s\t%s", champ1, champ2, champ3);
        }
    }
    
    XHCP_print (sockd, ".");
    return XHCP_EXE_SUCCESS;
}
예제 #4
0
char *clish_xmlnode_fetch_attr(clish_xmlnode_t *node,
			       const char *attrname)
{
	node_t *roxn;
	node_t *attr;
	char *content;

	if (!node || !attrname)
		return NULL;

	roxn = xmlnode_to_node(node);
	attr = roxml_get_attr(roxn, (char*)attrname, 0);

	content = roxml_get_content(attr, NULL, 0, NULL);
	if (content) {
		i_decode_and_copy(content, content);
	}
	return content;
}
예제 #5
0
int XHCP_loadConfig (node_t* argXmlConfig)
{
    node_t **result;
    int nb_result;
    char buffer[XHCP_BUFFER_SZ];
    int sz_buffer;
    char *xhcp_fileName;
    
    printf ("Loading XHCP server configuration...\n");
    
    if ( (xhcp_fileName = XHCP_getConfigFile ()) != NULL )
        domConfig = roxml_load_doc (xhcp_fileName);
    else if ( argXmlConfig != NULL )
        domConfig = argXmlConfig;
    else
        Error_Quit ("Unable to find XHCP configuration");
    
    
    /* Time Out */
    result = roxml_xpath ( domConfig, "//XHCPserver/ConnectionTimeOut[@delay]", &nb_result);
    if ( nb_result == 1 )
    {
        char *zaza = roxml_get_content ( roxml_get_attr (result[0], "delay", 0), buffer, XHCP_BUFFER_SZ, &sz_buffer );
        XHCP_connexionTimeOut = atoi (zaza);
        
        if ( XHCP_connexionTimeOut <= 0 )
            XHCP_connexionTimeOut=2;
    }
    else if ( nb_result == 0)
    {
        XHCP_connexionTimeOut = 5;
    }
    else
        Error_Quit ("Erroe parsing XHCP config file (ConnectionTimeOut)");
    
    roxml_release (RELEASE_LAST);
    printf ("XHCP_connexionTimeOut = %d\n", XHCP_connexionTimeOut);
    
    
    return 0;
}
예제 #6
0
파일: xcf_creator.c 프로젝트: Papify/papify
int xcf_creator(int argc, char *project_path) {
	FILE* actor_src;
	int j, k, n,size_of_config, size_of_partitioning, size_of_partition, size_of_papi, len, actor_num, number_of_actions, number_of_events;
	int num = 0;
	node_t *configuration, *partitioning, *partition, *instance, *papi, *actor_instance, *action, *event;
	char *actor_path;

	char *mapping_file_path;

	if ((mapping_file_path = findMappingFile(project_path)) == NULL) {
		printf("Unable to locate a mapping file, make sure you are using the root path to the RVC CAL generated code with the C backend\n");
		exit(1);
	}

	int actors_num = get_actors_num(mapping_file_path);

	configuration = roxml_load_doc(mapping_file_path); //a: LIBROXML node http://www.libroxml.net/public-api.html
	if (configuration == NULL) {
		printf("I/O error when reading mapping file.\n");
		exit(1);
	}
	node_t *papi_root_node = roxml_add_node(configuration, 0, ROXML_ELM_NODE, "Papi", NULL);
	node_t *papi_instance_node, *papi_action_node, *papi_event_node;

	size_of_config = roxml_get_chld_nb(configuration); //a: This function return the number of children for a given node

	if(DEBUG)printf("Found %d configuration\n", size_of_config);


	partitioning = roxml_get_chld(configuration, NULL, 0); //a: This function returns a given child of a node either by name, or the nth child. (node, child name, number of the child to get)
	size_of_partitioning = roxml_get_chld_nb(partitioning); //a: This function return the number of children for a given node
	if(DEBUG)printf("	Found %d partitionings\n", size_of_partitioning);
	for (j = 0; j < size_of_partitioning; j++) {
		partition = roxml_get_chld(partitioning, NULL, j);
		if(DEBUG)printf("		Found partition, id = '%s'\n", roxml_get_content(roxml_get_attr(partition, "id", 0), NULL, 0, &len));
		size_of_partition = roxml_get_chld_nb(partition);
		for (k = 0; k < size_of_partition; k++) {
			instance = roxml_get_chld(partition, NULL, k);
			if(DEBUG)printf("			Found instance, id = '%s'\n", roxml_get_content(roxml_get_attr(instance, "id", 0), NULL, 0, &len));
			papi_instance_node = roxml_add_node(papi_root_node, 0, ROXML_ELM_NODE, "Instance", NULL);
			roxml_add_node(papi_instance_node, 0, ROXML_ATTR_NODE, "id", roxml_get_content(roxml_get_attr(instance, "id", 0), NULL, 0, &len));

			//this goes for every action in the actor:
			actor_path = malloc(strlen(project_path)+strlen(roxml_get_content(roxml_get_attr(instance, "id", 0), NULL, 0, &len))+10);
			strcpy(actor_path,project_path);
			actor_path = strcat(actor_path,"/src/");
			actor_path = strcat(actor_path,roxml_get_content(roxml_get_attr(instance, "id", 0), NULL, 0, &len));
			actor_path = strcat(actor_path,".c");
			printf("opening %s\n", actor_path);
			actor_src = fopen(actor_path,"r");
			put_actions(actor_src, papi_instance_node, papi_action_node, papi_event_node);
			fclose(actor_src);
		}
	}

	char *mapping_file_cpy = malloc(strlen(mapping_file_path)+strlen(".papi.xcf")+1);

	strcpy(mapping_file_cpy, mapping_file_path);
	strcat(mapping_file_cpy, ".papi.xcf");



	//tmp = roxml_add_node(tmp, 0, ROXML_ELM_NODE, "price", "24");
	roxml_commit_changes(configuration, mapping_file_cpy, NULL, 1);
	//roxml_close(configuration);


	// release the last allocated buffer even if no pointer is maintained by the user
	roxml_release(RELEASE_LAST);
	// here no memory leak can occur.
	roxml_close(configuration);


	return 0;
}
예제 #7
0
파일: dictionary.c 프로젝트: pleo/ots
gboolean ots_load_xml_dictionary_buf(OtsArticle* Doc, const char* buffer) {
  char* head_name    = NULL;
  node_t* stem       = NULL;
  node_t* pre        = NULL;
  node_t* post       = NULL;
  node_t* syno       = NULL;        /* synonyms */
  node_t* manual     = NULL;        /* manual   */
  node_t* step1_pre  = NULL;        /* step1    */
  node_t* step1_post = NULL;        /* step1    */
  
  node_t* parse   = NULL;           /* parser rules */
  node_t* pbreak  = NULL;
  node_t* pdbreak = NULL;
  
  node_t* tc_words = NULL;          /* term count dictionary   */
  node_t* tf_words = NULL;          /* term frequency dictionary   */
  
  OtsStemRule* rule = Doc->stem;
  node_t* head = roxml_load_buf((char*)buffer);
  
  if (head == NULL) {
    fprintf(stderr, "empty document\n");
    roxml_release(RELEASE_ALL);
    return (FALSE);
  }
#if DEBUG > 1
  fprintf(stdout, "%d: %s\n", __LINE__, roxml_get_name(head, NULL, 0));
#endif /* DEBUG > 1 */
  if (g_strcmp0(roxml_get_name(head, head_name, 0), (const char*)"dictionary")) {
    fprintf(stderr, "%s\n", head_name);
    roxml_release(RELEASE_ALL);
    roxml_close(head);
    return (FALSE);
  }
  
  stem = roxml_get_chld(head, NULL, 0);
  if(stem == NULL) {
    roxml_release(RELEASE_ALL);
    roxml_close(head);
    return (FALSE);
  }
  ots_get_xml_node(&stem, (const char*)"stemmer");
  
  parse = roxml_get_chld(head, NULL, 0);
  if(parse == NULL) {
    roxml_release(RELEASE_ALL);
    roxml_close(head);
    return (FALSE);
  }
  ots_get_xml_node(&parse, (const char*)"parser");
  
  tc_words = roxml_get_chld(head, NULL, 0);
  if(tc_words == NULL) {
    roxml_release(RELEASE_ALL);
    roxml_close(head);
    return (FALSE);
  }
  ots_get_xml_node(&tc_words, (const char*)"grader-tc");
  
  tf_words = roxml_get_chld(head, NULL,  0);
  if(tf_words == NULL) {
    roxml_release(RELEASE_ALL);
    roxml_close(head);
    return (FALSE);
  }
  ots_get_xml_node(&tf_words, (const char*)"grader-tf");
  
  pre = roxml_get_chld(stem, NULL,  0);
  if(pre == NULL) {
    roxml_release(RELEASE_ALL);
    roxml_close(head);
    return (FALSE);
  }
  ots_get_xml_node(&pre, (const char*)"pre");
  
  post = roxml_get_chld(stem, NULL,  0);
  if(post == NULL) {
    roxml_release(RELEASE_ALL);
    roxml_close(head);
    return (FALSE);
  }
  ots_get_xml_node(&post, (const char*)"post");
  
  syno = roxml_get_chld(stem, NULL, 0);
  if(syno == NULL) {
    roxml_release(RELEASE_ALL);
    roxml_close(head);
    return (FALSE);
  }
  ots_get_xml_node(&syno, (const char*)"synonyms");
  
  manual = roxml_get_chld(stem, NULL, 0);
  if(manual == NULL) {
    roxml_release(RELEASE_ALL);
    roxml_close(head);
    return (FALSE);
  }
  ots_get_xml_node(&manual, (const char*)"manual");
  
  step1_pre = roxml_get_chld(stem, NULL, 0);
  if(step1_pre == NULL) {
    roxml_release(RELEASE_ALL);
    roxml_close(head);
    return (FALSE);
  }
  ots_get_xml_node(&step1_pre, (const char*)"step1_pre");
  
  step1_post = roxml_get_chld(stem, NULL, 0);
  if(step1_post == NULL) {
    roxml_release(RELEASE_ALL);
    roxml_close(head);
    return (FALSE);
  }
  ots_get_xml_node(&step1_post, (const char*)"step1_post");
  
  pre = roxml_get_chld(pre, NULL, 0); /* point to first word */
  if(pre == NULL) {
    roxml_release(RELEASE_ALL);
    roxml_close(head);
    return (FALSE);
  }
  ots_append_xml_node_contents(&rule->RemovePre, &pre);
  
  post = roxml_get_chld(post, NULL, 0);
  if(post == NULL) {
    roxml_release(RELEASE_ALL);
    roxml_close(head);
    return (FALSE);
  }
  ots_append_xml_node_contents(&rule->RemovePost, &post);
  
  syno = roxml_get_chld(syno, NULL, 0);
  if(syno == NULL) {
    roxml_release(RELEASE_ALL);
    roxml_close(head);
    return (FALSE);
  }
  ots_append_xml_node_contents(&rule->synonyms, &syno);
  
  manual = roxml_get_chld(manual, NULL, 0);
  if(manual == NULL) {
    roxml_release(RELEASE_ALL);
    roxml_close(head);
    return (FALSE);
  }
  ots_append_xml_node_contents(&rule->manual, &manual);
  
  step1_pre = roxml_get_chld(step1_pre, NULL, 0);
  if(step1_pre == NULL) {
    roxml_release(RELEASE_ALL);
    roxml_close(head);
    return (FALSE);
  }
  ots_append_xml_node_contents(&rule->step1_pre, &step1_pre);
  
  step1_post = roxml_get_chld(step1_post, NULL, 0);
  if(step1_post == NULL) {
    roxml_release(RELEASE_ALL);
    roxml_close(head);
    return (FALSE);
  }
  ots_append_xml_node_contents(&rule->step1_post, &step1_post);
  
  pbreak = roxml_get_chld(parse, NULL, 0);
  if(pbreak == NULL) {
    roxml_release(RELEASE_ALL);
    roxml_close(head);
    return (FALSE);
  }
  ots_get_xml_node(&pbreak, (const char*)"linebreak");
  
  pdbreak = roxml_get_chld(parse, NULL, 0);
  if(pdbreak == NULL) {
    roxml_release(RELEASE_ALL);
    roxml_close(head);
    return (FALSE);
  }
  ots_get_xml_node(&pdbreak, (const char*)"linedontbreak");
  
  /*Parser break*/
  pbreak = roxml_get_chld(pbreak, NULL, 0);
  if(pbreak == NULL) {
    roxml_release(RELEASE_ALL);
    roxml_close(head);
    return (FALSE);
  }
  ots_append_xml_node_contents(&rule->ParserBreak, &pbreak);
  
  /*Parser Don't break*/
  pdbreak = roxml_get_chld(pdbreak, NULL, 0);
  if(pdbreak == NULL) {
    roxml_release(RELEASE_ALL);
    roxml_close(head);
    return (FALSE);
  }
  ots_append_xml_node_contents(&rule->ParserDontBreak, &pdbreak);
  
  /* Term Count load dict */
  tc_words = roxml_get_chld(tc_words, NULL, 0);
  if(tc_words == NULL) {
    roxml_release(RELEASE_ALL);
    roxml_close(head);
    return (FALSE);
  }
#if DEBUG > 1
  fprintf(stdout, "%d: %s\n", __LINE__, roxml_get_name(tc_words, NULL, 0));
  fprintf(stdout, "%d: %s\n", __LINE__, roxml_get_content(tc_words, NULL, 0, NULL));
#endif /* DEBUG > 1 */
  while (tc_words != NULL) {
    if (!g_strcmp0(roxml_get_name(tc_words, NULL, 0), (const char*)"word")) {
      Doc->dict = g_list_prepend(Doc->dict,
        (gpointer)ots_new_wordEntery(
          (unsigned const char*)roxml_get_content(tc_words, NULL, 0, NULL)));
    }
    tc_words = roxml_get_next_sibling(tc_words);
#if DEBUG > 2
    fprintf(stdout, "%s\n", roxml_get_content(tc_words, NULL, 0, NULL));
#endif /* DEBUG > 2 */
  }
  
  /*Term Frequency load dict*/
  tf_words = roxml_get_chld(tf_words, NULL, 0);
  if(tf_words == NULL) {
    roxml_release(RELEASE_ALL);
    roxml_close(head);
    return (FALSE);
  }
#if DEBUG > 1
  fprintf(stdout, "%d: %s\n", __LINE__, roxml_get_name(tf_words, NULL, 0));
  fprintf(stdout, "%d: %s\n", __LINE__, roxml_get_content(tf_words, NULL, 0, NULL));
#endif /* DEBUG > 1 */
  while (tf_words != NULL) {
    if (!g_strcmp0(roxml_get_name(tf_words, NULL, 0), (const char*)"word")) {
      const gchar* key = g_strdup(roxml_get_content(tf_words, NULL, 0, NULL));
      node_t* idf_attr = roxml_get_attr(tf_words, "idf", 0);
      if (idf_attr != NULL) {
        const char* idf_val = roxml_get_content(idf_attr, NULL, 0, NULL);
        if (idf_val != NULL) {
#if DEBUG > 3
          fprintf(stdout, "%s\n", idf_val);
#endif /* DEBUG > 3 */
          Doc->tf_terms = g_list_append(Doc->tf_terms,
          ots_new_OtsWordTF((const unsigned char*)key, atof(idf_val)));
        }
      }
      g_free((gpointer)key);
    }
    tf_words = roxml_get_next_sibling(tf_words);
#if DEBUG > 2
    fprintf(stdout, "%s\n", roxml_get_content(tf_words, NULL, 0, NULL));
#endif /* DEBUG > 2 */
  }
  roxml_release(RELEASE_ALL);
  roxml_close(head);
  return (TRUE);
}
예제 #8
0
int XHCPcmd_SETRULE_handle (int sockd, int argc, char **argv, char *data)
{
    node_t *nTmp;
    node_t **lstNodes;
    char *newId = NULL;
    int nb;

	// A supprimer !!!
    char *zaza = NULL;

    printf ("Entree XHCPcmd_SETRULE_handle avec %d arguments\n", argc);
    int i;
	for ( i=0; i<argc; i++ )
		printf ( "%d - %s\n", i, argv[i]);



    if ( (nTmp = roxml_load_buf (data)) == NULL )
    {
        XHCP_printXHCPResponse (sockd, RES_SYNTAXERR); // Syntax Error
        return XHCP_EXE_ERROR;
    }
    
    printf ("Chargement XML OK\n");
    
	if ( argc == 2 ) // pas de node mais id donné en argument
		newId = strdup(argv[1]);

		// On recherche si un id est présent
    if ( (lstNodes = roxml_xpath (nTmp, "//determinator[@guid]", &nb )) != NULL )
	{
		node_t *attr_tmp = roxml_get_attr (lstNodes[0], "guid", 0);

		if ( newId == NULL && argc == 1 )
		{
			newId = roxml_get_content(attr_tmp, NULL, 0, NULL);
		}

		roxml_del_node(attr_tmp);
	}
	if ( newId == NULL )
		newId = XHCP_getUuid();

printf("a la fin id = %s\n",newId==NULL ? "NULL":newId);
		
	lstNodes = roxml_xpath (nTmp, "//determinator", &nb );
	if ( nb == 1 )
		nTmp = lstNodes[0];
	else
    {
printf("Pas trouve //derterminator, nb=%d\n",nb);
        XHCP_printXHCPResponse (sockd, RES_SYNTAXERR); // Syntax Error
        return XHCP_EXE_ERROR;
    }
	
	// Ajout d'un nouveau noeud
	roxml_add_node(nTmp, 0, ROXML_ATTR_NODE, "guid", newId);		
printf("attribut ajouté\n");

printf("Nouvel arbre determinator\n");
roxml_commit_changes (nTmp, NULL, &zaza, 1);
printf("%s\n",  zaza);
free(zaza);




	lstNodes = roxml_xpath (rootConfig, "//determinators", &nb );
	if ( nb != 1 )
    {
printf("Pas trouve //determinators, nb=%d\n",nb);
        XHCP_printXHCPResponse (sockd, RES_INTNERROR); // Internal error
        return XHCP_EXE_ERROR;
    }

	/* On ratache le nouveau determinator à la liste */
	roxml_parent_node(lstNodes[0], nTmp);
		
	
	saveHal4lConfig (HAL4L_getConfigFile ());
	//roxml_close (nTmp);
	
	
    loadHal4lConfig (HAL4L_getConfigFile ());


    free(newId);


    XHCP_printXHCPResponse (sockd, RES_CFGDOCUPL ); // Configuration document uploaded
    
    return XHCP_EXE_SUCCESS;
}