void ui_print_trl(trl_t *trl) { char *mid_str = NULL; if(trl == NULL) { printf("NULL"); return; } mid_str = mid_to_string(trl->mid); printf("TRL %s: T:%d P:"UVAST_FIELDSPEC" C:"UVAST_FIELDSPEC" A:", mid_str, (uint32_t) trl->time, trl->period, trl->count); ui_print_mc(trl->action); SRELEASE(mid_str); }
void ui_print_srl(srl_t *srl) { char *mid_str = NULL; if(srl == NULL) { printf("NULL"); return; } mid_str = mid_to_string(srl->mid); printf("SRL %s: T:%d E:", mid_str, (uint32_t) srl->time); ui_print_expr(srl->expr); printf(" C:"UVAST_FIELDSPEC" A:", srl->count); ui_print_mc(srl->action); SRELEASE(mid_str); }
/****************************************************************************** * * \par Function Name: adm_add_datadef_collect * * \par Registers a collection function to a data definition. * * \param[in] mid_str serialized MID value * \param[in] collect The data collection function. * * \par Notes: * 1. When working with parameterized OIDs, the given MID should * be all information excluding the parameterized portion of the OID. * 2. ADM names will be truncated after ADM_MAX_NAME bytes. * * Modification History: * MM/DD/YY AUTHOR DESCRIPTION * -------- ------------ --------------------------------------------- * 11/25/12 E. Birrane Initial implementation. * 07/27/13 E. BIrrane Updated ADM to use Lysts. *****************************************************************************/ void adm_add_datadef_collect(uint8_t *mid_str, adm_data_collect_fn collect) { uint32_t used = 0; mid_t *mid = NULL; adm_datadef_t *entry = NULL; DTNMP_DEBUG_ENTRY("adm_add_datadef_collect","(%lld, %lld)", mid_str, collect); if((mid_str == NULL) || (collect == NULL)) { DTNMP_DEBUG_ERR("adm_add_datadef_collect","Bad Args.", NULL); DTNMP_DEBUG_EXIT("adm_add_datadef_collect","->.", NULL); return; } if((mid = mid_deserialize(mid_str, ADM_MID_ALLOC, &used)) == NULL) { char *tmp = utils_hex_to_string(mid_str, ADM_MID_ALLOC); DTNMP_DEBUG_ERR("adm_add_datadef_collect","Can't deserialize MID str %s.",tmp); MRELEASE(tmp); DTNMP_DEBUG_EXIT("adm_add_datadef_collect","->.", NULL); return; } if((entry = adm_find_datadef(mid)) == NULL) { char *tmp = mid_to_string(mid); DTNMP_DEBUG_ERR("adm_add_datadef_collect","Can't find data for MID %s.", tmp); MRELEASE(tmp); } else { entry->collect = collect; } mid_release(mid); DTNMP_DEBUG_EXIT("adm_add_datadef_collect","->.", NULL); }
void adm_add_ctrl_run(uint8_t *mid_str, adm_ctrl_fn run) { uint32_t used = 0; mid_t *mid = NULL; adm_ctrl_t *entry = NULL; DTNMP_DEBUG_ENTRY("adm_add_ctrl_run","(%lld, %lld)", mid_str, run); if((mid_str == NULL) || (run == NULL)) { DTNMP_DEBUG_ERR("adm_add_ctrl_run","Bad Args.", NULL); DTNMP_DEBUG_EXIT("adm_add_ctrl_run","->.",NULL); return; } if((mid = mid_deserialize(mid_str, ADM_MID_ALLOC, &used)) == NULL) { char *tmp = utils_hex_to_string(mid_str, ADM_MID_ALLOC); DTNMP_DEBUG_ERR("adm_add_ctrl_run","Can't deserialized MID %s", tmp); MRELEASE(tmp); DTNMP_DEBUG_EXIT("adm_add_ctrl_run","->.",NULL); return; } if((entry = adm_find_ctrl(mid)) == NULL) { char *tmp = mid_to_string(mid); DTNMP_DEBUG_ERR("adm_add_ctrl_run","Can't find control for MID %s", tmp); MRELEASE(tmp); } else { entry->run = run; } mid_release(mid); DTNMP_DEBUG_EXIT("adm_add_ctrl_run","->.",NULL); }
char *mid_pretty_print(mid_t *mid) { int size = 0; int oid_size = 0; int raw_size = 0; char *oid_str = NULL; char *raw_str; char *result = NULL; char *cursor = NULL; DTNMP_DEBUG_ENTRY("mid_pretty_print","(%#llx)", (unsigned long) mid); /* Step 0: Sanity Check. */ if(mid == NULL) { DTNMP_DEBUG_ERR("mid_pretty_print","NULL MID.",NULL); DTNMP_DEBUG_EXIT("mid_pretty_print","->NULL.",NULL); return NULL; } /* Step 1: Grab the pretty-print of the encapsulated OID. We will need to * do this anyway and it will help with the sizing. */ if(mid->oid != NULL) { oid_str = oid_pretty_print(mid->oid); oid_size = strlen((char *)oid_str) + 1; } if(oid_str == NULL) { oid_size = strlen("NULL_OID") + 1; if((oid_str = (char *) MTAKE(oid_size)) != NULL) { memset(oid_str,0,oid_size); strncpy((char *)oid_str,"NULL OID",oid_size); } else { DTNMP_DEBUG_ERR("mid_pretty_print","Can't alloc %d bytes for OID.", oid_size); DTNMP_DEBUG_EXIT("mid_pretty_print","->NULL.",NULL); return NULL; } } /* Step 2: Grab the raw version of the MID string. */ if((raw_str = mid_to_string(mid)) == NULL) { raw_size = strlen("NO RAW!") + 1; if((raw_str = (char *) MTAKE(raw_size)) != NULL) { memset(raw_str, 0, raw_size); strncpy(raw_str,"NO RAW!", raw_size); } else { DTNMP_DEBUG_ERR("mid_pretty_print","Can't alloc %d bytes for RAW.", raw_size); MRELEASE(oid_str); DTNMP_DEBUG_EXIT("mid_pretty_print","->NULL.",NULL); return NULL; } } else { raw_size = strlen((char*)raw_str) + 1; } /* Step 3: Guestimate size. This is, at best, a dark art and prone to * exaggeration. Numerics are assumed to take 5 bytes, unless I * think they will take 3 instead (indices vs. values). Other * values are based on constant strings in the function. One must * update this calculation if one changes string constants, else * one will be sorry. */ size = 28 + /* BANNER------ */ 14 + /* Flag : <...> */ 18 + /* Type : <...> */ 17 + /* Cat : <...> */ 17 + /* ISS : <...> */ 7 + oid_size + /* OID : <...> */ 17 + /* Tag : <...> */ 7 + raw_size + /* Raw : <...> */ 28; /* BANNER ----- */ /* Step 4: Allocate the string. */ if((result = (char*)MTAKE(size)) == NULL) { DTNMP_DEBUG_ERR("mid_pretty_print", "Can't alloc %d bytes.", size); MRELEASE(oid_str); MRELEASE(raw_str); DTNMP_DEBUG_EXIT("mid_pretty_print","->NULL",NULL); return NULL; } else { memset(result,0,size); } /* Step 5: Populate the allocated string. Keep an eye on the size. */ cursor = result; cursor += sprintf(cursor,"MID:\n---------------------\nFlag: %#x",mid->flags); cursor += sprintf(cursor,"\nType : "); switch(mid->type) { case 0: cursor += sprintf(cursor,"DATA\n"); break; case 1: cursor += sprintf(cursor,"CONTROL\n"); break; case 2: cursor += sprintf(cursor,"LITERAL\n"); break; case 3: cursor += sprintf(cursor,"OPERATOR\n"); break; default: cursor += sprintf(cursor,"UNKNOWN\n"); break; } cursor += sprintf(cursor,"Cat: "); switch(mid->category) { case 0: cursor += sprintf(cursor,"ATOMIC\n"); break; case 1: cursor += sprintf(cursor,"COMPUTED\n"); break; case 2: cursor += sprintf(cursor,"COLLECTION\n"); break; default: cursor += sprintf(cursor,"UNKNOWN\n"); break; } if(MID_GET_FLAG_ISS(mid->flags)) { cursor += sprintf(cursor,UVAST_FIELDSPEC"\n",mid->issuer); } else { cursor += sprintf(cursor,"None.\n"); } cursor += sprintf(cursor,"OID : %s", oid_str); MRELEASE(oid_str); if(MID_GET_FLAG_TAG(mid->flags)) { cursor += sprintf(cursor,UVAST_FIELDSPEC"\n",mid->tag); } else { cursor += sprintf(cursor,"None.\n"); } cursor += sprintf(cursor,"RAW : %s", raw_str); MRELEASE(raw_str); /* Step 6: Sanity check. */ if((cursor - result) > size) { DTNMP_DEBUG_ERR("mid_pretty_print", "OVERWROTE! Alloc %d, wrote %llu.", size, (cursor-result)); MRELEASE(result); DTNMP_DEBUG_EXIT("mid_pretty_print","->NULL",NULL); return NULL; } DTNMP_DEBUG_INFO("mid_pretty_print","Wrote %llu into %d string.", (cursor -result), size); DTNMP_DEBUG_EXIT("mid_pretty_print","->%#llx",result); return result; }
char *midcol_to_string(Lyst mc) { LystElt elt; char *result = NULL; char *cursor = NULL; int num_items = 0; int i = 0; char **mid_strs = NULL; int tot_size = 0; DTNMP_DEBUG_ENTRY("midcol_to_string","(%#llx)", (unsigned long) mc); /* Step 0: Sanity Check. */ if(mc == NULL) { DTNMP_DEBUG_ERR("midcol_to_string","Bad Args.", NULL); DTNMP_DEBUG_EXIT("midcol_to_string","->NULL", NULL); return NULL; } /* Step 1: Grab the number of MIDs in the collection, and pre-allocate * space to store their printed information. */ num_items = (int) lyst_length(mc); mid_strs = (char**) MTAKE(num_items * sizeof(char*)); if(mid_strs == NULL) { DTNMP_DEBUG_ERR("midcol_to_string","Can't alloc %d bytes.", num_items * sizeof(char *)); DTNMP_DEBUG_EXIT("midcol_to_string","->NULL",NULL); return NULL; } /* Step 2: Grab the pretty-print of individual MIDs. We need this anyway * and it will help us get the sizing right. */ for(elt = lyst_first(mc); (elt && (i < num_items)); elt=lyst_next(elt)) { mid_t *cur_mid = (mid_t*) lyst_data(elt); mid_strs[i] = mid_to_string(cur_mid); tot_size += strlen(mid_strs[i]); i++; } /* Step 3: Calculate size of the MID collection print and allocate it. */ tot_size += 5 + /* "MC : " */ 2 + /* trailer */ num_items; /* space between MIDs. */ if((result = (char *) MTAKE(tot_size)) == NULL) { DTNMP_DEBUG_ERR("midcol_to_string","Can't alloc %d bytes.", tot_size); for(i = 0; i < num_items; i++) { MRELEASE(mid_strs[i]); } MRELEASE(mid_strs); DTNMP_DEBUG_EXIT("midcol_to_string","->NULL",NULL); return NULL; } else { cursor = result; } /* Step 4: Fill in the MID collection string. */ cursor += sprintf(cursor,"MC : "); for(i = 0; i < num_items; i++) { cursor += sprintf(cursor,"%s ",mid_strs[i]); MRELEASE(mid_strs[i]); } cursor += sprintf(cursor,".\n"); MRELEASE(mid_strs); /* Step 5: Sanity check. */ if((cursor - result) > tot_size) { DTNMP_DEBUG_ERR("midcol_to_string", "OVERWROTE! Alloc %d, wrote %llu.", tot_size, (cursor-result)); MRELEASE(result); DTNMP_DEBUG_EXIT("mid_to_string","->NULL",NULL); return NULL; } DTNMP_DEBUG_INFO("midcol_to_string","Wrote %llu into %d string.", (cursor -result), tot_size); DTNMP_DEBUG_EXIT("midcol_to_string","->%#llx",result); return result; }
adm_ctrl_t* adm_find_ctrl(mid_t *mid) { LystElt elt = 0; adm_ctrl_t *cur = NULL; DTNMP_DEBUG_ENTRY("adm_find_ctrl","(%#llx)", mid); /* Step 0 - Sanity Check. */ if(mid == NULL) { DTNMP_DEBUG_ERR("adm_find_ctrl", "Bad Args.", NULL); DTNMP_DEBUG_EXIT("adm_find_ctrl", "->NULL.", NULL); return NULL; } for(elt = lyst_first(gAdmCtrls); elt; elt = lyst_next(elt)) { cur = (adm_ctrl_t *) lyst_data(elt); char *tmp1 = mid_to_string(mid); char *tmp2 = mid_to_string(cur->mid); MRELEASE(tmp1); MRELEASE(tmp2); if (mid_compare(mid, cur->mid, 0) == 0) { break; } /** / * Step 1.1 - Determine if we need to account for parameters. * / if(cur->num_parms == 0) { / * Step 1.1.1 - If no params, straight compare * / if((mid->raw_size == cur->mid_len) && (memcmp(mid->raw, cur->mid, mid->raw_size) == 0)) { break; } } else { uvast tmp; unsigned char *cursor = (unsigned char*) &(cur->mid[1]); / * Grab size less paramaters. Which is SDNV at [1]. * / / * \todo: We need a more refined compare here. For example, the * code below will not work if tag values are used. * / unsigned long bytes = decodeSdnv(&tmp, cursor); if(memcmp(mid->raw, cur->mid, tmp + bytes + 1) == 0) { break; } } */ cur = NULL; } /* Step 2 - Return what we found, or NULL. */ DTNMP_DEBUG_EXIT("adm_find_ctrl", "->%llx.", cur); return cur; }