/* ELAPI Additional functions for printing and debugging collections. Copyright (C) Dmitri Pal 2009 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include #include #include "elapi_collection.h" #include "elapi_debug.h" #include "elapi_util.h" #include "elapi_tools.h" /* Debug handle */ int debug_handle(char *property, int property_len, int type, void *data, int length, void *custom_data, int *dummy) { int i; int nest_level; DEBUG_STRING("debug_handle","Entry."); nest_level = *(int *)(custom_data); DEBUG_NUMBER("We are getting this pointer:",custom_data); DEBUG_NUMBER("Nest level:",nest_level); switch(type) { case ELAPI_TYPE_STRING: printf("%*s %s[%d] str: %s (%d)\n", (nest_level-1)*4,"", property, length, (char *)(data), (int)(nest_level)); break; case ELAPI_TYPE_BINARY: printf("%*s %s[%d] bin: ", (nest_level-1)*4,"", property, length); for(i=0;icount, ((struct collection_header *)(data))->reference_count); for(i=0;iproperty); flag |= ELAPI_TRAVERSE_END; printf("Traverse flags %d\n",flag); /* Traverse collection */ error = traverse_collection(handle,flag,debug_handle,(void *)(&nest_level)); if(error) printf("Error debuging collection %d\n",error); DEBUG_STRING("debug_collection","Exit."); return error; } /* Print the collection using default serialization */ int print_collection(struct collection_item *handle) { struct serial_data buf_data; int error = EOK; printf("COLLECTION:\n"); buf_data.buffer=NULL; buf_data.length=0; buf_data.size=0; buf_data.nest_level=0; /* Traverse collection */ error = traverse_collection(handle,ELAPI_TRAVERSE_DEFAULT | ELAPI_TRAVERSE_END ,serialize,(void *)(&buf_data)); if(error) printf("Error traversing collection %d\n",error); else printf("%s\n",buf_data.buffer); free(buf_data.buffer); return error; } /* Find and print one item using default serialization */ int print_item(struct collection_item *handle, char *name) { struct serial_data buf_data; int error = EOK; printf("FIND ITEM:\n"); buf_data.buffer=NULL; buf_data.length=0; buf_data.size=0; buf_data.nest_level=0; error = get_item_and_do(handle, name, ELAPI_TYPE_ANY,ELAPI_TRAVERSE_DEFAULT, serialize,&buf_data); if(error) printf("Error searching collection %d\n",error); else { if(buf_data.buffer != NULL) { if(buf_data.length> 0) buf_data.length--; *(buf_data.buffer+buf_data.length)= '\0', printf("%s\n",buf_data.buffer); free(buf_data.buffer); } else printf("Name %s is not found in the collection %s.\n",name,handle->property); } return error; }