/*******************************************************************
 * Main routine for the PCM_OP_DEVICE_POL_SET_STATE operation.
 *******************************************************************/
void
op_device_pol_set_state(
	cm_nap_connection_t	*connp,
	int32			opcode,
	int32			flags,
	pin_flist_t		*i_flistp,
	pin_flist_t		**r_flistpp,
	pin_errbuf_t		*ebufp)
{
	pcm_context_t		*ctxp = connp->dm_ctx;
	pin_flist_t	*r_flistp = NULL;

	if (PIN_ERR_IS_ERR(ebufp))
		return;
	PIN_ERR_CLEAR_ERR(ebufp);

	/***********************************************************
	 * Null out results
	 ***********************************************************/
	*r_flistpp = NULL;

	/***********************************************************
	 * Insanity check.
	 ***********************************************************/
	if (opcode != PCM_OP_DEVICE_POL_SET_STATE) {
		pin_set_err(ebufp, PIN_ERRLOC_FM,
			PIN_ERRCLASS_SYSTEM_DETERMINATE,
			PIN_ERR_BAD_OPCODE, 0, 0, opcode);
		PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,
			"op_device_pol_set_state opcode error", ebufp);

		return;
	}
	
	/***********************************************************
	 * Debut what we got.
         ***********************************************************/
	PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG,
		"op_device_pol_set_state input flist", i_flistp);

	/***********************************************************
	 * Main rountine for this opcode
	 ***********************************************************/
	fm_device_pol_set_state(ctxp, flags, i_flistp, r_flistpp, ebufp);
	
	/***********************************************************
	 * Error?
	 ***********************************************************/
	if (PIN_ERR_IS_ERR(ebufp)) {
		PIN_FLIST_DESTROY_EX(r_flistpp, ebufp);
		PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,
			"op_device_pol_set_state error", ebufp);
	} else {
		PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG,
			"op_device_pol_set_state output flist", *r_flistpp);
	}

	return;
}
/*******************************************************************
 * Main routine for the PCM_OP_CUST_POL_VALID_STATUS operation.
 *******************************************************************/
void
op_cust_pol_valid_status(
        cm_nap_connection_t	*connp,
	u_int			opcode,
        u_int			flags,
        pin_flist_t		*i_flistp,
        pin_flist_t		**ret_flistpp,
        pin_errbuf_t		*ebufp)
{
	pcm_context_t		*ctxp = connp->dm_ctx;
	pin_flist_t		*r_flistp = NULL;


	/*
	 * Null out results until we have some.
	 */
	*ret_flistpp = NULL;
	PIN_ERR_CLEAR_ERR(ebufp);

	/*
	 * Insanity check.
	 */
	if (opcode != PCM_OP_CUST_POL_VALID_STATUS) {
		pin_set_err(ebufp, PIN_ERRLOC_FM,
			PIN_ERRCLASS_SYSTEM_DETERMINATE,
			PIN_ERR_BAD_OPCODE, 0, 0, opcode);
		PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,
			"bad opcode in op_cust_pol_valid_status", ebufp);
		return; 
	}

	/*
	 * Debug: what did we get?
	 */
	PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG,
		"op_cust_pol_valid_status input flist", i_flistp);

	/*
	 * Call main function to do it
	 */
	fm_cust_pol_valid_status(ctxp, i_flistp, &r_flistp, ebufp);

	/*
	 * Results.
	 */
	if (PIN_ERR_IS_ERR(ebufp)) {
		*ret_flistpp = (pin_flist_t *)NULL;
		PIN_FLIST_DESTROY(r_flistp, NULL);
		PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,
			"op_cust_pol_valid_status error", ebufp);
	} else {
		*ret_flistpp = r_flistp;
		PIN_ERR_CLEAR_ERR(ebufp);
		PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG,
			"op_cust_pol_valid_status return flist", r_flistp);
	}

	return;
}
/*******************************************************************
 * PCM_OP_BILL_POL_GET_PENDING_ITEMS 
 *
 * This policy provides a hook to the Bill Now opcode for selecting 
 * the Pending Items to be included in the Bill. The default 
 * implementation select all the Pending Items to be included in the
 * Bill.
 *******************************************************************/
void 
op_bill_pol_get_pending_items(
	cm_nap_connection_t	*connp,
	int32			opcode,
	int32			flags,
	pin_flist_t		*i_flistp,
	pin_flist_t		**r_flistpp,
	pin_errbuf_t		*ebufp)
{
	void		*vp = NULL;
	pcm_context_t	*ctxp = connp->dm_ctx;
	
	*r_flistpp = NULL;
	
	if (PIN_ERR_IS_ERR(ebufp)) {
		return;
	}
	PIN_ERR_CLEAR_ERR(ebufp);

	/*******************************************************************
	 * Insanity Check 
	 *******************************************************************/
	if (opcode != PCM_OP_BILL_POL_GET_PENDING_ITEMS) {
		pin_set_err(ebufp, PIN_ERRLOC_FM, 
			PIN_ERRCLASS_SYSTEM_DETERMINATE,
			PIN_ERR_BAD_OPCODE, 0, 0, opcode);
		PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,
			"op_bill_pol_get_pending_items error",
			ebufp);
		return;
	}

	PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG, 
		"op_bill_pol_get_pending_items input flist", i_flistp);

	/*******************************************************************
	 * Call the function in order to get pending items to be included
	 *  into the Bill Now. 
	 *******************************************************************/
	fm_bill_pol_get_pending_items(ctxp, i_flistp, r_flistpp, ebufp);
	
	 /******************************************************************
         * Set account poid and bill_type to the output flist.
         ******************************************************************/
	
	vp = PIN_FLIST_FLD_GET(i_flistp, PIN_FLD_POID, 0, ebufp);
	PIN_FLIST_FLD_SET(*r_flistpp, PIN_FLD_POID, vp, ebufp);
	
	if (PIN_ERR_IS_ERR(ebufp)) {
		PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR, 
			"op_bill_pol_get_pending_items error", ebufp);
	}
	else {
		PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG, 
		"op_bill_pol_get_pending_items output flist", *r_flistpp);
	}
	return;
}
/*******************************************************************
 * Main routine for the PCM_OP_CUST_POL_READ_PLAN operation. 
 *******************************************************************/
