/[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 524 by aramv, Tue Jun 30 13:03:07 2009 UTC revision 525 by aramv, Wed Jul 15 08:55:01 2009 UTC
# Line 93  NG_RC AOS_set(const char *label, void *v Line 93  NG_RC AOS_set(const char *label, void *v
93    buf_size = arg_bufsize;    buf_size = arg_bufsize;
94    
95          if(!AOS_is_initialized()){          if(!AOS_is_initialized()){
96                  ng_log(LOG_ERR, "AOS is not yet initialized. Aborting.\n");                  ng_log(LOG_ERR, "AOS is not yet initialized. Aborting.");
97                  return NG_FAILURE;                  return NG_FAILURE;
98          }          }
99    
100    if(!(AOS_get_value_by_label(label) == NULL)){    if(!(AOS_get_value_by_label(label) == NULL)){
101                  ng_log(LOG_ERR, "Block with label %s already exists.\n", label);                  ng_log(LOG_ERR, "Block with label %s already exists.", label);
102      return NG_FAILURE;      return NG_FAILURE;
103    }    }
104    
105    /* allocate an extra argument in the list */    /* allocate an extra argument in the list */
106    if((args_new = calloc(1, (sizeof(argument_t)))) == NULL){    if((args_new = calloc(1, (sizeof(argument_t)))) == NULL){
107                  ng_log(LOG_ERR, "Failed to realloc a new argument on the list. %s\n", strerror(errno));                  ng_log(LOG_ERR, "Failed to realloc a new argument on the list. %s", strerror(errno));
108                  return NG_FAILURE;                  return NG_FAILURE;
109          }          }
110    
111    if(args_new){    if(args_new){
112      ng_log(LOG_DEBUG, "Malloc succeeded. Argument lists is now %lu elements.\n", (unsigned long) (args_size));      ng_log(LOG_DEBUG, "Malloc succeeded. Argument lists is now %lu elements.", (unsigned long) (args_size));
113    } else {    } else {
114      ng_log(LOG_ERR, "args_new not set: %s", strerror(errno));      ng_log(LOG_ERR, "args_new not set: %s", strerror(errno));
115      return NG_FAILURE;      return NG_FAILURE;
# Line 118  NG_RC AOS_set(const char *label, void *v Line 118  NG_RC AOS_set(const char *label, void *v
118    if(buf_size == 0) {    if(buf_size == 0) {
119      args_new->data = value;      args_new->data = value;
120      args_new->needs_free = 0;      args_new->needs_free = 0;
121      ng_log(LOG_DEBUG, "1 pointer allocated at %p. No need to free!\n", args_new->data);      ng_log(LOG_DEBUG, "1 pointer allocated at %p. No need to free!", args_new->data);
122    } else {    } else {
123      args_new->data = calloc(1, buf_size);      args_new->data = calloc(1, buf_size);
124                  ng_log(LOG_DEBUG, "Storing bytes: %i\n", buf_size);                  ng_log(LOG_DEBUG, "Storing bytes: %i", buf_size);
125      memcpy(args_new->data, value, buf_size);      memcpy(args_new->data, value, buf_size);
126      args_new->needs_free = 1;      args_new->needs_free = 1;
127      ng_log(LOG_DEBUG, "%i bytes allocated at %p. (index %lu) Remember to free it or DIE!\n", buf_size, args_new->data, (unsigned long) args_size);      ng_log(LOG_DEBUG, "%i bytes allocated at %p. (index %lu) Remember to free it or DIE!", buf_size, args_new->data, (unsigned long) args_size);
128    }    }
129    
130          args_new->type           = type;          args_new->type           = type;
# Line 135  NG_RC AOS_set(const char *label, void *v Line 135  NG_RC AOS_set(const char *label, void *v
135    
136    last_node = AOS_get_last_node();    last_node = AOS_get_last_node();
137    if(last_node != NULL){    if(last_node != NULL){
138      /*ng_log(LOG_ERR, "Last node is not NULL at %p\n", last_node);*/      /*ng_log(LOG_ERR, "Last node is not NULL at %p", last_node);*/
139      last_node->next = args_new;      last_node->next = args_new;
140    } else {    } else {
141      /*ng_log(LOG_ERR, "Last node is NULL at %p\n", last_node);*/      /*ng_log(LOG_ERR, "Last node is NULL at %p", last_node);*/
142      args_list = args_new;      args_list = args_new;
143    }    }
144    
# Line 190  void AOS_free_argslist(void) { Line 190  void AOS_free_argslist(void) {
190    argument_t * next_arg;    argument_t * next_arg;
191    current_arg = args_list;    current_arg = args_list;
192    for(i = 0; i < args_size; i++){    for(i = 0; i < args_size; i++){
193      ng_log(LOG_DEBUG, "Element %i points to %p\n", i, current_arg->data);      ng_log(LOG_DEBUG, "Element %i points to %p", i, current_arg->data);
194      next_arg = current_arg->next;      next_arg = current_arg->next;
195      if(current_arg->needs_free){      if(current_arg->needs_free){
196        ng_log(LOG_DEBUG, "Freeing arg %i\n",i);        ng_log(LOG_DEBUG, "Freeing arg %i",i);
197        free(current_arg->data);        free(current_arg->data);
198        free(current_arg);        free(current_arg);
199      }      }
# Line 215  NG_RC AOS_delete_argument_by_label(const Line 215  NG_RC AOS_delete_argument_by_label(const
215    for(current_arg = args_list; current_arg != NULL; previous_arg = current_arg, current_arg = current_arg->next){    for(current_arg = args_list; current_arg != NULL; previous_arg = current_arg, current_arg = current_arg->next){
216      if(strncmp(current_arg->label, label, strlen(label)) == 0){      if(strncmp(current_arg->label, label, strlen(label)) == 0){
217        if(current_arg->setting_plugin != get_running_plugin()){        if(current_arg->setting_plugin != get_running_plugin()){
218          ng_log(LOG_ERR, "Argument %s is not owned by running plugin %s\n", current_arg->label, get_running_plugin()->pluginname);          ng_log(LOG_ERR, "Argument %s is not owned by running plugin %s", current_arg->label, get_running_plugin()->pluginname);
219          return NG_FAILURE;          return NG_FAILURE;
220        }        }
221        if(previous_arg == NULL){        if(previous_arg == NULL){
222          /* head node deleted. linking start of list to next node */          /* head node deleted. linking start of list to next node */
223          args_list = current_arg->next;          args_list = current_arg->next;
         break;  
224        } else {        } else {
225          /* link previous to deletee's next */          /* link previous to deletee's next */
226          previous_arg->next = current_arg->next;          previous_arg->next = current_arg->next;
         break;  
227        }        }
228          break;
229      }      }
230    }    }
231    
232    ng_log(LOG_ERR, "Deleting arg: %s\n", current_arg->label);    ng_log(LOG_ERR, "Deleting arg: %s", current_arg->label);
233    free(current_arg->data);    free(current_arg->data);
234    free(current_arg);    free(current_arg);
235    args_size--;    args_size--;

Legend:
Removed from v.524  
changed lines
  Added in v.525

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