Beispiel #1
0
int XHCPcmd_GETCONFIGXML (int sockd, int argc, char **argv)
{
    char *writeBuffer = NULL;
    
	XHCP_printXHCPResponse (sockd, RES_CFGDOCFOL ); // Configuration document follows
	
	roxml_commit_changes (rootConfig, NULL, &writeBuffer, 1);
	
	XHCP_print (sockd, writeBuffer);
	XHCP_print (sockd, ".");
	
	//free (writeBuffer);
	roxml_release(RELEASE_LAST);

    return XHCP_EXE_SUCCESS;
}
Beispiel #2
0
int XHCPcmd_GETRULE (int sockd, int argc, char **argv)
{
    node_t **rulesNodesLst;
    char buffer[XHCP_BUFFER_SZ];
    int sz_buffer;
    int nb;
    
    char *writeBuffer = NULL;
    
    
    if (argc != 2)
    {
        XHCP_printXHCPResponse (sockd, RES_SYNTAXERR ); // Syntax Error
        return XHCP_EXE_ERROR;
    }
    
    sprintf (buffer, "//determinator[@guid='%s']", argv[1]);
    
    printf ("%s\n", buffer);
    
    if ( (rulesNodesLst = roxml_xpath (rootConfig, buffer, &nb )) == NULL )
        XHCP_printXHCPResponse (sockd, RES_NOSUCHSCR ); // No such script/rule
    else
    {
        XHCP_printXHCPResponse (sockd, RES_REQSCRFOL ); // Requested script/rule follows
        
        sz_buffer = roxml_commit_changes (rulesNodesLst[0], NULL, &writeBuffer, 1);
        
        XHCP_print (sockd, writeBuffer);
        XHCP_print (sockd, ".");
        
        free (writeBuffer);
    }
    
    
    
    return XHCP_EXE_SUCCESS;
}
Beispiel #3
0
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;
}
Beispiel #4
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;
}
Beispiel #5
0
int main(int ac, char *av[])
{
	node_t 			*doc;
	char			*xmlname = NULL;
	char			*xpquery = NULL;
	node_t 			**xpr = NULL;
	int 			opt = 0;
	int 			longopt = 0;
	int			flags = 0;

	/* getopt_long() should not display any message */
	opterr = 0; 

	while ((opt = getopt_long(ac, av, short_options, long_options, &longopt)) != -1) {
		switch (opt) {
		case 0:
			/*
			long option encountered
			we should not see any of them, because they are supposed to
			map to the corresponding short option. So if we get this, it
			might indicate that something is borked.
			*/
			break;
		case 1:
			/* not an option */
			if (!xmlname) {
				xmlname = strdup(av[optind-1]);
			} else if (!xpquery) {
				xpquery = strdup(av[optind-1]);
			} else {
				fprintf(stderr, "too many non-option - remove '%s'\n", av[optind - 1]);
				return EXIT_FAILURE;
			}
			break;
		case 'h':
			display_usage(av[0]);
			return EXIT_FAILURE;
		case 'q':
			flags |= ROCAT_FLAG_QUIET;
			break;
		case '?':
			fprintf(stderr, "unknown option '%s'\n", av[optind - 1]);
			return EXIT_FAILURE;
		default:
			break;
		}
	}

	if (!xmlname) {
		if ((flags & ROCAT_FLAG_QUIET) == 0) {
			fprintf(stderr, "invalid options: no XML file name\n\n");
			display_usage(av[0]);
		}
		return EXIT_FAILURE;
	}

	doc = roxml_load_doc(xmlname);
	if (!doc) {
		if ((flags & ROCAT_FLAG_QUIET) == 0)
			fprintf(stderr, "failed to load XML file '%s'\n", xmlname);
		goto on_error;
	}

	if (xpquery) {
		int xncount;

		xpr = roxml_xpath(doc, xpquery, &xncount);
		if (!xpr) {
			if ((flags & ROCAT_FLAG_QUIET) == 0)
				fprintf(stderr, "XPath query '%s' failed on '%s'\n", 
					xpquery, xmlname);
			goto on_error;
		}

		if (xncount) {
			int npos; 
			
			for (npos = 0; npos < xncount; ++npos) {
				char *buffer = NULL;
				node_t *xn = xpr[npos];;
				/* commit the node to stdout */
				roxml_commit_changes(xn, NULL, &buffer, 1);
				printf("%s\n", buffer);
				free(buffer);
			}
		} else {
			if ((flags & ROCAT_FLAG_QUIET) == 0)
				fprintf(stderr, "XPath query '%s' does not yield to any result\n", 
					xpquery);
			goto on_error;
		}

		roxml_release(xpr);

		free(xpquery);
	} else {
		char *buffer = NULL;
		/* commit everything to stdout */
		roxml_commit_changes(doc, NULL, &buffer, 1);
		printf("%s\n", buffer);
		free(buffer);
	}

	roxml_close(doc);

	free(xmlname);

	return EXIT_SUCCESS;

on_error:
	if (xpr) {
		roxml_release(xpr);
	}
	if (doc) roxml_close(doc);
	if (xmlname) free(xmlname);
	if (xpquery) free(xpquery);

	return EXIT_FAILURE;
}