void
op_cust_pol_read_plan(
        cm_nap_connection_t	*connp,
	int32			opcode,
        int32			flags,
        pin_flist_t		*i_flistp,
        pin_flist_t		**ret_flistpp,
        pin_errbuf_t		*ebufp)
{
	pcm_context_t		*ctxp = connp->dm_ctx;
	pin_flist_t		*r_flistp = NULL;

	/***********************************************************
	 * Null out results until we have some.
	 ***********************************************************/
	*ret_flistpp = NULL;
	PIN_ERR_CLEAR_ERR(ebufp);

	/***********************************************************
	 * Insanity check.
	 ***********************************************************/
	if (opcode != PCM_OP_CUST_POL_READ_PLAN) {
		pin_set_err(ebufp, PIN_ERRLOC_FM,
			PIN_ERRCLASS_SYSTEM_DETERMINATE,
			PIN_ERR_BAD_OPCODE, 0, 0, opcode);
		PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,
			"bad opcode in op_cust_pol_read_plan", ebufp);
		return;
	}

	/***********************************************************
	 * Debug: What did we get?
	 ***********************************************************/
	PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG,
		"op_cust_pol_read_plan input flist", i_flistp);

	/***********************************************************
	 * Call main function to do it
	 ***********************************************************/
	fm_cust_pol_read_plan(ctxp, i_flistp, &r_flistp, ebufp);

	/***********************************************************
	 * Set the results.
	 ***********************************************************/
	if (PIN_ERR_IS_ERR(ebufp)) {
		*ret_flistpp = NULL;
		PIN_FLIST_DESTROY_EX(&r_flistp, NULL);
		PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,
			"op_cust_pol_read_plan error", ebufp);
	} else {
		*ret_flistpp = r_flistp;
		PIN_ERR_CLEAR_ERR(ebufp);
		PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG,
			"op_cust_pol_read_plan return flist", *ret_flistpp);
	}

	return;
}
/*******************************************************************
 * Main routine for the PCM_OP_CUST_POL_PRE_COMMIT  command
 *******************************************************************/
void
op_cust_pol_pre_commit(
        cm_nap_connection_t	*connp,
	u_int			opcode,
        u_int			flags,
        pin_flist_t		*in_flistp,
        pin_flist_t		**ret_flistpp,
        pin_errbuf_t		*ebufp)
{
	pcm_context_t		*ctxp = connp->dm_ctx;
	pin_flist_t		*r_flistp = NULL;

	/***********************************************************
	 * Null out results until we have some.
	 ***********************************************************/
	*ret_flistpp = NULL;
	PIN_ERR_CLEAR_ERR(ebufp);

	/***********************************************************
	 * Insanity check.
	 ***********************************************************/
	if (opcode != PCM_OP_CUST_POL_PRE_COMMIT) {
		pin_set_err(ebufp, PIN_ERRLOC_FM,
			PIN_ERRCLASS_SYSTEM_DETERMINATE,
			PIN_ERR_BAD_OPCODE, 0, 0, opcode);
		PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,
			"bad opcode in op_cust_pol_pre_commit", ebufp);
		return;
	}

	/***********************************************************
	 * We will not open any transactions with Policy FM
	 * since policies should NEVER modify the database.
	 ***********************************************************/

	/***********************************************************
	 * Call main function to do it
	 ***********************************************************/
	fm_cust_pol_pre_commit(ctxp, flags, in_flistp, &r_flistp, ebufp);

	/***********************************************************
	 * Results.
	 ***********************************************************/
	if (PIN_ERR_IS_ERR(ebufp)) {
		*ret_flistpp = (pin_flist_t *)NULL;
		PIN_FLIST_DESTROY(r_flistp, NULL);
		PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,
			"op_cust_pol_pre_commit error", ebufp);
	} else {
		*ret_flistpp = r_flistp;
		PIN_ERR_CLEAR_ERR(ebufp);
		PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG,
			"op_cust_pol_pre_commit return flist", r_flistp);
	}

	return;
}
/*******************************************************************
 * Main routine for the PCM_OP_RATE_POL_GET_TAXCODE operation.
 *******************************************************************/
void
op_rate_pol_get_taxcode(
        cm_nap_connection_t	*connp,
	u_int			opcode,
        u_int			flags,
        pin_flist_t		*i_flistp,
        pin_flist_t		**o_flistpp,
        pin_errbuf_t		*ebufp)
{
	pcm_context_t		*ctxp = connp->dm_ctx;

	if (PIN_ERR_IS_ERR(ebufp)) {
		return;
	}
	PIN_ERR_CLEAR_ERR(ebufp);

	/***********************************************************
	 * Insanity check.
	 ***********************************************************/
	if (opcode != PCM_OP_RATE_POL_GET_TAXCODE) {
		pin_set_err(ebufp, PIN_ERRLOC_FM,
			PIN_ERRCLASS_SYSTEM_DETERMINATE,
			PIN_ERR_BAD_OPCODE, 0, 0, opcode);
		PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,
			"op_rate_pol_get_taxcode opcode error", ebufp);
		return;
		/*****/
	}

	/***********************************************************
	 * Debug: What we got.
	 ***********************************************************/
	PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG,
		"op_rate_pol_get_taxcode input flist", i_flistp);

	/***********************************************************
	 * Do the actual op in a sub.
	 ***********************************************************/
	fm_rate_pol_get_taxcode(ctxp, i_flistp, o_flistpp, ebufp);

	/***********************************************************
	 * Error?
	 ***********************************************************/
	if (PIN_ERR_IS_ERR(ebufp)) {
		PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,
			"op_rate_pol_get_taxcode error", ebufp);
	} else {
		/***************************************************
		 * Debug: What we're sending back.
		 ***************************************************/
		PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG,
		  "op_rate_pol_get_taxcode return flist", *o_flistpp);
	}

	return;
}
/*******************************************************************
 * PCM_OP_ACT_POL_POST_AUTHORIZE  
 *******************************************************************/
