/[pdpsoft]/trunk/grid-mw-security/ees/src/aos/aos.c
ViewVC logotype

Diff of /trunk/grid-mw-security/ees/src/aos/aos.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 472 by aramv, Tue Jun 23 13:05:50 2009 UTC revision 473 by aramv, Wed Jun 24 14:25:36 2009 UTC
# Line 1  Line 1 
1  #include "aos.h"  #include "aos.h"
2    
3  static arguments args_list;  static arguments args_list;
4    static int _is_initialized;
5  int args_size;  int args_size;
6    
7    int AOS_is_initialized(){
8            return _is_initialized;
9    }
10    
11  int buffer_size(arg_type argtype){  int buffer_size(arg_type argtype){
12    switch (argtype){    switch (argtype){
13      case TYPE_NONE :      case TYPE_NONE :
# Line 68  int buffer_size(arg_type argtype){ Line 73  int buffer_size(arg_type argtype){
73    }    }
74  }  }
75    
76  void AOS_set_int(const char* label, int value){  int AOS_set_int(const char* label, int value){
   /*int buf_size = buffer_size(TYPE_INT);*/  
   /*int* stack_value = malloc(buf_size);*/  
77    int* stack_value = &value;    int* stack_value = &value;
78    AOS_set(label, stack_value, TYPE_INT, 0, NULL);    return AOS_set(label, stack_value, TYPE_INT, 0, NULL);
79  }  }
80    
81  void AOS_set_string(const char* label, char* value){  int AOS_set_string(const char* label, char* value){
82    AOS_set(label, value, TYPE_STRING, strlen(value)+1, NULL);    return AOS_set(label, value, TYPE_STRING, strlen(value)+1, NULL);
83    }
84    
85    int AOS_set_pem(const char* label, char* value){
86      return AOS_set(label, value, TYPE_PEM, strlen(value)+1, NULL);
87  }  }
88    
89  /* uses memcpy to pass by value */  /* uses memcpy to pass by value */
90  void AOS_set(const char *label, void *value, arg_type type, int arg_bufsize, argument_t * parent){  int AOS_set(const char *label, void *value, arg_type type, int arg_bufsize, argument_t * parent){
91    void* args_new = NULL;    argument_t* args_new = NULL;
92    int buf_size;    int buf_size;
93    buf_size = arg_bufsize;    buf_size = arg_bufsize;
94    
95    args_new = realloc(args_list.arg, (sizeof(argument_t) * (args_list.count + 1)));          if(!AOS_is_initialized()){
96                    ng_log(LOG_ERR, "AOS is not yet initialized. Aborting.\n");
97                    return 1;
98            }
99    
100    /* allocate an extra argument in the list */    /* allocate an extra argument in the list */
101      if((args_new = realloc(args_list.arg, (sizeof(argument_t) * (args_list.count + 1)))) == NULL){
102                    ng_log(LOG_ERR, "Failed to realloc a new argument on the list. %s\n", strerror(errno));
103                    return 1;
104            } else {
105                    memset(&(args_new[args_list.count]), 0, sizeof(argument_t));
106            }
107            /*memset(args_list.arg[args_list.count].data, 0, buf_size);*/
108    
109    if(args_new){    if(args_new){
110      args_list.arg = args_new;      args_list.arg = args_new;
111      printf("Realloc succeeded. Argument lists is now %lu elements.\n", (unsigned long) (args_list.count + 1));      printf("Realloc succeeded. Argument lists is now %lu elements.\n", (unsigned long) (args_list.count + 1));
112    } else {    } else {
113      perror("args_list.arg");      ng_log("args_list.arg not set: %s", strerror(errno));
114      return;      return 1;
115    }    }
116    
117    if(buf_size == 0) {    if(buf_size == 0) {
# Line 100  void AOS_set(const char *label, void *va Line 119  void AOS_set(const char *label, void *va
119      args_list.arg[args_list.count].needs_free = 0;      args_list.arg[args_list.count].needs_free = 0;
120      printf("1 pointer allocated at %p. No need to free!\n", args_list.arg[args_list.count].data);      printf("1 pointer allocated at %p. No need to free!\n", args_list.arg[args_list.count].data);
121    } else {    } else {
122      args_list.arg[args_list.count].data = malloc(buf_size);      args_list.arg[args_list.count].data = calloc(1, buf_size);
123      memset(args_list.arg[args_list.count].data, 0, buf_size);                  printf("Storing bytes: %i\n", buf_size);
124      memcpy(args_list.arg[args_list.count].data, value, buf_size);      memcpy(args_list.arg[args_list.count].data, value, buf_size);
125      args_list.arg[args_list.count].needs_free = 1;      args_list.arg[args_list.count].needs_free = 1;
126      printf("%i bytes allocated at %p. (index %lu) Remember to free it or DIE!\n", buf_size, args_list.arg[args_list.count].data, (unsigned long) args_list.count);      printf("%i bytes allocated at %p. (index %lu) Remember to free it or DIE!\n", buf_size, args_list.arg[args_list.count].data, (unsigned long) args_list.count);
127    }    }
128    
129          args_list.arg[args_list.count].type = type;          args_list.arg[args_list.count].type = type;
130    args_list.arg[args_list.count].label = label;          args_list.arg[args_list.count].label = label;
131    args_list.arg[args_list.count].parent= parent;          args_list.arg[args_list.count].parent= parent;
132    
133    args_list.count++;    args_list.count++;
134            return 0;
135  }  }
136    
137  void* AOS_get_value_by_label(char *label){  void* AOS_get_value_by_label(char *label){
# Line 146  void AOS_free_argslist(void) { Line 167  void AOS_free_argslist(void) {
167    args_list.count = 0;    args_list.count = 0;
168  }  }
169    
   
170  int AOS_Init (void)  int AOS_Init (void)
171  {  {
172    /*args_size = 0;*/    /*args_size = 0;*/
# Line 160  int AOS_Init (void) Line 180  int AOS_Init (void)
180    
181      /*memset(args_list.arg, 0, args_size);*/      /*memset(args_list.arg, 0, args_size);*/
182    
183                    _is_initialized = 1;
184    
185      return 0;      return 0;
186  }  }
187    

Legend:
Removed from v.472  
changed lines
  Added in v.473

grid.support@nikhef.nl
ViewVC Help
Powered by ViewVC 1.1.28