static void check_str_wrapper(void) { int ret; hi_handle_t *hi_handle; char key[32]; uint16_t i; const char *data = "data element"; void *data_ptr; fputs(" o check string wrapper functions tests ...", stdout); ret = hi_init_str(&hi_handle, 23); assert(ret == 0); for (i = 0; i < 23; i++) { sprintf(key, "%u", i); ret = hi_insert_str(hi_handle, key, data); assert(ret == 0); ret = hi_get_str(hi_handle, key, &data_ptr); assert(ret == 0); } ret = hi_fini(hi_handle); assert(ret == 0); puts(" passed"); }
PBXRESULT PbniHashStr::Get(PBCallInfo *ci) { PBXRESULT pbxr = PBX_OK; int iRet; void *data_ptr; if ( ci->pArgs->GetAt(0)->IsNull()) { // if any of the passed arguments is null, return the null value ci->returnValue->SetToNull(); } else { pbstring key = ci->pArgs->GetAt(0)->GetString(); LPCTSTR tszKey = m_pSession->GetString(key); //convert the key into ansi int iKeyLen = wcstombs(NULL, (LPWSTR)tszKey, 0) + 1; LPSTR ansiKey = (LPSTR)malloc(iKeyLen); wcstombs(ansiKey, (LPWSTR)(LPWSTR)tszKey, iKeyLen); ReleaseSessionString(tszKey); //search the key iRet = hi_get_str(m_hi_handle, ansiKey, (void**)&data_ptr); if (HI_ERR_SUCCESS == iRet){ //ci->returnValue->SetString((LPCWSTR)data_ptr); LPCTSTR tmp_str = m_pSession->GetString(((IPB_Value*)data_ptr)->GetString()); ci->returnValue->SetString(tmp_str); ReleaseSessionString( tmp_str ); } else ci->returnValue->SetToNull(); } return pbxr; }
int reexport (ipfixt_node_t *t, ipfix_datarecord_t *d) { ipfix_template_t* outtemplate; if (hi_get_str(templates, t->ident, (void**)&outtemplate )) { if ( ipfix_new_data_template( ipfixh, &outtemplate, t->ipfixt->nfields ) <0 ) { fprintf( stderr, "ipfix_new_template() failed in reexport: %s\n", strerror(errno) ); exit(1); } int i; fprintf( stdout, "reexporting template %s as id %i.\n", t->ident, outtemplate->tid ); for (i=0; i < t->ipfixt->nfields; i++) { if (ipfix_add_field( ipfixh, outtemplate, t->ipfixt->fields[i].elem->ft->eno, t->ipfixt->fields[i].elem->ft->ftype, t->ipfixt->fields[i].flength ) <0 ) { fprintf( stderr, "ipfix_add_field() failed in reexport: %s - eno = %i, type = %i, length = %i\n", strerror(errno), t->ipfixt->fields[i].elem->ft->eno, t->ipfixt->fields[i].elem->ft->ftype, t->ipfixt->fields[i].flength); exit(1); } //fprintf( stdout, " added field %i:%i(%i||%i,%i)\n", outtemplate->fields[i].elem->ft->eno, outtemplate->fields[i].elem->ft->ftype, outtemplate->fields[i].elem->ft->length, t->ipfixt->fields[i].flength, t->ipfixt->fields[i].elem->ft->length ); } hi_insert_str(templates, t->ident, outtemplate); } if (verbose_level>1) { int i; char tmps[256]; fprintf( stdout, "data record, tid = %i.\n", outtemplate->tid); for (i=0; i < outtemplate->nfields; i++) { t->ipfixt->fields[i].elem->snprint(tmps, 255, d->addrs[i], d->lens[i]); fprintf( stdout, "%i: %s\n", i, tmps); } } ipfix_export_array(ipfixh, outtemplate, outtemplate->nfields, d->addrs, d->lens); /* TODO FIXME do a flush only every now and then instead of each time */ ipfix_export_flush(ipfixh); return 0; }
static void check_preambel_test(void) { int ret; hi_handle_t *hi_handle; const char *key = "23"; const char *data = "data element"; void *data_ptr; /* initialize hashish handle */ hi_init_str(&hi_handle, 23); /* insert an key/data pair */ ret = hi_insert_str(hi_handle, key, data); /* search for a pair with a string key and store result */ hi_get_str(hi_handle, key, &data_ptr); /* free the hashish handle */ hi_fini(hi_handle); }