void 
op_act_pol_post_authorize(
	cm_nap_connection_t	*connp,
	int32			opcode,
	int32			flags,
	pin_flist_t		*i_flistp,
	pin_flist_t		**r_flistpp,
	pin_errbuf_t		*ebufp)
{
	pcm_context_t		*ctxp = connp->dm_ctx;

	*r_flistpp = NULL;
	
	if (PIN_ERR_IS_ERR(ebufp)) {
		return;
	}
	PIN_ERR_CLEAR_ERR(ebufp);

	/*******************************************************************
	 * Insanity Check 
	 *******************************************************************/
	if (opcode != PCM_OP_ACT_POL_POST_AUTHORIZE) {
		pin_set_err(ebufp, PIN_ERRLOC_FM, 
			PIN_ERRCLASS_SYSTEM_DETERMINATE,
			PIN_ERR_BAD_OPCODE, 0, 0, opcode);
		PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,
			"op_act_pol_post_authorize error",
			ebufp);
		return;
	}

	/*******************************************************************
	 * Debug: Input flist 
	 *******************************************************************/
	PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG, 
		"op_act_pol_post_authorize input flist", i_flistp);
	
	/*******************************************************************
	 * Call the default implementation 
	 *******************************************************************/
	fm_act_pol_post_authorize(ctxp, flags, i_flistp, r_flistpp, ebufp);

	/*******************************************************************
	 * Errors? 
	 *******************************************************************/
	if (PIN_ERR_IS_ERR(ebufp)) {
		PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR, 
			"op_act_pol_post_authorize error", ebufp);
	}
	else {
		PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG, 
			"op_act_pol_post_authorize output flist", 
			*r_flistpp);
	}
	return;
}
/*******************************************************************
 * Main routine for PCM_OP_BILL_POL_REVERSE_PAYMENT  
 *******************************************************************/
void
op_bill_pol_reverse_payment(
	cm_nap_connection_t	*connp,
	int			opcode,
	int			flags,
	pin_flist_t		*in_flistp,
	pin_flist_t		**ret_flistpp,
	pin_errbuf_t		*ebufp)
{
	pcm_context_t		*ctxp = connp->dm_ctx;

	if (PIN_ERR_IS_ERR(ebufp)) {
		return;
	}
	PIN_ERR_CLEAR_ERR(ebufp);

	/***********************************************************
	 * Null out results until we have some.
	 ***********************************************************/
	*ret_flistpp = (pin_flist_t *)NULL;

	/***********************************************************
	 * Insanity check.
	 ***********************************************************/
	if (opcode != PCM_OP_BILL_POL_REVERSE_PAYMENT) {
		pin_set_err(ebufp, PIN_ERRLOC_FM,
			PIN_ERRCLASS_SYSTEM_DETERMINATE,
			PIN_ERR_BAD_OPCODE, 0, 0, opcode);
		PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,
			"bad opcode in op_bill_pol_reverse_payment", ebufp);
		return;
	}

	/***********************************************************
	 * Debug: What did we get?
	 ***********************************************************/
	PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG,
		"op_bill_pol_reverse_payment input flist", in_flistp);
	
	fm_bill_pol_reverse_payment(ctxp, flags, in_flistp, ret_flistpp, ebufp);	

	/***********************************************************
	* Results.
	***********************************************************/
	if (PIN_ERR_IS_ERR(ebufp)) {
		PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,
			"op_bill_pol_reverse_payment error", ebufp);
	} else {
		PIN_ERR_CLEAR_ERR(ebufp);
		PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG,
			"op_bill_pol_reverse_payment return flist", 
			*ret_flistpp);
	}

	return;
}
/*******************************************************************
 * Main routine for the PCM_OP_CUST_POL_GET_CONFIG operation.
 *******************************************************************/
void
op_cust_pol_get_config(
        cm_nap_connection_t	*connp,
	u_int			opcode,
        u_int			flags,
        pin_flist_t		*in_flistp,
        pin_flist_t		**ret_flistpp,
        pin_errbuf_t		*ebufp)
{
	pcm_context_t		*ctxp = connp->dm_ctx;
	pin_flist_t		*r_flistp = NULL;

	if (PIN_ERR_IS_ERR(ebufp))
		return;
	PIN_ERR_CLEAR_ERR(ebufp);

	/***********************************************************
	 * Insanity check.
	 ***********************************************************/
	if (opcode != PCM_OP_CUST_POL_GET_CONFIG) {
		pin_set_err(ebufp, PIN_ERRLOC_FM,
			PIN_ERRCLASS_SYSTEM_DETERMINATE,
			PIN_ERR_BAD_OPCODE, 0, 0, opcode);
		PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,
			"bad opcode in op_cust_pol_get_config",  ebufp);
		return;
	}

	/***********************************************************
	 * Debug: What did we get?
	 ***********************************************************/
	PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG,
		"op_cust_pol_get_config input flist", in_flistp);

	/***********************************************************
	 * Call main function to do it
	 ***********************************************************/
	fm_cust_pol_get_config(ctxp, in_flistp, &r_flistp, ebufp);

	/***********************************************************
	 * Results.
	 ***********************************************************/
	if (PIN_ERR_IS_ERR(ebufp)) {
		*ret_flistpp = (pin_flist_t *)NULL;
		PIN_FLIST_DESTROY(r_flistp, NULL);
		PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,
			"op_cust_pol_get_config error", ebufp);
	} else {
		*ret_flistpp = r_flistp;
		PIN_ERR_CLEAR_ERR(ebufp);
		PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG,
			"op_cust_pol_get_config return flist", r_flistp);
	}

	return;
}
/*******************************************************************
 * Main routine for the PCM_OP_CUST_POL_PREP_TOPUP operation
 *******************************************************************/
