/******************************************************************* * fm_zonemap_pol_get_lineage_find_bucket(): * * Given a bucket in the hash table, this function returns * the matching entry in that bucket. * *******************************************************************/ static ZonemapHashEntry_t * fm_zonemap_pol_get_lineage_find_bucket( ZonemapHashEntry_t *pBucket, const char *pszTarget, pin_errbuf_t *ebufp) { ZonemapHashEntry_t *pCurNode; /* Debug */ PIN_ERR_LOG_MSG(PIN_ERR_LEVEL_DEBUG, "fm_zonemap_pol_get_lineage_find_poid_in_bucket starting"); /* For each node in list... */ for (pCurNode = pBucket; pCurNode != NULL; pCurNode = pCurNode->pNext) { /* Is this the one we want? */ if (!strcmp(pszTarget, pCurNode->pszZonemapName)) { /* Yes: return */ break; } } /* Debug */ PIN_ERR_LOG_MSG(PIN_ERR_LEVEL_DEBUG, "fm_zonemap_pol_get_lineage_find_poid_in_bucket returning"); return pCurNode; }
bool bs_CreateLECRecourse::createRecourse( pin_Session * pinp, c_NvRecord& nv, pin_flist_t **return_flistpp, pin_errbuf_t *ebufp ) { const char * file_name = NULL; string title("LEC Recourse nvRec"); nv.StringBuffer(title); PIN_ERR_LOG_MSG(PIN_ERR_LEVEL_DEBUG, (char*)title.c_str() ); /// /// -- translation --------------------------- /// PIN_ERR_LOG_MSG(PIN_ERR_LEVEL_DEBUG,(char*)"Unpacking..." ); string sBtn = nv.value("BTN"); string sAmount = nv.value("AMOUNT"); string sRecordType = nv.value("TYPE"); string sAuthDate = nv.value("DATE"); string sReasonCode = nv.value("RESULT"); string fn = nv.value("FILENAME"); string sVersion = nv.value("VER"); if (! fn.empty() ) file_name = fn.c_str(); //---e default values if (sReasonCode.empty())sReasonCode.assign("00"); if (sAuthDate.empty())sAuthDate.assign("080228"); /// /// -- call base function --------------------------- /// PIN_ERR_LOG_MSG(PIN_ERR_LEVEL_DEBUG,(char*)"Calling base function..." ); PIN_ERR_CLEAR_ERR(ebufp); bs_CreateLECRecourse::createRecourse( pinp, sRecordType.c_str(), sBtn.c_str(), sAuthDate.c_str(), sReasonCode.c_str(), sAmount.c_str(), sVersion.c_str(), file_name, return_flistpp, ebufp ); if (PIN_ERR_IS_ERR(ebufp)) return false; return true; };
bool bs_UpdateContactInfo::updateContactInfo( pin_Session * pinp, bs_NvRecord& nv, pin_flist_t **return_flistpp, pin_errbuf_t *ebufp ) { c_Decimal amount_cp; poid_t * account_pdp = NULL; pin_decimal_t * amountp = NULL; string account_no = nv.value(ACCOUNT_NO); string str_poid_id0 = nv.value(ACCOUNT_OBJ_ID0); string str_source = nv.value(SOURCE); bool rc = false; int64 database = pinp->getDBNumber(); ostringstream account_descr; /// /// -- translation --------------------------- /// string title("updateContactInfo nvRec"); PIN_ERR_LOG_MSG(PIN_ERR_LEVEL_DEBUG, (char*)nv.StringBuffer(title).c_str()); //-- translate account poid----------- c_Poid account_cp; if ( ! nv.resolve_AccountPoid(pinp, account_cp)) { pin_set_err(ebufp, PIN_ERRLOC_APP, PIN_ERRCLASS_APPLICATION, PIN_ERR_NOT_FOUND,PIN_FLD_ACCOUNT_OBJ, 0, 0); PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR, (char*)"bad account info", ebufp ); return false; }; //-- translate others ----------- bs_SignupRec bsr; sprintf(bsr.s_caddress, "%s\0", nv.value(CONTACT_ADDRESS).c_str()); sprintf(bsr.s_ccity, "%s\0",nv.value(CONTACT_CITY).c_str()); sprintf(bsr.s_cstate, "%s\0",nv.value(CONTACT_STATE).c_str()); sprintf(bsr.s_czip, "%s\0",nv.value(CONTACT_ZIPCODE).c_str()); sprintf(bsr.s_lastName, "%s\0",nv.value(CONTACT_LASTNAME).c_str()); sprintf(bsr.s_firstName, "%s\0", nv.value(CONTACT_FIRSTNAME).c_str()); sprintf(bsr.s_cemail_addr, "%s\0",nv.value(CONTACT_EMAIL).c_str()); sprintf(bsr.s_evePhone, "%s\0", nv.value(EVENING_PHONE).c_str()); sprintf(bsr.s_dayPhone, "%s\0", nv.value(DAY_PHONE).c_str()); /// /// -- call base function --------------------------- /// PIN_ERR_CLEAR_ERR(ebufp); rc = bs_UpdateContactInfo::updateContactInfo( pinp, account_cp.borrow(), &bsr, str_source, return_flistpp, ebufp ); return rc; };
/******************************************************************* * Function bodies. *******************************************************************/ void fm_zonemap_pol_get_lineage_init() { int32 *i_ptr = NULL; int32 error = 0; PIN_HEAP_VAR; PIN_ERR_LOG_MSG(PIN_ERR_LEVEL_DEBUG, "fm_zonemap_pol_get_lineage_init Enter"); /* * Init ProductHashArray */ if (nInitDone == PIN_BOOLEAN_FALSE) { nInitDone = PIN_BOOLEAN_TRUE; /* * initialize the interval */ interval = 3600; /* * read the value of this variable from the pin.conf file. If it * doesn't exist then the default value stays. */ pin_conf("fm_zonemap_pol", "update_interval", PIN_FLDT_INT, (caddr_t *)&i_ptr, &error); if (error == PIN_ERR_NONE) { interval = *i_ptr; } if (i_ptr) { free(i_ptr); } PIN_SET_GLOBAL_HEAP; /* * Init mutex */ MutexInit(HashTableLock); PIN_RESET_GLOBAL_HEAP; } PIN_ERR_LOG_MSG(PIN_ERR_LEVEL_DEBUG, "fm_zonemap_pol_get_lineage_init Exit"); }
/******************************************************************* * fm_cust_pol_valid_pwd_srvc(): * * Validate the service level password. * *******************************************************************/ static void fm_cust_pol_valid_pwd_srvc( pcm_context_t *ctxp, pin_flist_t *i_flistp, pin_flist_t *r_flistp, pin_errbuf_t *ebufp) { u_int result; const char *pwd = NULL; if (PIN_ERR_IS_ERR(ebufp)) return; PIN_ERR_CLEAR_ERR(ebufp); /*********************************************************** * Pass by default. ***********************************************************/ result = PIN_CUST_VERIFY_PASSED; PIN_FLIST_FLD_SET(r_flistp, PIN_FLD_RESULT, (void *)&result, ebufp); pwd = PIN_FLIST_FLD_GET(i_flistp, PIN_FLD_PASSWD_CLEAR, 0, ebufp); if (pwd && !strncmp(pwd, FM_PWD_INVALID_PASSWD, strlen(FM_PWD_INVALID_PASSWD))) { PIN_ERR_LOG_MSG(PIN_ERR_LEVEL_ERROR, " Invalid Password."); pin_errbuf_set_err( ebufp, PIN_ERRLOC_FM, PIN_ERRCLASS_SYSTEM_DETERMINATE, PIN_ERR_VALIDATION_FAILED, 0, 0, 0, PIN_DOMAIN_ERRORS, PIN_ERR_VALIDATE_PASSWORD,1, 0, NULL); goto cleanup; /***********/ } /*********************************************************** * If it's there, is it too long? * Try to validate based on /config/fld_validate (Pswd) obj. ***********************************************************/ fm_cust_pol_validate_fld_value( ctxp, i_flistp, i_flistp, r_flistp, PIN_FLD_PASSWD_CLEAR, 0, /* element_id */ "Pswd", 1, ebufp); cleanup: /*********************************************************** * Error? ***********************************************************/ if (PIN_ERR_IS_ERR(ebufp)) { PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR, "fm_cust_pol_valid_pwd_srvc error", ebufp); } return; }
/******************************************************************* * fm_zonemap_pol_get_lineage_hash_zone_name(): * * Returns the hash value for the given zone name (a string) * *******************************************************************/ static int32 fm_zonemap_pol_get_lineage_hash_zone_name( const char *pszTarget) { unsigned long nHashVal = 0; unsigned long nCount; unsigned long nMask = 0xF0000000; /* Debug */ PIN_ERR_LOG_MSG(PIN_ERR_LEVEL_DEBUG, "fm_zonemap_pol_get_lineage_hash_zone_name starting"); /* * Use your basic ELF hash */ while (*pszTarget) { nHashVal = (nHashVal << 4) + *pszTarget++; if (nCount = nHashVal & nMask) { nHashVal ^= nCount >> 24; } nHashVal &= ~nCount; }
/* * Search for a brand name within a brand. */ static void fm_cust_pol_is_brandname_unique_within_brand( pcm_context_t *ctxp, poid_t *poidp, char *namep, pin_flist_t **r_flistpp, pin_errbuf_t *ebufp) { pin_flist_t *flistp = (pin_flist_t *)NULL; pin_flist_t *rlistp = (pin_flist_t *)NULL; pin_flist_t *sublistp; poid_t *search_poidp; int32 int_val; int32 cred; pin_account_type_t brand_type = PIN_ACCOUNT_TYPE_BRAND; pin_cookie_t cookie = (pin_cookie_t)NULL; pin_flist_t *b_flistp = NULL; pin_flist_t *t_flistp = NULL; poid_t *b_pdp = NULL; poid_t *g_pdp = NULL; poid_t *rootp = NULL; int32 elemid = 0; int under_host = PIN_BOOLEAN_FALSE; void *vp = NULL; /* * If there are pending errors, then short circuit immediately */ if (PIN_ERR_IS_ERR(ebufp)) return; PIN_ERR_CLEAR_ERR(ebufp); fm_utils_lineage_get_brand_hierarchy(ctxp, poidp, &b_flistp, ebufp); if (PIN_ERR_IS_ERR(ebufp)) { PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR, "fm_cust_pol_is_brandname_unique_within_brand() : " "Call to get brand hierarchy failed ", ebufp); PIN_FLIST_DESTROY_EX (&b_flistp, NULL); fm_cust_pol_read_err_return_list(poidp, namep, r_flistpp, ebufp); goto cleanup; } PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG, "Got brand hierarchy. Return flist :", b_flistp); t_flistp = PIN_FLIST_ELEM_GET_NEXT(b_flistp, PIN_FLD_RESULTS, &elemid, 1, &cookie, ebufp); if (PIN_ERR_IS_ERR(ebufp) || t_flistp == (pin_flist_t *)NULL) { PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR, "fm_cust_pol_is_brandname_unique_within_brand() : " "Call to get first brand failed ", ebufp); PIN_FLIST_DESTROY_EX (&b_flistp, NULL); fm_cust_pol_read_err_return_list(poidp, namep, r_flistpp, ebufp); goto cleanup; } /******************************************** * Get the first brand object from hierarchy ********************************************/ b_pdp = PIN_FLIST_FLD_GET(t_flistp, PIN_FLD_BRAND_OBJ, 0, ebufp); /*************************************************************** * During the brand creation, the first brand object from the * the hierarchy is the parent brand. But, for an existing * brand, the first object is self, the next one in hierarchy * is the parent brand. ***************************************************************/ if (!PIN_POID_COMPARE(b_pdp, poidp, 0, ebufp)) { PIN_ERR_LOG_MSG(PIN_ERR_LEVEL_DEBUG, "first brand is self"); t_flistp = PIN_FLIST_ELEM_GET_NEXT(b_flistp, PIN_FLD_RESULTS, &elemid, 1, &cookie, ebufp); if (PIN_ERR_IS_ERR(ebufp) || t_flistp == (pin_flist_t *)NULL) { PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR, "fm_cust_pol_is_brandname_unique_within_brand() : " "Call to get second brand failed ", ebufp); PIN_FLIST_DESTROY_EX (&b_flistp, NULL); fm_cust_pol_read_err_return_list(poidp, namep, r_flistpp, ebufp); goto cleanup; } /* Get the parent brand object */ b_pdp = PIN_FLIST_FLD_GET(t_flistp, PIN_FLD_BRAND_OBJ, 0, ebufp); } else { PIN_ERR_LOG_MSG(PIN_ERR_LEVEL_DEBUG, "first brand is parent"); } PIN_ERR_LOG_POID(PIN_ERR_LEVEL_DEBUG, "parent brand = ", b_pdp); /*************************************************************** * Check to see if we are creating brand under brandhost ***************************************************************/ rootp = PIN_POID_CREATE(PIN_POID_GET_DB(poidp), "/account", 1, ebufp); if (!PIN_POID_COMPARE(b_pdp, rootp, 0, ebufp)) { under_host = PIN_BOOLEAN_TRUE; /* creating brand under brandhost */ } else { /* creating sub-brand under a brand */ /* get the group_obj_id0 for the parent brand */ cred = CM_FM_BEGIN_OVERRIDE_SCOPE(CM_CRED_SCOPE_OVERRIDE_ROOT); g_pdp = fm_utils_lineage_get_billing_group_by_parent(ctxp, b_pdp, ebufp); CM_FM_END_OVERRIDE_SCOPE(cred); if (PIN_ERR_IS_ERR(ebufp) || g_pdp == (poid_t*)NULL) { PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR, "fm_cust_pol_is_brandname_unique_within_brand() : " "Call to get parent group failed ", ebufp); PIN_POID_DESTROY(rootp, NULL); PIN_FLIST_DESTROY_EX (&b_flistp, NULL); fm_cust_pol_read_err_return_list(poidp, namep, r_flistpp, ebufp); goto cleanup; } } PIN_POID_DESTROY(rootp, NULL); PIN_FLIST_DESTROY_EX (&b_flistp, NULL); /* * Create search flist to try to figure out if someother brand already * has this name within the parent brand. */ flistp = PIN_FLIST_CREATE(ebufp); search_poidp = PIN_POID_CREATE(PIN_POID_GET_DB(poidp), "/search", -1, ebufp); PIN_FLIST_FLD_PUT(flistp, PIN_FLD_POID, (void *)search_poidp, ebufp); int_val = SRCH_DISTINCT; PIN_FLIST_FLD_SET(flistp, PIN_FLD_FLAGS, (void *)&int_val, ebufp); /*************************************************************** * We need different search templates for checking duplicate * brandnames under the brandhost or another brand. * The brandhost doesnot have an entry in the /group/billing * storable class. The only way we can get the names of the * existing brands under the brandhost is to check the lineage * tag. Arguments 1 to 3 are the same for both search templates, * but arguments 4 & 5 are different. ***************************************************************/ if (under_host == PIN_BOOLEAN_FALSE) { /* creating sub-brands under a brand */ PIN_FLIST_FLD_SET(flistp, PIN_FLD_TEMPLATE, (void *)TEMPLATE_UNIQUE_UNDER_BRAND, ebufp); } else { /* creating brand under brandhost */ PIN_FLIST_FLD_SET(flistp, PIN_FLD_TEMPLATE, (void *)TEMPLATE_UNIQUE_UNDER_BRANDHOST, ebufp); } PIN_FLIST_ELEM_SET(flistp, NULL, PIN_FLD_RESULTS, 0, ebufp); /* * Arg 1 is the type of the account; only interested in brand accounts */ sublistp = PIN_FLIST_ELEM_ADD(flistp, PIN_FLD_ARGS, 1, ebufp); PIN_FLIST_FLD_SET(sublistp, PIN_FLD_ACCOUNT_TYPE, (void *)&brand_type, ebufp); /* * Arg 2 is the name of the brand. */ sublistp = PIN_FLIST_ELEM_ADD(flistp, PIN_FLD_ARGS, 2, ebufp); PIN_FLIST_FLD_SET(sublistp, PIN_FLD_NAME, (void *)namep, ebufp); /* * Arg 3 -- POID of account */ sublistp = PIN_FLIST_ELEM_ADD(flistp, PIN_FLD_ARGS, 3, ebufp); PIN_FLIST_FLD_PUT(sublistp, PIN_FLD_POID, NULL, ebufp); if (under_host == PIN_BOOLEAN_FALSE) { /* creating sub-brands under a brand */ /* * Arg 4 -- OBJECT_ID of members from /group/billing */ sublistp = PIN_FLIST_ELEM_ADD(flistp, PIN_FLD_ARGS, 4, ebufp); sublistp = PIN_FLIST_ELEM_ADD(sublistp, PIN_FLD_MEMBERS, PIN_ELEMID_ANY, ebufp); PIN_FLIST_FLD_PUT(sublistp, PIN_FLD_OBJECT, (void *)NULL, ebufp); /* * Arg 5 -- POID of the group */ sublistp = PIN_FLIST_ELEM_ADD(flistp, PIN_FLD_ARGS, 5, ebufp); PIN_FLIST_FLD_SET(sublistp, PIN_FLD_POID, (void *)g_pdp, ebufp); } else { /* creating brand under brandhost */ /* * Arg 4 -- Parent of the group */ sublistp = PIN_FLIST_ELEM_ADD(flistp, PIN_FLD_ARGS, 4, ebufp); PIN_FLIST_FLD_PUT(sublistp, PIN_FLD_PARENT, NULL, ebufp); /* * Arg 5 -- LINEAGE of account */ /* accounts under brandhost have only one ":" in their lineage tag. We want to exclude others. */ vp = (void *)"%:%:%"; sublistp = PIN_FLIST_ELEM_ADD(flistp, PIN_FLD_ARGS, 5, ebufp); PIN_FLIST_FLD_SET(sublistp, PIN_FLD_LINEAGE, vp, ebufp); } /* * Arg 6 -- POID of current account */ sublistp = PIN_FLIST_ELEM_ADD(flistp, PIN_FLD_ARGS, 6, ebufp); PIN_FLIST_FLD_SET(sublistp, PIN_FLD_POID, poidp, ebufp); /* * For completeness, dump the input flist if debugging is enabled. */ PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG, "fm_cust_pol_is_brandname_unique_within_brand search input flist:", flistp); /* * Ready to search! Temporarily suspend search to ensure that * all brands are traversed. */ cred = CM_FM_BEGIN_OVERRIDE_SCOPE(CM_CRED_SCOPE_OVERRIDE_ROOT); PCM_OP(ctxp, PCM_OP_GLOBAL_SEARCH, PCM_OPFLG_COUNT_ONLY, flistp, &rlistp, ebufp); CM_FM_END_OVERRIDE_SCOPE(cred); /* * For completeness, dump the results flist if debugging is enabled * and we actually have a results flist. */ if(rlistp != (pin_flist_t *)NULL) { PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG, "fm_cust_pol_is_brandname_unique_within_brand search output flist:", rlistp); } /* * See if there is a brand out there right now that already has * this name. If so, flag it as an error. */ cookie = (pin_cookie_t)NULL; int_val = 0; PIN_FLIST_ELEM_GET_NEXT(rlistp, PIN_FLD_RESULTS, &int_val, 1, &cookie, ebufp); if(int_val > 0) { *r_flistpp = PIN_FLIST_CREATE(ebufp); PIN_FLIST_FLD_SET(*r_flistpp, PIN_FLD_POID, (void *)poidp, ebufp); fm_cust_pol_valid_add_fail(*r_flistpp, PIN_FLD_NAME, 0, PIN_CUST_VAL_ERR_DUPE, PIN_CUST_DUPE_VALUE_ERR_MSG, (void *)namep, ebufp); pin_set_err(ebufp, PIN_ERRLOC_FM, PIN_ERRCLASS_SYSTEM_DETERMINATE, PIN_ERR_DUPLICATE, PIN_FLD_NAME, 0, 0); } cleanup: /* * Cleanup and return */ PIN_FLIST_DESTROY_EX(&flistp, NULL); PIN_FLIST_DESTROY_EX(&rlistp, NULL); PIN_POID_DESTROY(g_pdp, NULL); }
/******************************************************************* * Main * * This sets up the parameters and then calls the FM. * *******************************************************************/ int main( int argc, char *argv[]) { pcm_context_t *ctxp; pin_flist_t *flistp = NULL; pin_flist_t *a_flistp = NULL; pin_flist_t *r_flistp = NULL; poid_t *acct_pdp = NULL; poid_t *srvc_pdp = NULL; u_int opcode; int64 database; void *vp; char logfile[256]; char *c_ptr = (char *)NULL; char *program; int32 err; pin_errbuf_t ebuf; PIN_ERR_CLEAR_ERR(&ebuf); /* * Logging initialization */ program = basename(argv[0]); PIN_ERR_SET_PROGRAM(program); PIN_ERR_SET_LEVEL(PIN_ERR_LEVEL_WARNING); strcpy(logfile, "default.pinlog"); pin_conf(program, "logfile", PIN_FLDT_STR, (caddr_t *)&(c_ptr), &err); if (c_ptr != (char *)NULL) { pin_strlcpy(logfile, c_ptr, sizeof(logfile)); pin_free(c_ptr); c_ptr = (char *)NULL; } PIN_ERR_SET_LOGFILE(logfile); /* * Check the input. */ if (argc != 3) { usage(argv[0]); PIN_ERR_LOG_MSG(PIN_ERR_LEVEL_ERROR, "bad # of arguments"); exit(1); } /* * Initialize PCM connection. */ PCM_CONNECT(&ctxp, &database, &ebuf); if (PIN_ERR_IS_ERR(&ebuf)) { PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR, "pcm_connect error", &ebuf); exit(2); } /* * Create the poid prototype. */ srvc_pdp = PIN_POID_CREATE(database, argv[1], 0, &ebuf); /* * Look up the account. */ flistp = PIN_FLIST_CREATE(&ebuf); vp = (void *)srvc_pdp; PIN_FLIST_FLD_SET(flistp, PIN_FLD_POID, vp, &ebuf); vp = (void *)argv[2]; PIN_FLIST_FLD_SET(flistp, PIN_FLD_LOGIN, vp, &ebuf); opcode = PCM_OP_ACT_FIND; PCM_OP(ctxp, opcode, 0, flistp, &a_flistp, &ebuf); /* * Did we find anything? */ acct_pdp = PIN_FLIST_FLD_GET(a_flistp, PIN_FLD_ACCOUNT_OBJ, 0, &ebuf); if (!PIN_POID_IS_NULL(acct_pdp)) { /* * Advisory (or add confirm?) */ fprintf(stdout, "Deleting Account:\t"); pin_poid_print(acct_pdp, 0, &ebuf); fprintf(stdout, "\n"); /* * Put the real account poid on the flist * (The account_obj field will just be ignored) */ vp = (void *)acct_pdp; PIN_FLIST_FLD_SET(a_flistp, PIN_FLD_POID, vp, &ebuf); /* * Delete the account. */ opcode = PCM_OP_CUST_DELETE_ACCT; PCM_OP(ctxp, opcode, 0, a_flistp, &r_flistp, &ebuf); /* * Did we delete or not? */ if (PIN_ERR_IS_ERR(&ebuf)) { fprintf(stdout, "Account Deletion Error Occurred.\n"); PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR, "op_cust_delete_acct error", &ebuf); } else { fprintf(stdout, "Account Deleted.\n"); } } else { /* * FIND error. */ fprintf(stdout, "Unable to locate Account.\n"); PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR, "op_act_find error", &ebuf); } /* * Close the PCM context. */ PCM_CONTEXT_CLOSE(ctxp, 0, &ebuf); /* * Clean up. */ /* Free local memory. */ PIN_FLIST_DESTROY(flistp, NULL); PIN_FLIST_DESTROY(a_flistp, NULL); PIN_FLIST_DESTROY(r_flistp, NULL); /* No errors. */ return(0); }
//**************************************************** // updateStatus // Pre: // Post: // bool bs_UpdateStatus::updateStatus( pin_Session * pinp, poid_t * account_pdp, poid_t * service_pdp, int status, int status_flags, string source, string description, pin_flist_t **return_flistpp, pin_errbuf_t *ebufp ) { pin_flist_t * x_flistp = NULL; pin_flist_t * d_flistp = NULL; pin_flist_t * f_flistp = NULL; pin_flist_t * f_outflistp = NULL; pin_errbuf_t localebuf; int flag=status_flags; poid_t * pdp = NULL; void * vp = NULL; bool rc; const string this_program("updateStatus"); if ( source.empty() ) { source.assign(this_program); } if ( description.empty() ) { description.assign(this_program); } PIN_ERR_CLEAR_ERR(ebufp); //--enter function-------------- PIN_ERR_LOG_MSG(PIN_ERR_LEVEL_DEBUG, (char*)this_program.c_str() ); /*--- Create set_status ---*/ if ( status == PIN_STATUS_ACTIVE && status_flags <= 0 ) { PIN_ERR_LOG_MSG(PIN_ERR_LEVEL_ERROR, (char*)"This is an activation - get existing flags" ); PIN_ERR_CLEAR_ERR(&localebuf); pdp = ( pin_poid_is_null(service_pdp)) ? account_pdp : service_pdp; f_flistp = PIN_FLIST_CREATE(ebufp); PIN_FLIST_FLD_SET(f_flistp, PIN_FLD_POID, (void*)pdp, &localebuf); PIN_FLIST_FLD_SET(f_flistp, PIN_FLD_STATUS_FLAGS, (void*)NULL, &localebuf); if ( pinp->call_opcode( PCM_OP_READ_FLDS, 0, f_flistp, &f_outflistp, &localebuf)) { if ((vp=PIN_FLIST_FLD_GET( f_outflistp, PIN_FLD_STATUS_FLAGS, 1, &localebuf )) != NULL ) status_flags = *(int*)vp; } if (f_flistp) PIN_FLIST_DESTROY(f_flistp,NULL); f_flistp = NULL; if (f_outflistp) PIN_FLIST_DESTROY_EX(&f_outflistp,NULL); f_outflistp = NULL; } if ( status_flags < 0) { status_flags = 0; } /*--- Create set_status ---*/ x_flistp = PIN_FLIST_CREATE(ebufp); PIN_FLIST_FLD_SET(x_flistp, PIN_FLD_POID, account_pdp, ebufp); if ( ! pin_poid_is_null(service_pdp) ) PIN_FLIST_FLD_SET(x_flistp, PIN_FLD_SERVICE_OBJ, service_pdp, ebufp); PIN_FLIST_FLD_SET(x_flistp, PIN_FLD_PROGRAM_NAME, (void*)source.c_str(), ebufp); PIN_FLIST_FLD_SET(x_flistp, PIN_FLD_DESCR, (void*)description.c_str(), ebufp); d_flistp = PIN_FLIST_ELEM_ADD( x_flistp, PIN_FLD_STATUSES, PIN_ELEMID_ASSIGN, ebufp ); PIN_FLIST_FLD_SET(d_flistp, PIN_FLD_STATUS, (void*)&status, ebufp); PIN_FLIST_FLD_SET(d_flistp, PIN_FLD_STATUS_FLAGS, (void*)&status_flags, ebufp); if ( (! pin_poid_is_null(service_pdp)) && (status == PIN_STATUS_CLOSED) ) { rc = pinp->call_opcode( PCM_OP_CUST_SET_STATUS, 0, x_flistp, return_flistpp, ebufp); } else { rc = pinp->call_opcode( UOL_OP_SET_STATUS, 0, x_flistp, return_flistpp, ebufp); } PIN_ERR_LOG_FLIST( PIN_ERR_LEVEL_DEBUG,(char*)"leaving bs_UpdateStatus::updateStatus" , *return_flistpp ); if (x_flistp) PIN_FLIST_DESTROY(x_flistp,NULL); return rc; }
bool bs_UpdateStatus::updateStatus( pin_Session * pinp, bs_NvRecord& nv, pin_flist_t **return_flistpp, pin_errbuf_t *ebufp ) { c_Poid service_cp; c_Status status_cp; poid_t * service_pdp = NULL; pin_decimal_t * amountp = NULL; bool rc = false; char buff[255]; int64 database = pinp->getDBNumber(); ostringstream account_descr; string title("updateStatus nvRec"); nv.StringBuffer(title); PIN_ERR_LOG_MSG(PIN_ERR_LEVEL_DEBUG, (char*)title.c_str() ); /// /// -- translation --------------------------- /// PIN_ERR_LOG_MSG(PIN_ERR_LEVEL_DEBUG,(char*)"Unpacking..." ); string str_account_obj_id0 = nv.value(ACCOUNT_OBJ_ID0); string account_no = nv.value(ACCOUNT_NO); string str_service_obj_id0 = nv.value(SERVICE_OBJ_ID0); string str_service_obj_type = nv.value(SERVICE_OBJ_TYPE); string str_status = nv.value(STATUS); string str_status_flags = nv.value(STATUS_FLAGS); string str_source = nv.value(SOURCE); string str_descr = nv.value(DESCRIPTION); PIN_ERR_LOG_MSG(PIN_ERR_LEVEL_DEBUG,(char*)"Translating status..." ); if ( ! status_cp.set(str_status) ) { ostringstream os; sprintf(buff, "Cannot translate %s to a known status ...", str_status.c_str() ); PIN_ERR_LOG_MSG(PIN_ERR_LEVEL_DEBUG,(char*)buff ); pin_set_err(ebufp, PIN_ERRLOC_APP, PIN_ERRCLASS_APPLICATION, PIN_ERR_BAD_VALUE, PIN_FLD_STATUS, 0, 0); PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,(char*)str_status.c_str(), ebufp ); return false; } //-- translate account poid----------- PIN_ERR_LOG_MSG(PIN_ERR_LEVEL_DEBUG,(char*)"Locating account..." ); c_Poid account_cp; if ( ! nv.resolve_AccountPoid(pinp, account_cp)) { sprintf(buff, "Cannot locate account %s ...", str_account_obj_id0.c_str() ); pin_set_err(ebufp, PIN_ERRLOC_APP, PIN_ERRCLASS_APPLICATION, PIN_ERR_NOT_FOUND,PIN_FLD_ACCOUNT_OBJ, 0, 0); PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR, (char*)buff, ebufp ); return false; }; //-- get service poid----------- bs_ServiceInfo service; ostringstream service_descr; int service_count = 0; if (! str_service_obj_id0.empty() ) { PIN_ERR_LOG_MSG(PIN_ERR_LEVEL_DEBUG,(char*)"Create service poid from poid_id0..." ); int64 poid_id0 = atol(str_service_obj_id0.c_str()); service_descr << "service_obj_id0=" << str_service_obj_id0; service_cp.create(database, (char *)"/service", poid_id0 ); } else if (! str_service_obj_type.empty() ) { PIN_ERR_LOG_MSG(PIN_ERR_LEVEL_DEBUG,(char*)"Locate service poid from type and account poid ..." ); service_descr << "service_type=" << str_service_obj_type; if((rc = service.loadByAccount_Type( pinp, account_cp.borrow(), str_service_obj_type, service_count )) == true ) service_pdp = service.service_pdp; rc = ( ! pin_poid_is_null( service_pdp ) ); } else { PIN_ERR_LOG_MSG(PIN_ERR_LEVEL_DEBUG,(char*)"No service info - assume this is an account level change..." ); rc = true; // this is an account level change } if ( PIN_ERR_IS_ERR(ebufp) || ! rc ) { if (! PIN_ERR_IS_ERR(ebufp)) pin_set_err(ebufp, PIN_ERRLOC_APP, PIN_ERRCLASS_APPLICATION, PIN_ERR_NOT_FOUND,PIN_FLD_SERVICE_OBJ, 0, 0); service_descr << "-Error: Found " << service_count << " services of this type..."; string str( service_descr.str()); PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,(char*)str.c_str(), ebufp ); return false; } //-- translate others ----------- int istatus = status_cp.get(); int status_flags = atoi( str_status_flags.c_str() ); /// /// -- call base function --------------------------- /// PIN_ERR_LOG_MSG(PIN_ERR_LEVEL_DEBUG,(char*)"Calling base function..." ); PIN_ERR_CLEAR_ERR(ebufp); rc = bs_UpdateStatus::updateStatus( pinp, account_cp.borrow(), service_pdp, istatus, status_flags, str_source, str_descr, return_flistpp, ebufp ); return rc; };
//**************************************************** // update_contactinfo // Pre: // Post: // bool bs_UpdateContactInfo::updateContactInfo( pin_Session * pinp, poid_t * account_pdp, bs_SignupRec * bsrp, string source, pin_flist_t **return_flistpp, pin_errbuf_t *ebufp ) { pin_flist_t * c_outflistp = NULL; pin_flist_t * c_flistp = NULL; pin_flist_t * t1_flistp = NULL; pin_flist_t * t2_flistp = NULL; pin_flist_t * outflistp = NULL; void * vp = NULL; int32 flags = 0; /* source name */ /* source / desc name */ const string this_program("bs_UpdateContactInfo::updateContactInfo"); if ( source.empty() ) { source.assign(this_program); } PIN_ERR_LOG_MSG(PIN_ERR_LEVEL_DEBUG, (char*)this_program.c_str() ); //--- get appropriate fields ---------- char * firstname = bsrp->s_firstName; char * lastname = bsrp->s_lastName; char * address = bsrp->s_caddress; char * city = bsrp->s_ccity; char * state = bsrp->s_cstate; char * zip = bsrp->s_czip; char * email_addr = bsrp->s_cemail_addr; int32 contact_type = PIN_NAMEINFO_BILLING; const char * country = "USA"; const char * program_name = source.c_str(); PIN_ERR_CLEAR_ERR(ebufp); /* create flist */ c_flistp = PIN_FLIST_CREATE( ebufp ); /* top level fields */ PIN_FLIST_FLD_SET(c_flistp, PIN_FLD_POID,(void *)account_pdp, ebufp); PIN_FLIST_FLD_SET(c_flistp, PIN_FLD_PROGRAM_NAME,(void *)program_name, ebufp); /* nameinfo */ t1_flistp = PIN_FLIST_ELEM_ADD(c_flistp, PIN_FLD_NAMEINFO, contact_type, ebufp); PIN_FLIST_FLD_SET(t1_flistp, PIN_FLD_FIRST_NAME,(void *)firstname, ebufp); PIN_FLIST_FLD_SET(t1_flistp, PIN_FLD_LAST_NAME,(void *)lastname, ebufp); PIN_FLIST_FLD_SET(t1_flistp, PIN_FLD_ADDRESS,(void *)address, ebufp); PIN_FLIST_FLD_SET(t1_flistp, PIN_FLD_CITY,(void *)city, ebufp); PIN_FLIST_FLD_SET(t1_flistp, PIN_FLD_STATE,(void *)state, ebufp); PIN_FLIST_FLD_SET(t1_flistp, PIN_FLD_ZIP,(void *)zip, ebufp); PIN_FLIST_FLD_SET(t1_flistp, PIN_FLD_COUNTRY,(void *)country, ebufp); PIN_FLIST_FLD_SET(t1_flistp, PIN_FLD_EMAIL_ADDR,(void *)email_addr, ebufp); PIN_ERR_CLEAR_ERR(ebufp); bool rc = pinp->call_opcode( PCM_OP_CUST_POL_UOL_SET_NAMEINFO, flags, c_flistp, &c_outflistp, ebufp); if (c_flistp) PIN_FLIST_DESTROY(c_flistp,ebufp); if (c_outflistp) PIN_FLIST_DESTROY_EX(&c_outflistp,ebufp); return rc; }
/******************************************************************* * fm_cust_pol_valid_status() * * Validate the status for an account/service. * * XXX NOOP - STUBBED ONLY - ALWAYS RETURN PASS XXX * *******************************************************************/ static void fm_cust_pol_valid_status( pcm_context_t *ctxp, pin_flist_t *i_flistp, pin_flist_t **out_flistpp, pin_errbuf_t *ebufp) { void *vp; poid_t *pdp; const char *poid_type = NULL; u_int result = PIN_CUST_VERIFY_PASSED; u_int status; if (PIN_ERR_IS_ERR(ebufp)) return; PIN_ERR_CLEAR_ERR(ebufp); /* * Create outgoing flist */ *out_flistpp = PIN_FLIST_CREATE(ebufp); pdp = PIN_FLIST_FLD_GET(i_flistp, PIN_FLD_POID, 0, ebufp); /* * Try to change root account? */ poid_type = PIN_POID_GET_TYPE(pdp); if (poid_type && strcasecmp(poid_type, "/account") == 0) { if (PIN_POID_GET_ID(pdp) == 1) { PIN_ERR_LOG_MSG( PIN_ERR_LEVEL_WARNING, "op_cust_pol_valid_status warning: root account status can't be changed"); status = PIN_STATUS_ACTIVE; PIN_FLIST_FLD_SET(i_flistp, PIN_FLD_STATUS, &status, ebufp); result = PIN_CUST_VERIFY_FAILED; fm_cust_pol_valid_add_fail( *out_flistpp, PIN_FLD_STATUS, /* u_int field */ 0, /* u_int elemid */ result, "root account status can't be changed", /* char *descr */ PIN_FLIST_FLD_GET(i_flistp, PIN_FLD_STATUS, 0, ebufp), /* void *val */ ebufp); } } else { vp = PIN_FLIST_FLD_GET(i_flistp, PIN_FLD_STATUS, 0, ebufp); if (vp) { switch (*(int32 *)vp) { case PIN_STATUS_CLOSED: case PIN_STATUS_INACTIVE: case PIN_STATUS_ACTIVE: break; default: result = PIN_CUST_VERIFY_FAILED; fm_cust_pol_valid_add_fail(*out_flistpp, PIN_FLD_STATUS, 0, result, "invalid status value", vp, ebufp); } } } if (result == PIN_CUST_VERIFY_PASSED) { PIN_FLIST_FLD_SET(*out_flistpp, PIN_FLD_POID, pdp, ebufp); vp = (void *)&result; PIN_FLIST_FLD_SET(*out_flistpp, PIN_FLD_RESULT, vp, ebufp); } /* * Error? */ if (PIN_ERR_IS_ERR(ebufp)) { PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR, "fm_cust_pol_valid_status error", ebufp); } return; }
/******************************************************************* * fm_zonemap_pol_get_lineage_rev_changed(): * * Determine whether the matrix has changed since we loaded it. * *******************************************************************/ static int32 fm_zonemap_pol_get_lineage_rev_changed( pcm_context_t *pCtx, const poid_t *pMatrixPoid, pin_errbuf_t *ebufp) { pin_flist_t *pReadPoidInFlist = NULL; pin_flist_t *pReadPoidOutFlist = NULL; poid_t *pNewPoid = NULL; int32 nRetVal; int64 in_db_no; /* Sanity check */ if (PIN_ERR_IS_ERR(ebufp)) { return PIN_BOOLEAN_FALSE; } /* Debug */ PIN_ERR_LOG_MSG(PIN_ERR_LEVEL_DEBUG, "fm_zonemap_pol_get_lineage_rev_changed starting"); /* * Create flist for reading the zonemap poid */ pReadPoidInFlist = PIN_FLIST_CREATE(ebufp); /* In multi-db case the input context DB number may be different than the one earlier cached in pMatrixPoid. * So do READ_FLDS on the DB from input context for cached zonemap poid to avoid error from CM that * a transaction is already open. */ pNewPoid = PIN_POID_COPY((poid_t *)pMatrixPoid, ebufp); in_db_no = cm_fm_get_current_db_no(pCtx); PIN_POID_SET_DB(pNewPoid, in_db_no); PIN_FLIST_FLD_PUT(pReadPoidInFlist, PIN_FLD_POID, pNewPoid, ebufp); PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG, "fm_zonemap_pol_get_lineage_rev_changed zonemap read_flds input flist", pReadPoidInFlist); /* * Read current poid from DB */ PCM_OP(pCtx, PCM_OP_READ_FLDS, 0, pReadPoidInFlist, &pReadPoidOutFlist, ebufp); PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG, "fm_zonemap_pol_get_lineage_rev_changed zonemap read_flds output flist", pReadPoidOutFlist); /* * Compare poid revs */ /* Get new poid from flist */ pNewPoid = (poid_t*) PIN_FLIST_FLD_GET(pReadPoidOutFlist, PIN_FLD_POID, 0, ebufp); /* To compare poids for revision check and in multi-db case just set back the * pMatrixPoid cached zonemap poid DB number to the newly read poid * to just compare poid_id, type and revision and not db number */ in_db_no = PIN_POID_GET_DB((poid_t *)pMatrixPoid); PIN_POID_SET_DB(pNewPoid, in_db_no); /* Is db rev newer than stored rev? */ if (PIN_POID_COMPARE(pNewPoid, (poid_t*)pMatrixPoid, PIN_BOOLEAN_TRUE, ebufp)) { /* Yes: set return to true */ nRetVal = PIN_BOOLEAN_TRUE; } else { /* No: set return to false */ nRetVal = PIN_BOOLEAN_FALSE; } /* * Clean up */ PIN_FLIST_DESTROY_EX(&pReadPoidInFlist, NULL); PIN_FLIST_DESTROY_EX(&pReadPoidOutFlist, NULL); if (PIN_ERR_IS_ERR(ebufp)) { PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR, "fm_zonemap_pol_get_lineage_rev_changed() error", ebufp); /* Set return value to error */ nRetVal = PIN_BOOLEAN_FALSE; } /* Debug */ PIN_ERR_LOG_MSG(PIN_ERR_LEVEL_DEBUG, "fm_zonemap_pol_get_lineage_rev_changed returning"); return nRetVal; }
/******************************************************************* * fm_zonemap_pol_get_lineage_get_zonemap(): *******************************************************************/ static ZonemapHashEntry_t * fm_zonemap_pol_get_lineage_get_zonemap( pcm_context_t *pCtx, poid_t *pRoutingPoid, poid_t *pBrandPoid, ZonemapHashEntry_t **apHashTable, const char *pszTarget, pin_errbuf_t *ebufp) { int32 nTargetHash; int32 nLoadStatus; ZonemapHashEntry_t *pHashEntry; ZonemapHashEntry_t *pBucket; ZonemapHashEntry_t *pCurNode; Blob_t **ppBuffer; poid_t **ppMatrixPoid; int32 *pnSearchMode; int32 nLoadFromDB; int32 nUnlockNode = PIN_BOOLEAN_FALSE; time_t current_time = 0; PIN_HEAP_VAR; /* The HashTableLock has already been acquired by the time * this procedure is called. */ pHashEntry = pBucket = NULL; if (PIN_ERR_IS_ERR(ebufp)) { return NULL; } /* Debug */ PIN_ERR_LOG_MSG(PIN_ERR_LEVEL_DEBUG, "fm_zonemap_pol_get_lineage_get_zonemap starting"); /* * Hash zone name */ nTargetHash = fm_zonemap_pol_get_lineage_hash_zone_name(pszTarget); /* Get bucket */ pBucket = apHashTable[nTargetHash]; /* Assume we don't have to load from DB */ nLoadFromDB = PIN_BOOLEAN_FALSE; /* * Have we already loaded this matrix? */ pHashEntry = fm_zonemap_pol_get_lineage_find_bucket(pBucket, pszTarget, ebufp); if (pHashEntry != NULL) { /* * do a revision check only if a certain time has * elapsed */ current_time = pin_virtual_time((time_t*)NULL); if(current_time > (pHashEntry->lastUpdate + interval)) { /* * reset the timer */ pHashEntry->lastUpdate = current_time; /* * Yes: Has it changed since last load? */ if (fm_zonemap_pol_get_lineage_rev_changed(pCtx, pHashEntry->pMatrixPoid, ebufp)) { /* * Yes: Free old data & reload matrix from DB */ /* Lock the node */ MutexLock(pHashEntry->Lock); /* Remove node from bucket */ for (pCurNode = pBucket; pCurNode != NULL; pCurNode = pCurNode->pNext) { if (pCurNode->pNext == pHashEntry) { pCurNode->pNext = pHashEntry->pNext; break; } } PIN_SET_GLOBAL_HEAP; /* Free buffer */ free(pHashEntry->pBuffer); pHashEntry->pBuffer = NULL; /* Free matrix poid */ PIN_POID_DESTROY(pHashEntry->pMatrixPoid, NULL); pHashEntry->pMatrixPoid = NULL; PIN_RESET_GLOBAL_HEAP; /* Indicate that we need to load from DB */ nLoadFromDB = PIN_BOOLEAN_TRUE; /* Indicate that we need to unlock the node */ nUnlockNode = PIN_BOOLEAN_TRUE; } } } else { /* * No: Add new node to bucket */ PIN_SET_GLOBAL_HEAP; /* Create & init new bucket */ pHashEntry = (ZonemapHashEntry_t *) malloc(sizeof(ZonemapHashEntry_t)); /* Verify that memory was allocated */ if (pHashEntry != NULL) { pHashEntry->pszZonemapName = malloc(strlen(pszTarget) + 1); if (pHashEntry->pszZonemapName == NULL) { pin_set_err(ebufp, PIN_ERRLOC_FM, PIN_ERRCLASS_SYSTEM_DETERMINATE, PIN_ERR_NO_MEM, 0, 0, 0); PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR, "fm_zonemap_pol_get_lineage_get_zonemap: " "failed to allocate memory for zonemap name", ebufp); free(pHashEntry); pHashEntry = NULL; goto Done; } strcpy((char*) pHashEntry->pszZonemapName, pszTarget); pHashEntry->pNext = NULL; pHashEntry->pBuffer = NULL; /* Init semaphore */ MutexInit(pHashEntry->Lock); } PIN_RESET_GLOBAL_HEAP; /* Verify that memory was allocated */ if (pHashEntry == NULL) { pin_set_err(ebufp, PIN_ERRLOC_FM, PIN_ERRCLASS_SYSTEM_DETERMINATE, PIN_ERR_NO_MEM, 0, 0, 0); PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR, "fm_zonemap_pol_get_lineage_get_zonemap: " "failed to allocate memory for hash entry", ebufp); goto Done; } /* Indicate that we need to load from DB */ nLoadFromDB = PIN_BOOLEAN_TRUE; } /* Do we need to load from the database? */ if (nLoadFromDB == PIN_BOOLEAN_TRUE) { /* * Yes: Load matrix from DB */ /* Copy trie address from global to local mem */ ppBuffer = &(pHashEntry->pBuffer); ppMatrixPoid = &(pHashEntry->pMatrixPoid); pnSearchMode = &(pHashEntry->nDefaultSearchMode); /* Attempt to read matrix from DB */ nLoadStatus = fm_zonemap_pol_get_lineage_load_zonemap( pCtx, pszTarget, pRoutingPoid, ppMatrixPoid,pBrandPoid, ppBuffer, pnSearchMode, ebufp); PIN_SET_GLOBAL_HEAP; /* Did we load a matrix? */ if (nLoadStatus == PIN_BOOLEAN_FALSE) { /* Failed: set return value */ /* If this happened on a RELOAD, we have more * work to do */ if (nUnlockNode == PIN_BOOLEAN_TRUE) { /* * Yes: Unlock the node */ MutexUnlock(pHashEntry->Lock); nUnlockNode = PIN_BOOLEAN_FALSE; } free((char*)pHashEntry->pszZonemapName); pHashEntry->pszZonemapName = NULL; /* Destroy the mutex */ MutexDestroy(pHashEntry->Lock); free(pHashEntry); pHashEntry = NULL; } else { /* * Add bucket to hash table */ pHashEntry->pNext = apHashTable[nTargetHash]; apHashTable[nTargetHash] = pHashEntry; pHashEntry->lastUpdate = pin_virtual_time((time_t *)NULL); } PIN_RESET_GLOBAL_HEAP; } Done: /* Do we need to unlock the node? */ if (nUnlockNode == PIN_BOOLEAN_TRUE) { /* * Yes: Unlock the node */ MutexUnlock(pHashEntry->Lock); } /* Debug */ PIN_ERR_LOG_MSG(PIN_ERR_LEVEL_DEBUG, "fm_zonemap_pol_get_lineage_get_zonemap returning"); return pHashEntry; }
//**************************************************** // createRecourse // Pre: // Post: // void bs_CreateLECRecourse::createRecourse( pin_Session * pinp, const char * sRecordType, const char * sBtn, const char * sAuthDate, const char * sReasonCode, const char * sAmount, const char * sVersion, const char * file_name, pin_flist_t **return_flistpp, pin_errbuf_t *ebufp ) { pin_flist_t * x_flistp = NULL; pin_flist_t * c_flistp = NULL; int lec_db = 5; //WIP: hard coded int command = 9; poid_t * pdp = NULL; pin_decimal_t * amtp = NULL; void * vp = NULL; int impact_type = 0; int version = 0; PIN_ERR_CLEAR_ERR(ebufp); //--enter function-------------- PIN_ERR_LOG_MSG(PIN_ERR_LEVEL_DEBUG, "bs_CreateLECRecourse::createRecourse: enter" ); /*--- Convert ---*/ if (sVersion && strlen(sVersion)> 0 ) version = atoi(sVersion); amtp = pbo_decimal_from_str(sAmount,ebufp); if(amtp && !PIN_ERR_IS_ERR(ebufp) && pbo_decimal_sign(amtp, ebufp) == -1 ) { pbo_decimal_abs_assign(amtp, ebufp); impact_type = 1; } /*--- Create set_status ---*/ x_flistp = PIN_FLIST_CREATE(ebufp); pdp = pin_poid_create((int64)lec_db,"/_lec_db", (int64)1, ebufp); PIN_FLIST_FLD_PUT(x_flistp, PIN_FLD_POID, pdp, ebufp); PIN_FLIST_FLD_SET(x_flistp, PIN_FLD_COMMAND, (void*)&command, ebufp); c_flistp = PIN_FLIST_ELEM_ADD( x_flistp, PIN_FLD_CHARGES, PIN_ELEMID_ASSIGN, ebufp ); PIN_FLIST_FLD_SET(c_flistp, PIN_FLD_PHONE, (void*)sBtn, ebufp); PIN_FLIST_FLD_SET(c_flistp, PIN_FLD_AUTH_DATE, (void*)sAuthDate, ebufp); PIN_FLIST_FLD_SET(c_flistp, PIN_FLD_RECORD_TYPE, (void*)sRecordType, ebufp); PIN_FLIST_FLD_SET(c_flistp, PIN_FLD_REASON_CODE, (void*)sReasonCode, ebufp); PIN_FLIST_FLD_SET(c_flistp, PIN_FLD_IMPACT_TYPE, (void*)&impact_type, ebufp); PIN_FLIST_FLD_SET(c_flistp, PIN_FLD_VERSION_ID, (void*)&version, ebufp); PIN_FLIST_FLD_PUT(c_flistp, PIN_FLD_AMOUNT_ADJUSTED, (void*)amtp, ebufp); if (file_name != NULL ) { c_flistp = PIN_FLIST_ELEM_ADD( x_flistp, PIN_FLD_BATCH_INFO, PIN_ELEMID_ASSIGN, ebufp ); PIN_FLIST_FLD_SET(c_flistp, PIN_FLD_FILENAME, (void*)file_name, ebufp); } /*----* Connect to the LEC DM *---*/ // pcm_context_t *my_ctxp = NULL; // PCM_CONTEXT_OPEN(&my_ctxp, (pin_flist_t *)0, ebufp); PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG,"dm search input flist", x_flistp); pinp->call_opcode( PCM_OP_SEARCH, 0, x_flistp, return_flistpp, ebufp); if (return_flistpp) PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG, "dm search output flist", *return_flistpp); // if ( PIN_ERR_IS_ERR(ebufp) ) // { // PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,"Failed connecting to DM_LEC...", ebufp ); // } // PCM_CONTEXT_CLOSE(my_ctxp, 0, NULL); PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG,(char*)"leaving bs_CreateLECRecourse::createRecourse" , *return_flistpp ); PIN_FLIST_DESTROY_EX(&x_flistp,NULL); return; }
/******************************************************************* * fm_zonemap_pol_get_lineage_load_zonemap(): * * Retrieve and process the named zonemap. * *******************************************************************/ static int32 fm_zonemap_pol_get_lineage_load_zonemap( pcm_context_t *pCtx, const char *pszTarget, poid_t *pRoutingPoid, poid_t **ppZonemapPoid, poid_t *pBrandPoid, Blob_t **ppBuffer, int32 *pnDefaultSearchMode, pin_errbuf_t *ebufp) { pin_flist_t *pGetZonemapInFlist = NULL; pin_flist_t *pGetZonemapOutFlist = NULL; pin_flist_t *pZonemaps = NULL; poid_t *pSearchPoid = NULL; pin_buf_t *pBuf = NULL; Blob_t *pTempBufAddr = NULL; int32 nRetVal = PIN_BOOLEAN_TRUE; pin_zonemap_data_type_t dt = PIN_ZONEMAP_DATA_BINARY; int32 *pnSearchMode; PIN_HEAP_VAR; /* Debug */ PIN_ERR_LOG_MSG(PIN_ERR_LEVEL_DEBUG, "fm_zonemap_pol_get_lineage_load_zonemap starting"); /* * Create flist for retrieving matrix */ pGetZonemapInFlist = PIN_FLIST_CREATE(ebufp); pSearchPoid = PIN_POID_CREATE(PIN_POID_GET_DB((poid_t *) pRoutingPoid), "/zonemap", -1, ebufp); PIN_FLIST_FLD_PUT(pGetZonemapInFlist, PIN_FLD_POID, (void *)pSearchPoid, ebufp); PIN_FLIST_FLD_SET(pGetZonemapInFlist, PIN_FLD_NAME, (void *) pszTarget, ebufp); PIN_FLIST_FLD_SET(pGetZonemapInFlist, PIN_FLD_ZONEMAP_DATA_TYPE, (void *) &dt, ebufp); PIN_FLIST_FLD_SET(pGetZonemapInFlist, PIN_FLD_ACCOUNT_OBJ, (void *) pBrandPoid, ebufp); /* * Call zonemap loading opcode (automatically seaches) */ PCM_OP(pCtx, PCM_OP_ZONEMAP_GET_ZONEMAP, 0, pGetZonemapInFlist, &pGetZonemapOutFlist, ebufp); /* * Process matrix */ pZonemaps = PIN_FLIST_ELEM_GET(pGetZonemapOutFlist, PIN_FLD_ZONEMAPS, PIN_ELEMID_ANY, 1, ebufp); if (pZonemaps != NULL) { /* * Found a zonemap, set current matrix poid */ PIN_SET_GLOBAL_HEAP; *ppZonemapPoid = PIN_POID_COPY((poid_t*) PIN_FLIST_FLD_GET(pZonemaps,PIN_FLD_POID, 0, ebufp), ebufp); PIN_RESET_GLOBAL_HEAP; /* * Grab default search mode (NULL means no default) */ pnSearchMode = (int32*) PIN_FLIST_FLD_GET(pZonemaps, PIN_FLD_ZONEMAP_SEARCH_TYPE, 1, ebufp); /* Did we find a default search mode? */ if (pnSearchMode != NULL) { /* Yes: copy value to input */ *pnDefaultSearchMode = *pnSearchMode; } else { /* No: indicate no default search mode */ pnDefaultSearchMode = NULL; } /* * Get address of buffer */ pBuf = (pin_buf_t *)PIN_FLIST_FLD_GET(pZonemaps, PIN_FLD_ZONEMAP_DATA_DERIVED, 1, ebufp); if (pBuf != NULL && (pBuf->data != NULL)) { /* get the actual blob */ pTempBufAddr = (Blob_t *)(pBuf->data); PIN_SET_GLOBAL_HEAP; /* Allocate memory to hold buffer on global heap */ *ppBuffer = (Blob_t*) malloc(pTempBufAddr->blob_size); /* Copy buffer to global mem */ memcpy(*ppBuffer, pTempBufAddr, pTempBufAddr->blob_size); PIN_RESET_GLOBAL_HEAP; } else { *ppBuffer = NULL; PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_WARNING, "fm_zonemap_pol_get_lineage_load_zonemap: " "zonemap is empty!", ebufp); } } else { /* * No zonemap found */ nRetVal = PIN_BOOLEAN_FALSE; } /* * Clean up */ PIN_FLIST_DESTROY_EX(&pGetZonemapInFlist, NULL); PIN_FLIST_DESTROY_EX(&pGetZonemapOutFlist, NULL); if (PIN_ERR_IS_ERR(ebufp)) { nRetVal = PIN_BOOLEAN_FALSE; if (ebufp->pin_err == PIN_ERR_NO_MATCH) { PIN_ERR_LOG_MSG(PIN_ERR_LEVEL_DEBUG, "fm_zonemap_pol_get_lineage_load_zonemap: " "no matrix"); PIN_ERR_CLEAR_ERR(ebufp); } else { PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR, "fm_zonemap_pol_get_lineage_load_zonemap: error", ebufp); } } /* Debug */ PIN_ERR_LOG_MSG(PIN_ERR_LEVEL_DEBUG, "fm_zonemap_pol_get_lineage_load_zonemap returning"); return nRetVal; }
//**************************************************** // adjust_CashBalance // Pre: // Post: // bool bs_AdjustCashBalance::adjust_CashBalance( pin_Session * pinp, poid_t * account_pdp, pin_decimal_t * amountp, string source, string description, string service_str, string reason_id, pin_flist_t **return_flistpp, pin_errbuf_t *ebufp ) { pin_flist_t *input_flistp = NULL; poid_t *bal_pdp = NULL; int dollar_currency = 840; int iversion = DEFAULT_CASH_ADJUSTMENT_VER; ostringstream os; bool rc = false; char *service_code = (char *)NULL; service_code = (char *)calloc(256, sizeof(char)); strcpy(service_code,(const char *)GENERIC_SERVICE_ADJUSTMENT_CODE); strcat(service_code,reason_id.c_str()); int id = atoi(service_code); PIN_ERR_CLEAR_ERR(ebufp); //--- setup -------------------------- /* source / desc name */ const string this_program("adjust_CashBalance"); if ( description.empty() ) { ostringstream os; os << DEFAULT_CASH_ADJUSTMENT_DESCR << "." << getuser(ENV_USER) << "." << this_program; description.assign(os.str()); } if ( source.empty() ) { source.assign(this_program); } PIN_ERR_LOG_MSG(PIN_ERR_LEVEL_DEBUG, (char*)description.c_str() ); /* retrieving the bal_grp poid associated with a service * if the service_str is NULL, then account level bal_grp will be used */ pin_flist_t *r_flistp = NULL; r_flistp = bs_AccountInfo::getService_and_BalGrpPoids(pinp, account_pdp, service_str); bal_pdp = PIN_FLIST_FLD_TAKE(r_flistp,PIN_FLD_BAL_GRP_OBJ, 1, ebufp); if(r_flistp) PIN_FLIST_DESTROY(r_flistp,ebufp); if(PIN_POID_IS_NULL(bal_pdp)) { PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,(char*)"/balance_group poid is NULL", ebufp ); return false; } //--- adjust------------------------------ input_flistp = PIN_FLIST_CREATE(ebufp); PIN_FLIST_FLD_SET(input_flistp, PIN_FLD_PROGRAM_NAME, (void*)source.c_str(), ebufp); PIN_FLIST_FLD_SET(input_flistp, PIN_FLD_POID,(void *) account_pdp, ebufp); PIN_FLIST_FLD_SET(input_flistp, PIN_FLD_DESCR, (void *)description.c_str(), ebufp); PIN_FLIST_FLD_SET(input_flistp, PIN_FLD_CURRENCY, (void *) &dollar_currency,ebufp); PIN_FLIST_FLD_SET(input_flistp, PIN_FLD_AMOUNT, amountp, ebufp); PIN_FLIST_FLD_SET(input_flistp, PIN_FLD_STR_VERSION, (void *) &iversion, ebufp); PIN_FLIST_FLD_SET(input_flistp, PIN_FLD_STRING_ID, (void *) &id, ebufp); /*** Inserting BAL_GRP poid ***/ PIN_FLIST_FLD_PUT(input_flistp, PIN_FLD_BAL_GRP_OBJ, (void *) bal_pdp, ebufp); /* * Call opcode */ rc = pinp->call_opcode( PCM_OP_AR_ACCOUNT_ADJUSTMENT, 0, input_flistp, return_flistpp, ebufp); PIN_FLIST_DESTROY(input_flistp, ebufp); return rc; }
bool bs_AdjustCashBalance::adjust_CashBalance( pin_Session * pinp, bs_NvRecord& nv, pin_flist_t **return_flistpp, pin_errbuf_t *ebufp ) { c_Decimal amount_cp; poid_t * account_pdp = NULL; pin_decimal_t * amountp = NULL; string str_login = nv.value(LOGIN); string account_no = nv.value(ACCOUNT_NO); string str_poid_id0 = nv.value(ACCOUNT_OBJ_ID0); string str_amount = nv.value(AMOUNT); string str_resource = nv.value("resource_id"); string str_source = nv.value(SOURCE); string str_descr = nv.value(DESCRIPTION); //optional string service_str = nv.value(SERVICE_OBJ_TYPE); string reason_id = nv.value("REASON_ID"); bool rc = false; int64 database = pinp->getDBNumber(); ostringstream account_descr; /// /// -- translation --------------------------- /// string title("adjust_CashBalance nvRec"); nv.StringBuffer(title); PIN_ERR_LOG_MSG(PIN_ERR_LEVEL_DEBUG, (char*)title.c_str() ); //-- translate account poid----------- PIN_ERR_LOG_MSG(PIN_ERR_LEVEL_DEBUG, (char*)"Locating account..." ); c_Poid account_cp; if ( ! nv.resolve_AccountPoid(pinp, account_cp)) { pin_set_err(ebufp, PIN_ERRLOC_APP, PIN_ERRCLASS_APPLICATION, PIN_ERR_NOT_FOUND,PIN_FLD_ACCOUNT_OBJ, 0, 0); PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR, (char*)"bad account info", ebufp ); return false; }; //-- translate others ----------- PIN_ERR_LOG_MSG(PIN_ERR_LEVEL_DEBUG, (char*)"Translate amount..." ); if (! amount_cp.create( str_amount.c_str() ) || amount_cp.isnull() ) { if (! PIN_ERR_IS_ERR(ebufp)) pin_set_err(ebufp, PIN_ERRLOC_APP, PIN_ERRCLASS_APPLICATION, PIN_ERR_BAD_VALUE,PIN_FLD_AMOUNT, 0, 0); account_descr << "-Can not get a valid amount"; PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,(char*)((account_descr.str()).c_str()), ebufp ); return false; } /// /// -- call base function --------------------------- /// PIN_ERR_LOG_MSG(PIN_ERR_LEVEL_DEBUG, (char*)"Calling base function..." ); PIN_ERR_CLEAR_ERR(ebufp); rc = adjust_CashBalance( pinp, account_cp.borrow(), amount_cp.borrow(), str_source, str_descr, service_str, reason_id, return_flistpp, ebufp ); /// /// -- cleanup and return --------------------------- /// return rc; };
/******************************************************************* * fm_cust_pol_tax_init() * * Use this policy to load any custom user tax data into an internal * data structure you may have declared in this file. In this default * implementation, the structure will be the Tax_Table global flist. * *******************************************************************/ void fm_cust_pol_tax_init( pcm_context_t *ctxp, pin_flist_t *in_flistp, pin_flist_t **out_flistpp, pin_errbuf_t *ebufp) { int32 errp = 0; void *vp = NULL; char *taxfile = NULL; FILE *fp = NULL; char buf[STR_LEN]; char code[STR_LEN]; char pkg[STR_LEN]; char rate[STR_LEN]; char start_t[STR_LEN]; char end_t[STR_LEN]; char j_level[STR_LEN]; char j_list[STR_LEN]; char descr[STR_LEN]; char rule[STR_LEN]; pin_decimal_t *pct = NULL; pin_decimal_t *npct=NULL; pin_decimal_t *dpct=NULL; int32 len = 0; int32 lvl = 0; int32 trl = 0; int32 elemid = 0; int32 precision = 6; time_t startTm = 0; time_t endTm = 0; pin_flist_t *flistp = NULL; if (PIN_ERR_IS_ERR(ebufp)) return; PIN_ERR_CLEAR_ERR(ebufp); /* Create the return flist */ *out_flistpp = PIN_FLIST_CREATE(ebufp); /* Set the account POID */ vp = PIN_FLIST_FLD_GET(in_flistp, PIN_FLD_POID, 0, ebufp); PIN_FLIST_FLD_SET(*out_flistpp, PIN_FLD_POID, (void *)vp, ebufp); if (Tax_Table == (pin_flist_t*)NULL) { /* Create the flist to hold the tax rates */ Tax_Table = (pin_flist_t*)PIN_FLIST_CREATE(ebufp); PIN_ERR_LOG_MSG(PIN_ERR_LEVEL_DEBUG, "Creating the Tax_Table"); } else { /* the tax table has been initialized */ PIN_ERR_LOG_MSG(PIN_ERR_LEVEL_WARNING, "The Tax_Table has already been created!"); return; /*****/ } /* * Build Tax_Table from external table, which in this * implementation happens to be the same taxcodes_map * file specified in the cm/pin.conf */ /* get the taxcodes_map path from the pin.conf */ pin_conf("fm_rate", "taxcodes_map", PIN_FLDT_STR, (caddr_t*)&taxfile, &errp); if (errp != PIN_ERR_NONE) { PIN_ERR_LOG_MSG(PIN_ERR_LEVEL_ERROR, "taxcodes_map table config error!"); return; /*****/ } /* Let's redefine the taxcodes_map table so that the following * columns: * * # Taxcode Pkg Code1 Code2 Si Wt_code Cmdty_code * # ------- --- ----- ----- ------ ------- ---------- * usage : Q : 01 : 01 : S : : * VAT : U : 4.5 : : : : * * will now become these: * * # Taxcode Pkg Rate Start End Lvl List Desc Rule * # ------- ---- ---- -------- -------- --- ----- ------ ---- * VAT : U : 5.0 : 02/01/01 : 01/31/02 : Fed : GB;FR : VAT-EU : Std * VAT : U : 4.5 : 02/01/02 : 01/31/08 : Fed : GB : VAT-GB : Std * VAT : U : 4.0 : 02/01/02 : 01/31/08 : Fed : FR : VAT-FR : Std */ fp = (FILE*) fopen(taxfile, "r"); free(taxfile); if (fp == (FILE*)NULL) { PIN_ERR_LOG_MSG(PIN_ERR_LEVEL_ERROR, "Failed to open taxcodes_map file!"); goto Done; /********/ } while (fgets(buf, STR_LEN, fp) != NULL) { if (strchr(buf, '#') || *buf == '\n') { /* skip comments and blank lines*/ continue; } /* Strip newline, if it is there */ len = strlen(buf); if (buf[len-1] == '\n') { buf[len-1] = '\0'; } code[0] = pkg[0] = rate[0] = start_t[0] = end_t[0] = '\0'; j_level[0] = j_list[0] = descr[0] = rule[0] = '\0'; /* Parse the line in the taxcodes_map */ fm_cust_pol_parse_map_file(buf, code, pkg, rate, start_t, end_t, j_level, j_list, descr, rule); if (strncmp(pkg, "U", 1) != 0) { /* skip entries other than "user" */ continue; /*******/ } /* Start of validity date */ fm_cust_pol_str_to_time_t(start_t, &startTm, 0); /* End of validity date */ fm_cust_pol_str_to_time_t(end_t, &endTm, 1); /* Jurisdiction level */ if (strncmp("Federal", j_level, 3) == 0) { lvl = PIN_RATE_TAX_JUR_FED; } else if (strncmp("State", j_level, 3) == 0) { lvl = PIN_RATE_TAX_JUR_STATE; } else if (strncmp("County", j_level, 3) == 0) { lvl = PIN_RATE_TAX_JUR_COUNTY; } else if (strncmp("City", j_level, 3) == 0) { lvl = PIN_RATE_TAX_JUR_CITY; } else { lvl = PIN_RATE_TAX_JUR_FED; } /* Tax rule (how to tax) */ if (strncmp(rule, "Std", 3) == 0) { trl = 0; /* standard tax */ } else if (strncmp(rule, "Tax", 3) == 0) { trl = 1; /* tax on tax */ } else if (strncmp(rule, "Fee", 3) == 0) { trl = 2; /* flat fee */ } else if (strncmp(rule, "Inc", 3) == 0) { trl = 3; /* inclusive tax */ } else if (strncmp(rule, "NCS", 3) == 0) { trl = 4; /* non-cumulative standard tax */ } else if (strncmp(rule, "NCT", 3) == 0) { trl = 5; /* non-cumulative tax on tax */ } else if (strncmp(rule, "NCF", 3) == 0) { trl = 6; /* non-cumulative flat fee */ } else if (strncmp(rule, "NCI", 3) == 0) { trl = 7; /* non-cumulative inclusive */ } else { trl = 0; /* default */ } /* Tax rate */ if (trl == 2 || trl == 6) { /* 'rate' is a flat fee */ pct = pbo_decimal_from_str(rate,ebufp); } else { /* 'rate' is a percentage */ npct = pbo_decimal_from_str(rate,ebufp); dpct = pbo_decimal_from_str("100.0",ebufp); pct = pbo_decimal_divide( npct, dpct ,ebufp); } /* Set some defaults */ if (!*j_list) { strcpy(j_list, "*"); } if (!*descr) { strcpy(descr, "No Tax Description"); } flistp = PIN_FLIST_ELEM_ADD(Tax_Table, PIN_FLD_TAXES, elemid++, ebufp); PIN_FLIST_FLD_SET(flistp, PIN_FLD_TAX_CODE, (void*)code, ebufp); PIN_FLIST_FLD_PUT(flistp, PIN_FLD_PERCENT,(void*)pbo_decimal_round(pct, (int32)precision,ROUND_HALF_UP,ebufp), ebufp); PIN_FLIST_FLD_SET(flistp, PIN_FLD_START_T, (void*)&startTm, ebufp); PIN_FLIST_FLD_SET(flistp, PIN_FLD_END_T, (void*)&endTm, ebufp); PIN_FLIST_FLD_SET(flistp, PIN_FLD_TYPE, (void*)&lvl, ebufp); PIN_FLIST_FLD_SET(flistp, PIN_FLD_NAME, (void*)j_list, ebufp); PIN_FLIST_FLD_SET(flistp, PIN_FLD_DESCR, (void*)descr, ebufp); PIN_FLIST_FLD_SET(flistp, PIN_FLD_TAX_WHEN, (void*)&trl, ebufp); pbo_decimal_destroy(&npct); pbo_decimal_destroy(&dpct); pbo_decimal_destroy(&pct); } /* end while */ fclose(fp); Done: PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG, "Tax Table from taxcodes_map file", Tax_Table); return; }