git-svn-id: http://svn.eurecom.fr/openair4G/trunk@4233 818b1a75-f10b-46b9-bf7c-635c3b92a50f

This commit is contained in:
Cedric Roux
2013-10-18 15:24:52 +00:00
parent b4dca574d9
commit ff4360527c
72 changed files with 6392 additions and 0 deletions
@@ -0,0 +1,12 @@
AM_CFLAGS = \
@ADD_CFLAGS@ \
-I$(top_srcdir) \
-I$(top_srcdir)/libparser \
-I$(top_srcdir)/libbuffers
noinst_LTLIBRARIES = libresolver.la
libresolver_la_LDFLAGS = -all-static
libresolver_la_SOURCES = \
locate_root.c locate_root.h \
resolvers.c resolvers.h
@@ -0,0 +1,82 @@
#include <stdio.h>
#include <string.h>
#include "../rc.h"
#include "types.h"
#include "locate_root.h"
int locate_root(const char *root_name, types_t *head, types_t **root) {
types_t *next_type;
/* The root element is for example : MessageDef.
* This element is the entry for other sub-types.
*/
if (!root_name || (strlen (root_name) == 0)) {
printf ("FATAL: no root element name provided\n");
return -1;
}
if (!head) {
printf ("Empty list detected\n");
return -1;
}
if (!root) {
printf ("NULL root reference\n");
return -1;
}
for (next_type = head; next_type; next_type = next_type->next) {
if (next_type->name == NULL)
continue;
if (strcmp (root_name, next_type->name) == 0) {
/* Matching reference */
break;
}
}
*root = next_type;
return (next_type == NULL) ? -2 : 0;
}
int locate_type(const char *type_name, types_t *head, types_t **type) {
types_t *next_type;
/* The root element is for example : MessageDef.
* This element is the entry for other sub-types.
*/
if (!type_name) {
printf ("FATAL: no root element name provided\n");
return RC_BAD_PARAM;
}
if (!head) {
printf ("Empty list detected\n");
return RC_BAD_PARAM;
}
for (next_type = head; next_type; next_type = next_type->next) {
if (next_type->name == NULL)
continue;
if (strcmp (type_name, next_type->name) == 0) {
/* Matching reference */
break;
}
}
if (type)
*type = next_type;
return (next_type == NULL) ? RC_FAIL : RC_OK;
}
int get_message_id(types_t *head, buffer_t *buffer, uint32_t *message_id) {
uint32_t value;
types_t *type_message_id;
if (!head || !message_id || !buffer)
return RC_BAD_PARAM;
CHECK_FCT(locate_type("messageId", head, &type_message_id));
/* MessageId is an offset from start of buffer */
value = buffer_get_uint32_t (buffer, type_message_id->offset);
*message_id = value;
return RC_OK;
}
@@ -0,0 +1,10 @@
#ifndef LOCATE_ROOT_H_
#define LOCATE_ROOT_H_
int locate_root(const char *root_name, types_t *head, types_t **root);
int locate_type(const char *type_name, types_t *head, types_t **type);
int get_message_id(types_t *head, buffer_t *buffer, uint32_t *message_id);
#endif /* LOCATE_ROOT_H_ */
@@ -0,0 +1,25 @@
#include <stdio.h>
#include <string.h>
#include "types.h"
int resolve_typedefs(types_t **head)
{
types_t *next_type;
if (!head) {
printf("Empty list detected\n");
return -1;
}
for (next_type = head; next_type; next_type = next_type->next)
{
/* Only resolve typedef */
if (next_type->type != TYPE_TYPEDEF)
continue;
printf("Trying to resolve typedef %s\n", next_type->name);
}
return 0;
}
@@ -0,0 +1,330 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "types.h"
#include "resolvers.h"
typedef enum {
RESOLV_OK = 0,
RESOLV_ERROR = -1,
RESOLV_LIST_EMPTY = -2,
RESOLV_NOT_FOUND = -3,
} resolv_rc_e;
int search_id(types_t *head, types_t **found, int id)
{
types_t *next_type;
if (!head) {
printf("Empty list detected\n");
return RESOLV_LIST_EMPTY;
}
for (next_type = head; next_type; next_type = next_type->next)
{
if (next_type->id == id && next_type->type != TYPE_FILE)
break;
}
if (found)
*found = next_type;
return next_type == NULL ? RESOLV_NOT_FOUND : RESOLV_OK;
}
int search_file(types_t *head, types_t **found, int file_id)
{
types_t *next_type;
if (!head) {
printf("Empty list detected\n");
return RESOLV_LIST_EMPTY;
}
for (next_type = head; next_type; next_type = next_type->next)
{
if (next_type->type != TYPE_FILE)
continue;
if (file_id == next_type->id)
break;
}
if (found)
*found = next_type;
return next_type == NULL ? RESOLV_NOT_FOUND : RESOLV_OK;
}
int resolve_typedefs(types_t **head)
{
types_t *next_type;
if (!head) {
printf("Empty list detected\n");
return RESOLV_LIST_EMPTY;
}
for (next_type = *head; next_type; next_type = next_type->next)
{
/* Only resolve typedef */
if (next_type->type != TYPE_TYPEDEF)
continue;
// printf("Trying to resolve typedef %s with type %d\n", next_type->name, next_type->id);
if (search_id(*head, &next_type->child, next_type->type_xml) != RESOLV_OK) {
/* We have to remove this reference */
}/* else {
next_type->type_hr_display(next_type, 0);
}*/
}
return 0;
}
int resolve_struct(types_t **head)
{
types_t *next_type;
if (!head) {
printf("Empty list detected\n");
return RESOLV_LIST_EMPTY;
}
for (next_type = *head; next_type; next_type = next_type->next)
{
char *member;
char *members;
/* Only resolve typedef */
if (next_type->type != TYPE_STRUCT)
continue;
// printf("Trying to resolve struct members %s with type %d\n", next_type->name, next_type->id);
/* Struct may have no member */
if (next_type->members == NULL)
continue;
/* We have to copy the string as strtok will split the string in argument */
members = strdup(next_type->members);
/* Split the string on spaces and _ */
member = strtok(members, " _");
while(member != NULL)
{
if (next_type->nb_members == 0) {
next_type->members_child = malloc(sizeof(struct types_s *));
} else {
next_type->members_child = realloc(next_type->members_child,
(next_type->nb_members + 1) * sizeof(struct types_s *));
}
if (search_id(*head, &next_type->members_child[next_type->nb_members], atoi(member)) != RESOLV_OK) {
/* We have to remove this reference */
}
if ((next_type->members_child[next_type->nb_members] != NULL)
&& (next_type->members_child[next_type->nb_members]->type != TYPE_FIELD))
{
/* Only keep field child for structure, other member can be present
* for defining types (union or struct) used by fields but should not be considered. */
next_type->members_child[next_type->nb_members] = NULL;
/* We have to remove this reference */
}
next_type->nb_members++;
/* Pick up the next string available */
member = strtok(NULL, " _");
}
// next_type->type_hr_display(next_type, 0);
}
return 0;
}
int resolve_union(types_t **head)
{
types_t *next_type;
if (!head) {
printf("Empty list detected\n");
return RESOLV_LIST_EMPTY;
}
for (next_type = *head; next_type; next_type = next_type->next)
{
char *member;
char *members;
/* Only resolve typedef */
if (next_type->type != TYPE_UNION)
continue;
// printf("Trying to resolve struct members %s with type %d\n", next_type->name, next_type->id);
/* Struct may have no member */
if (next_type->members == NULL)
continue;
/* We have to copy the string as strtok will modify the string in argument */
members = strdup(next_type->members);
/* Split the string on spaces and _ */
member = strtok(members, " _");
while(member != NULL)
{
if (next_type->nb_members == 0) {
next_type->members_child = malloc(sizeof(struct types_s *));
} else {
next_type->members_child = realloc(next_type->members_child,
(next_type->nb_members + 1) * sizeof(struct types_s *));
}
if (search_id(*head, &next_type->members_child[next_type->nb_members], atoi(member)) != RESOLV_OK) {
/* We have to remove this reference */
}
next_type->nb_members++;
/* Pick up the next string available */
member = strtok(NULL, " _");
}
// next_type->type_hr_display(next_type, 0);
}
return 0;
}
int resolve_pointer_type(types_t **head)
{
types_t *next_type;
if (!head) {
printf("Empty list detected\n");
return RESOLV_LIST_EMPTY;
}
for (next_type = *head; next_type; next_type = next_type->next)
{
/* Only resolve typedef */
if (next_type->type != TYPE_POINTER)
continue;
// printf("Trying to resolve pointer id %d with type %d\n",
// next_type->id, next_type->type_xml);
if (search_id(*head, &next_type->child, next_type->type_xml) != RESOLV_OK) {
/* We have to remove this reference */
}
// next_type->type_hr_display(next_type, 0);
}
return 0;
}
int resolve_reference(types_t **head)
{
types_t *next_type;
if (!head) {
printf("Empty list detected\n");
return RESOLV_LIST_EMPTY;
}
for (next_type = *head; next_type; next_type = next_type->next)
{
/* Only resolve typedef */
if (next_type->type != TYPE_REFERENCE)
continue;
// printf("Trying to resolve reference id %d with type %d\n",
// next_type->id, next_type->type_xml);
if (search_id(*head, &next_type->child, next_type->type_xml) != RESOLV_OK) {
/* We have to remove this reference */
}
// next_type->type_hr_display(next_type, 0);
}
return 0;
}
int resolve_field(types_t **head)
{
types_t *next_type;
if (!head) {
printf("Empty list detected\n");
return RESOLV_LIST_EMPTY;
}
for (next_type = *head; next_type; next_type = next_type->next)
{
/* Only resolve typedef */
if (next_type->type != TYPE_FIELD)
continue;
// printf("Trying to resolve pointer id %d with type %d\n",
// next_type->id, next_type->type_xml);
if (search_id(*head, &next_type->child, next_type->type_xml) != RESOLV_OK) {
/* We have to remove this reference */
}
// next_type->type_hr_display(next_type, 0);
}
return 0;
}
int resolve_array(types_t **head)
{
types_t *next_type;
if (!head) {
printf("Empty list detected\n");
return RESOLV_LIST_EMPTY;
}
for (next_type = *head; next_type; next_type = next_type->next)
{
/* Only resolve typedef */
if (next_type->type != TYPE_ARRAY)
continue;
// printf("Trying to resolve array id %d with type %d\n",
// next_type->id, next_type->type_xml);
if (search_id(*head, &next_type->child, next_type->type_xml) != RESOLV_OK) {
/* We have to remove this reference */
}
// next_type->type_hr_display(next_type, 0);
}
return 0;
}
int resolve_file(types_t **head)
{
types_t *next_type;
if (!head) {
printf("Empty list detected\n");
return RESOLV_LIST_EMPTY;
}
for (next_type = *head; next_type; next_type = next_type->next)
{
/* Only resolve typedef */
if (next_type->type == TYPE_FILE)
continue;
/* No reference to a file */
if (next_type->file == NULL) {
continue;
}
// printf("Trying to resolve file %s\n", next_type->file);
if (search_file(*head, &next_type->file_ref, atoi(&next_type->file[1])) != RESOLV_OK) {
/* We have to remove this reference */
}
// next_type->type_hr_display(next_type, 0);
}
return 0;
}
@@ -0,0 +1,22 @@
#ifndef RESOLVERS_H_
#define RESOLVERS_H_
int resolve_typedefs(types_t **head);
int resolve_struct(types_t **head);
int resolve_pointer_type(types_t **head);
int resolve_field(types_t **head);
int resolve_array(types_t **head);
int resolve_reference(types_t **head);
int resolve_union(types_t **head);
int resolve_file(types_t **head);
int search_file(types_t *head, types_t **found, int id);
#endif /* RESOLVERS_H_ */