void
op_cust_pol_prep_topup(
        cm_nap_connection_t     *connp,
        int32                   opcode,
        int32                   flags,
        pin_flist_t             *i_flistp,
        pin_flist_t             **r_flistpp,
        pin_errbuf_t            *ebufp)
{
        pcm_context_t           *ctxp = connp->dm_ctx;

        if (PIN_ERR_IS_ERR(ebufp))
                return;
        PIN_ERR_CLEAR_ERR(ebufp);

        /*
         * Null out results until we have some.
         */
        *r_flistpp = NULL;

        /*
         * Insanity check.
         */

        if (opcode != PCM_OP_CUST_POL_PREP_TOPUP) {
                pin_set_err(ebufp, PIN_ERRLOC_FM,
                        PIN_ERRCLASS_SYSTEM_DETERMINATE,
                        PIN_ERR_BAD_OPCODE, 0, 0, opcode);
                PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,
                        "bad opcode in op_cust_pol_prep_topup", ebufp);
                return;
        }


        PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG,
                          "op_cust_pol_prep_topup input flist:",
                          i_flistp);

        /*
         * Call the main function.
         */
        fm_cust_pol_prep_topup(ctxp, flags, i_flistp, r_flistpp, ebufp);

        PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG,
                          "op_cust_pol_prep_topup output flist:",
                          *r_flistpp);


        if (PIN_ERR_IS_ERR(ebufp))
                PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,
                                 "op_cust_pol_prep_topup flist error",
                                 ebufp);

        return;
}
/*******************************************************************
 * Main routine for the PCM_OP_BILL_POL_POST_BILLING
 *******************************************************************/
void
op_bill_pol_post_billing(
	cm_nap_connection_t	*connp,
	int32			opcode,
	int32			flags,
	pin_flist_t		*i_flistp,
	pin_flist_t		**r_flistpp,
	pin_errbuf_t		*ebufp)
{
	pcm_context_t           *ctxp = connp->dm_ctx;
	void			*vp = NULL;

	*r_flistpp = NULL;

	if (PIN_ERR_IS_ERR(ebufp)) {
		return;
	}
	PIN_ERR_CLEAR_ERR(ebufp);

	/*******************************************************************
	 * Insanity check.
	 *******************************************************************/
	if (opcode != PCM_OP_BILL_POL_POST_BILLING) {
		pin_set_err(ebufp, PIN_ERRLOC_FM,
			PIN_ERRCLASS_SYSTEM_DETERMINATE,
			PIN_ERR_BAD_OPCODE, 0, 0, opcode);
		PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,
			"op_bill_pol_post_billing bad opcode error", 
			ebufp);
		return;
	}

	/*******************************************************************
	 * Debug: What we got.
	 *******************************************************************/
	PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG,
		"op_bill_pol_post_billing input flist", i_flistp);


	/*******************************************************************
	 * Call the default implementation in order to stop billing of the 
	 * closed accounts
	 *******************************************************************/
	fm_bill_pol_stop_billing(ctxp, flags, i_flistp, r_flistpp, ebufp);

	if (PIN_ERR_IS_ERR(ebufp)) {
		PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,
		"op_bill_pol_post_billing error", ebufp);
	} else {

		PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG,
		"op_bill_pol_post_billing output flist", *r_flistpp);
	}
	return;
}
/*******************************************************************
 * Main routine for the PCM_OP_PRICE_POL_PREP_DEPENDENCY  command
 *******************************************************************/
EXPORT_OP void
op_price_pol_prep_dependency(
        cm_nap_connection_t	*connp,
	u_int32			opcode,
        u_int32			flags,
        pin_flist_t		*i_flistp,
        pin_flist_t		**o_flistpp,
        pin_errbuf_t		*ebufp)
{
	pcm_context_t		*ctxp = connp->dm_ctx;
	pin_flist_t		*r_flistp = NULL;

	if (PIN_ERR_IS_ERR(ebufp))
		return;
	PIN_ERR_CLEAR_ERR(ebufp);

	/*
	 * Null out results until we have some.
	 */
	*o_flistpp = NULL;

	/*
	 * Insanity check.
	 */
	if (opcode != PCM_OP_PRICE_POL_PREP_DEPENDENCY) {
		pin_set_err(ebufp, PIN_ERRLOC_FM,
			PIN_ERRCLASS_SYSTEM_DETERMINATE,
			PIN_ERR_BAD_OPCODE, 0, 0, opcode);
		PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,
			"bad opcode in op_price_pol_prep_dependency", ebufp);
		return;
	}

	/*
	 * Do the actual prep in a lower routine
	 */
	fm_price_pol_prep_dependency(ctxp, flags, i_flistp, &r_flistp, ebufp);

	/*
	 * Results.
	 */
	if (PIN_ERR_IS_ERR(ebufp)) {
		*o_flistpp = (pin_flist_t *)NULL;
		PIN_FLIST_DESTROY(r_flistp, NULL);
		PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,
			"op_price_pol_prep_dependency error", ebufp);
	} else {
		*o_flistpp = r_flistp;
		PIN_ERR_CLEAR_ERR(ebufp);
		PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG,
			"op_price_pol_prep_dependency return flist", r_flistp);
	}

	return;
}
/*******************************************************************
 * Main routine for the PCM_OP_CUST_POL_TAX_INIT command
 *******************************************************************/
void
op_cust_pol_tax_init(
	cm_nap_connection_t	*connp,
	int32			opcode,
	int32			flags,
	pin_flist_t		*in_flistp,
	pin_flist_t		**out_flistpp,
	pin_errbuf_t		*ebufp)
{
	pcm_context_t		*ctxp = connp->dm_ctx;

	if (PIN_ERR_IS_ERR(ebufp))
		return;
	PIN_ERR_CLEAR_ERR(ebufp);

	/*
	 * Insanity check.
	 */
	if (opcode != PCM_OP_CUST_POL_TAX_INIT) {
		pin_set_err(ebufp, PIN_ERRLOC_FM,
			PIN_ERRCLASS_SYSTEM_DETERMINATE,
			PIN_ERR_BAD_OPCODE, 0, 0, opcode);
		PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,
			"op_cust_pol_tax_init opcode error", ebufp);
		return;
	}

	/*
	 * Debug - What we got.
	 */
	PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG,
		"op_cust_pol_tax_init input flist", in_flistp);

	/*
	 * Do the actual op in a sub. 
	 */
	fm_cust_pol_tax_init(ctxp, in_flistp, out_flistpp, ebufp);

	/*
	 * Error?
	 */
	if (PIN_ERR_IS_ERR(ebufp)) {
		PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_DEBUG,
			"op_cust_pol_tax_init error", ebufp);
	} else {
		/*
		 * Debug: What we're sending back.
		 */
		PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG,
			"op_cust_pol_tax_init return flist", *out_flistpp);
	}

	return;
}
/*******************************************************************
 * Main routine for the PCM_OP_CREATE_METAFIELD operation.
 *******************************************************************/
void
op_create_metafield(
    cm_nap_connection_t     *connp,
    int32                    opcode,
    int32                    flags,
    pin_flist_t             *in_flistp,
    pin_flist_t            **ret_flistpp,
    pin_errbuf_t            *ebufp)
{
    pcm_context_t           *ctxp = connp->dm_ctx;
    void				*vp =NULL;

    PIN_ERR_CLEAR_ERR(ebufp);

    /***********************************************************
     * Insanity check.
     ***********************************************************/
    if (opcode != PCM_OP_CREATE_METAFIELD) {
        pin_set_err(ebufp, PIN_ERRLOC_FM, PIN_ERRCLASS_SYSTEM_DETERMINATE, PIN_ERR_BAD_OPCODE, 0, 0, opcode);
        PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR, "op_create_metafield opcode error", ebufp);
        return;
    }

    /***********************************************************
     * Debug: What we got.
     ***********************************************************/
    PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG, "op_create_metafield input flist", in_flistp);

    /***********************************************************
     * Do the actual op in a sub-function.
     ***********************************************************/
    fm_cust_pol_create_metafield_obj(ctxp, flags, in_flistp, ret_flistpp, ebufp);

    /***********************************************************
     * Error?
     ***********************************************************/
    if (PIN_ERR_IS_ERR(ebufp))
    {
        PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR, "op_create_metafield error", ebufp);
        PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_ERROR, "op_create_metafield return flist", *ret_flistpp);
    }
    else
    {
        /***************************************************
         * Debug: What we're sending back.
         ***************************************************/
        PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG, "op_create_metafield return flist", *ret_flistpp);
        vp = PIN_FLIST_FLD_GET(*ret_flistpp,PIN_FLD_POID,1,ebufp);

        if(PIN_POID_IS_NULL(vp)==0)
            PIN_ERR_LOG_POID(PIN_ERR_LEVEL_DEBUG, "metafield poid created is", vp);
    }
    return;
}
/*******************************************************************
 * fm_cust_pol_get_config()
 *
 *	Policy that takes the incoming flist of info contained
 *	on an srvc array and other, and adds more information and
 *	sends out the config information in big flist.
 *
 *******************************************************************/
static void
fm_cust_pol_get_config(
	pcm_context_t		*ctxp,
	pin_flist_t		*in_flistp,
	pin_flist_t		**out_flistpp,
        pin_errbuf_t		*ebufp)
{
	if (PIN_ERR_IS_ERR(ebufp))
		return;
	PIN_ERR_CLEAR_ERR(ebufp);

	/***********************************************************
	 * Copy the incoming flist.
	 ***********************************************************/
	*out_flistpp = PIN_FLIST_COPY(in_flistp, ebufp);

	/***********************************************************
	 * Add the file configed parameters.
	 ***********************************************************/
	fm_cust_pol_read_config(*out_flistpp, in_flistp, ebufp);

	/***********************************************************
	 * Error?
	 ***********************************************************/
	if(PIN_ERR_IS_ERR(ebufp)) {
		PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,
			"fm_cust_pol_get_config error", ebufp);
	}

	return;
}
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;
};
/*******************************************************************
 * fm_cust_pol_str_to_time_t ()
 *
 *******************************************************************/
static void
fm_cust_pol_str_to_time_t(
	char			*str,
	time_t			*time_ptr,
	int32			flag)
{
	struct tm	*tm = 0;
	time_t		cur_time = 0;
	int32		dd = 0;
	int32		mm = 0;
	int32		yy = 0;
	char		delim[5] = {0};
	pin_errbuf_t	*ebufp = NULL;

	*time_ptr = 0;
	if (*str == '\0') {
		if (flag) {
			strcpy(str, "01/01/2038");
		} else {
			strcpy(str, "01/01/1970");
		}
	}

	/* parse the date */
	sscanf(str, "%d%[/.-]%d%[/.-]%d", &mm, delim, &dd, delim, &yy);

	/* get virtual time to set defaults */
	pin_virtual_time(&cur_time);
	tm = localtime(&cur_time);
	if(!tm) {
		pin_set_err(ebufp, PIN_ERRLOC_FM,
		PIN_ERRCLASS_SYSTEM_DETERMINATE, PIN_ERR_BAD_VALUE,
			0, 0, 0);
		PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,
			"NULL pointer returned from localtime", ebufp);
		return;
	}

	if (yy < 70) {
		/* assume years < 70 are after 2000 */
		yy += 100;
	} else if (yy > 1900) {
		yy -= 1900;
	}
	tm->tm_mday = dd;
	tm->tm_mon = mm - 1;
	tm->tm_year = yy;
	tm->tm_sec = 0;
	tm->tm_min = 0;
	tm->tm_hour = 0;
	tm->tm_isdst = -1;
	if (flag) {
		/* make it the end of the day */
		tm->tm_mday = dd + 1;
		tm->tm_sec = -1;
	}
	*time_ptr = mktime(tm);

	return;
}
/********************************************************************
 * fm_bal_pol_get_bal_grp_and_svc()
 ********************************************************************/
static void 
fm_bal_pol_get_bal_grp_and_svc(
	pcm_context_t           *ctxp,
	int			flags,
	pin_flist_t 		*i_flistp,
	pin_flist_t 		*r_flistp,
	pin_errbuf_t            *ebufp)
{
	int             err = PIN_ERR_NONE;
	

	if (PIN_ERR_IS_ERR(ebufp))
	{
		return ;
	}
        PIN_ERR_CLEAR_ERR(ebufp);


	if (PIN_ERR_IS_ERR(ebufp)){
		/***************************************************
		 * Log Error Buffer and return.
		 ***************************************************/
		PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,
			"fm_bal_pol_get_bal_grp_and_svc error", ebufp);
	}
	return ;
}
/************************************************************************
 * fm_validate_existence_and_get ()
 *
 *   	Function to validate the existence of a field.  If a null
 *	pointer was found, an error is returned.  If not, then the
 *      (pointer to the) value is returned.
 *
 ************************************************************************/
void
fm_validate_existence_and_get(
pin_flist_t	*flistp,		/* Pointer to input flist	*/
int		partial,		/* If set, no mandatory fields  */
u_int		pin_fld_field_num,	/* Field currently checked	*/
void		**valpp,  		/* Set if empty field found	*/
pin_errbuf_t	*ebufp)			/* Error buffer pointer		*/

{
	void	*vp = NULL;			/* Void pointer			*/

	if (PIN_ERR_IS_ERR(ebufp))
		return;
	PIN_ERR_CLEAR_ERR(ebufp);

	if (partial) {
		vp = PIN_FLIST_FLD_GET(flistp, pin_fld_field_num, 1, ebufp);
	} else {
		vp = PIN_FLIST_FLD_GET(flistp, pin_fld_field_num, 0, ebufp);
	}

	if ( (vp == (void *)NULL)  && !partial) {
		pin_set_err(ebufp, PIN_ERRLOC_FM,
			    PIN_ERRCLASS_SYSTEM_DETERMINATE, 
			    PIN_ERR_MISSING_ARG,
			    pin_fld_field_num, 0, 0);
                PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,
				 "fm_validate_existence(): NULL ptr.", ebufp);
	}
	*valpp = vp;
	return;
}
/*******************************************************************
 * fm_price_pol_prep_dependency():
 *
 *	Prepare the given dependency flist for database insertion.
 *
 *	XXX NOOP - STUBBED PROTOTYPE ONLY XXX
 *
 *******************************************************************/
void
fm_price_pol_prep_dependency(
	pcm_context_t		*ctxp,
	u_int32			flags,
	pin_flist_t		*i_flistp,
	pin_flist_t		**o_flistpp,
        pin_errbuf_t		*ebufp)
{
	if (PIN_ERR_IS_ERR(ebufp))
		return;
	PIN_ERR_CLEAR_ERR(ebufp);

	/*
	 * Copy the input to output
	 */

	*o_flistpp = PIN_FLIST_COPY(i_flistp, ebufp);


	/*
	 * Error?
	 */
	if (PIN_ERR_IS_ERR(ebufp)) {
		PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,
			"fm_price_pol_prep_dependency error", ebufp);
	}

	return;
}
void
op_cust_pol_set_brandinfo(
	cm_nap_connection_t	*connp,
	int32			opcode,
	int32			opflags,
	pin_flist_t		*i_flistp,
	pin_flist_t		**r_flistpp,
	pin_errbuf_t		*ebufp)
{
        pcm_context_t           *ctxp = connp->dm_ctx;

	/*
	 * If there are pending errors, then short circuit immediately
	 */
        if (PIN_ERR_IS_ERR(ebufp))
                return;
        PIN_ERR_CLEAR_ERR(ebufp);

        /*
         * Null out results until we're sure there's something to send back
         */
        *r_flistpp = NULL;

        /*
         * Sanity check -- make sure we've routed the opcode appropriately
         */
        if (opcode != PCM_OP_CUST_POL_SET_BRANDINFO) {
                pin_set_err(ebufp, PIN_ERRLOC_FM,
                        PIN_ERRCLASS_SYSTEM_DETERMINATE,
                        PIN_ERR_BAD_OPCODE, 0, 0, opcode);
                PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,
                        "bad opcode in op_cust_pol_set_brandinfo", ebufp);
                return;
        }

	/*
	 * For completeness, dump the input flist if debugging is enabled.
	 */
        PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG,
                          "op_cust_pol_set_brandinfo input flist:",
                          i_flistp);

	/*
 	 * Call the main function -- this is where all the real work is done.
	 */
	fm_cust_pol_set_brandinfo(ctxp, opflags, i_flistp, r_flistpp, ebufp);

	/*
	 * For completeness, dump the results flist if debugging is enabled
	 * and we actually have a results flist.
	 */
	if(*r_flistpp != (pin_flist_t *)NULL) {
		PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG,
			"op_cust_pol_set_brandinfo output flist:",
			*r_flistpp);
	}

	return;
}
/*******************************************************************
 * fm_cust_pol_valid_passwd()
 *
 *	Validate the given passwd according to the given poid type.
 *
 *******************************************************************/
static void
fm_cust_pol_valid_passwd(
	pcm_context_t		*ctxp,
	pin_flist_t		*in_flistp,
	pin_flist_t		**out_flistpp,
        pin_errbuf_t		*ebufp)
{
	pin_flist_t		*r_flistp = NULL;

	poid_t			*o_pdp;
	const char		*o_type = NULL;

	if (PIN_ERR_IS_ERR(ebufp))
		return;
	PIN_ERR_CLEAR_ERR(ebufp);

	/***********************************************************
	 * Create outgoing flist
	 ***********************************************************/
	r_flistp = PIN_FLIST_CREATE(ebufp);
	*out_flistpp = r_flistp;

	/***********************************************************
	 * Get (and add) the object poid.
	 ***********************************************************/
	o_pdp = (poid_t *)PIN_FLIST_FLD_GET(in_flistp, PIN_FLD_POID, 0, ebufp);
	PIN_FLIST_FLD_SET(r_flistp, PIN_FLD_POID, (void *)o_pdp, ebufp);

	/***********************************************************
	 * We might have different rules for different services.
	 ***********************************************************/
	o_type = PIN_POID_GET_TYPE(o_pdp);

	if (!strncmp(o_type, "/service", 8)) {

		/* Any service password */
		fm_cust_pol_valid_pwd_srvc(ctxp, in_flistp, r_flistp, ebufp);

	} else {

		/* Error - unknown/usupported type */
		pin_set_err(ebufp, PIN_ERRLOC_FM,
			PIN_ERRCLASS_SYSTEM_DETERMINATE,
			PIN_ERR_BAD_POID_TYPE, PIN_FLD_POID, 0, 0);

	}

	/***********************************************************
	 * Error?
	 ***********************************************************/
	if (PIN_ERR_IS_ERR(ebufp)) {
		PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,
			"fm_cust_pol_valid_passwd error", ebufp);
	}

	return;
}
/*******************************************************************
 * 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_bill_pol_reverse_payment()
 ************************************************************************/
static  void
fm_bill_pol_reverse_payment(
	pcm_context_t      	*ctxp,
	int			flags,
	pin_flist_t             *in_flistp,
	pin_flist_t             **ret_flistpp,
	pin_errbuf_t       	*ebufp)	
{
	poid_t                  *a_pdp 		= NULL;
	pin_flist_t             *inh_flistp 	= NULL;
	
	if (PIN_ERR_IS_ERR(ebufp)){
		return;
	}
	PIN_ERR_CLEAR_ERR(ebufp);

	*ret_flistpp	=  PIN_FLIST_CREATE(ebufp);

	/***********************************************************
	 * Get and set PIN_FLD_POID in the output flist
	 ***********************************************************/
	a_pdp = PIN_FLIST_FLD_GET(in_flistp, PIN_FLD_POID, 0, ebufp);
	PIN_FLIST_FLD_SET(*ret_flistpp, PIN_FLD_POID, (void *)a_pdp, ebufp);

	/***********************************************************
	 * Get INHERITED_INFO from the input flist and
	 * Set in the ouput flist if present
	 ***********************************************************/
	inh_flistp = PIN_FLIST_SUBSTR_GET(in_flistp,
				PIN_FLD_INHERITED_INFO, 1, ebufp);
	if ( inh_flistp ) {
		PIN_FLIST_SUBSTR_SET(*ret_flistpp, inh_flistp, 
				PIN_FLD_INHERITED_INFO, ebufp);
	}

	fm_bill_pol_reverse_payment_writeoff_account(ctxp, flags, in_flistp,
						 ebufp);

	if (PIN_ERR_IS_ERR(ebufp)) {
		PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,
				"fm_bill_pol_reverse_payment error", ebufp);
	} else {
		PIN_ERR_CLEAR_ERR(ebufp);
	}
	return;
}
/************************************************************************
 * fm_validate_existence ()
 *
 *   	Function to validate the existence of a field.  If a null
 *	pointer was found, an error is returned.  The *empty_field
 *	flag will be set to PIN_BOOLEAN_TRUE if there's a 0 length
 *	string found.  This routine does NOT initialize this flag.
 *
 ************************************************************************/
void
fm_validate_existence(
pin_flist_t	*flistp,		/* Pointer to input flist	*/
int		partial,		/* if set, no mandatory fields  */
pin_flist_t	*r_flistp,		/* Pointer to return flist	*/
u_int		pin_fld_field_num,	/* Field currently checked	*/
u_int		pin_fld_element_id,	/* Element id of current array 	*/
u_int		*empty_field,		/* Set if empty field found	*/
pin_errbuf_t	*ebufp)			/* Error buffer pointer		*/

{
	void	*vp = NULL;		/* Void pointer			*/

	if (PIN_ERR_IS_ERR(ebufp))
		return;
	PIN_ERR_CLEAR_ERR(ebufp);

	/****************************************************************
	 * Only fill the failed field descriptor if the field exists but
	 * there is nothing there (i.e. *vp == '\0').
	 ****************************************************************/
	if (partial) {
		vp = PIN_FLIST_FLD_GET(flistp, pin_fld_field_num, 1, ebufp);
	} else {
		vp = PIN_FLIST_FLD_GET(flistp, pin_fld_field_num, 0, ebufp);
	}

	if (vp != (char *)NULL && (!partial))
	{
		if (strlen(vp) == 0)
		{
			(void)fm_cust_pol_valid_add_fail(r_flistp,
				pin_fld_field_num, pin_fld_element_id,
				PIN_CUST_VAL_ERR_MISSING, 
				"Missing field.", vp, ebufp);
			*empty_field = PIN_BOOLEAN_TRUE;
		}
	} else if (!partial) {
                pin_set_err(ebufp, PIN_ERRLOC_FM,
                        PIN_ERRCLASS_SYSTEM_DETERMINATE, PIN_ERR_MISSING_ARG,
			pin_fld_field_num, pin_fld_element_id, 0);
                PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,
			"fm_validate_existence(): NULL ptr.", ebufp);
	}
	return;
}
/*******************************************************************
 * fm_pymt_pol_charge()
 ******************************************************************/
static void 
fm_pymt_pol_charge(
	pcm_context_t           *ctxp,
	pin_flist_t             *i_flistp,
	pin_flist_t		*r_flistp,
	pin_errbuf_t            *ebufp)
{
	if (PIN_ERR_IS_ERR(ebufp))
	{
		return ;
	}
	PIN_ERR_CLEAR_ERR(ebufp);
	fm_pymt_pol_charge_set_reason_id(ctxp,r_flistp, ebufp);
	if (PIN_ERR_IS_ERR(ebufp)) {
		PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,
			"fm_pymt_pol_charge", ebufp);
	}	

	return;
}
/*******************************************************************
 * fm_cust_pol_pre_commit()
 *
 *	Pre-creation legacy system hook.
 *
 *	XXX NOOP - STUBBED ONLY XXX
 *
 *******************************************************************/
static void
fm_cust_pol_pre_commit(
	pcm_context_t		*ctxp,
	u_int           flags,
	pin_flist_t		*in_flistp,
	pin_flist_t		**out_flistpp,
        pin_errbuf_t		*ebufp)
{
	void			*vp;

	if (PIN_ERR_IS_ERR(ebufp))
		return;
	PIN_ERR_CLEAR_ERR(ebufp);

	/***********************************************************
	 * Create outgoing flist
	 ***********************************************************/
	*out_flistpp = PIN_FLIST_CREATE(ebufp);

	vp = PIN_FLIST_FLD_GET(in_flistp, PIN_FLD_POID, 0, ebufp);
	PIN_FLIST_FLD_SET(*out_flistpp, PIN_FLD_POID, vp, ebufp);

	/***********************************************************
	 * Check if Out Of Order detection feature is enabled.
	 * If so, create the /profile/event_ordering object.
	 ***********************************************************/
	if (fm_cust_pol_pre_commit_is_OOD_feature_enabled(ctxp, in_flistp, ebufp)) {
		fm_cust_pol_pre_commit_create_profile_OOD_obj(ctxp, flags, in_flistp, ebufp);
	}	

	/***********************************************************
	 * Error?
	 ***********************************************************/
	if (PIN_ERR_IS_ERR(ebufp)) {
		PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,
			"fm_cust_pol_pre_commit error", ebufp);
	}

	return;
}
/*******************************************************************
 * This is the default implementation for this policy
 *******************************************************************/
static void 
fm_act_pol_pre_reauthorize(
	pcm_context_t		*ctxp,
	int32			flags,
	pin_flist_t		*i_flistp,
	pin_flist_t		**r_flistpp,
	pin_errbuf_t		*ebufp)
{
	if (PIN_ERR_IS_ERR(ebufp))
		return;

	*r_flistpp = PIN_FLIST_COPY(i_flistp, ebufp);

	/********************************************************* 
	 * Errors..?
	 *********************************************************/
	if (PIN_ERR_IS_ERR(ebufp)) {
		PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,
			"fm_act_pol_pre_reauthorize error",ebufp);
	}
	
	return;
}
/*******************************************************************
 * This is the default implementation for this policy
 *******************************************************************/
static void 
fm_act_pol_post_authorize(
	pcm_context_t		*ctxp,
	int32			flags,
	pin_flist_t		*i_flistp,
	pin_flist_t		**r_flistpp,
	pin_errbuf_t		*ebufp)
{
	pin_flist_t	*rate_flistp = NULL;
	int32		elemid = 0;

	if (PIN_ERR_IS_ERR(ebufp))
		return;

	*r_flistpp = PIN_FLIST_COPY(i_flistp, ebufp);
	/* IF rating result is present in the output flist, drop it.
	 * By default we will drop this flist, to trim the final output flist.
         * If any of the vertical managers need this rating output, they need 
         * to customize the policy.
         */
	rate_flistp = PIN_FLIST_ELEM_GET(*r_flistpp, PIN_FLD_RESULTS,
		elemid, 1, ebufp);
	if (rate_flistp) {
		PIN_FLIST_ELEM_DROP(*r_flistpp, PIN_FLD_RESULTS, elemid, ebufp);
	}


	/********************************************************* 
	 * Errors..?
	 *********************************************************/
	if (PIN_ERR_IS_ERR(ebufp)) {
		PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,
			"fm_act_pol_post_authorize error",ebufp);
	}
	
	return;
}
/*****************************************************************
 * fm_pymt_pol_charge_set_domain_id()
 * Function to set the reason domain ID
 ******************************************************************/
static void
fm_pymt_pol_charge_set_domain_id(
        pcm_context_t           *ctxp,
        pin_flist_t             *i_flistp,
	pin_flist_t		*res_flistp,
        int32                   *domain_idp,
        pin_errbuf_t            *ebufp)
{
        void                    *vp = NULL;

        if (PIN_ERR_IS_ERR(ebufp))
        {
                return ;
        }
        PIN_ERR_CLEAR_ERR(ebufp);
	vp = PIN_FLIST_FLD_GET(i_flistp,
			PIN_FLD_REASON_DOMAIN_ID, 1,ebufp);
	/*****************************************************
	 * Set the domain ID in the Results array
	 *****************************************************/
	if(!vp){
		PIN_FLIST_FLD_SET(res_flistp, PIN_FLD_REASON_DOMAIN_ID,
					(void *) domain_idp, ebufp);

        }
	else{
		PIN_FLIST_FLD_SET(res_flistp, PIN_FLD_REASON_DOMAIN_ID,
						vp, ebufp);
	}

        if (PIN_ERR_IS_ERR(ebufp)) {
                PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,
                        "fm_pymt_pol_charge_set_domain_id", ebufp);
        }
        return ;
}