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;
}
/*******************************************************************
 * 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;
}
/*******************************************************************
 * 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;
}
/*******************************************************************
 * 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_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;
}
/*******************************************************************
 * 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;
}
/*******************************************************************
 * 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_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_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;
}
/*******************************************************************
 * 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_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;
}
/*ARGSUSED*/
static void
fm_cust_pol_set_brandname(
	pcm_context_t		*ctxp,
	int32			opflags,
	pin_flist_t		*i_flistp,
	pin_flist_t		**r_flistpp,
	pin_errbuf_t		*ebufp)
{
	char			*namep;
	poid_t			*poidp;
        poid_t                  *g_pdp;
	pin_flist_t		*sublistp;

	/* 
	 * For pending errors, return immediately.
	 */
	if(PIN_ERR_IS_ERR(ebufp))
		return;
	PIN_ERR_CLEAR_ERR(ebufp);

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

	/*
	 * Get the name if there is one 
	 */
	poidp = (poid_t *)PIN_FLIST_FLD_GET(i_flistp, PIN_FLD_POID, 0, ebufp);
	sublistp = (pin_flist_t *)PIN_FLIST_FLD_GET(i_flistp, 
		PIN_FLD_BRAND_INFO, 0, ebufp);
	namep = (char *)PIN_FLIST_FLD_GET(sublistp, PIN_FLD_NAME, 1, ebufp);
	if((namep == (char *)NULL) || (*namep == '\0')) {
		return;
	}	

	if(check_unique == BRANDWIDE_UNIQUE) {
		fm_cust_pol_is_brandname_unique_within_brand(ctxp, poidp,
			namep, r_flistpp, ebufp);
	}
	else if(check_unique == SYSTEMWIDE_UNIQUE) {
		fm_cust_pol_is_brandname_unique_global(ctxp, poidp, namep,
			r_flistpp, ebufp);
	}
}
/*******************************************************************
 * Main routine for the PCM_OP_PYMT_POL_PURCHASE_DEAL operation.
 *******************************************************************/
void
op_pymt_pol_purchase_deal(
        cm_nap_connection_t	*connp,
	int32			opcode,
        int32			flags,
        pin_flist_t		*i_flistp,
        pin_flist_t		**r_flistpp,
        pin_errbuf_t		*ebufp)
{
	if (PIN_ERR_IS_ERR(ebufp))
		return;
	PIN_ERR_CLEAR_ERR(ebufp);
        
	/*******************************************************************
	 * Insanity check.
 	 *******************************************************************/
	if (opcode != PCM_OP_PYMT_POL_PURCHASE_DEAL) {
		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_pymt_pol_purchase_deal bad opcode error", ebufp);
		return;
	}

	/*******************************************************************
	 * Debug: What we got.
 	 *******************************************************************/
	PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG,
		"op_pymt_pol_purchase_deal input flist", i_flistp);
        
	/** Dummy Implementation for the time being **/
	*r_flistpp = PIN_FLIST_COPY(i_flistp, ebufp);

	return;
}
/*******************************************************************
 * Main routine for the PCM_OP_PYMT_POL_CHARGE operation.
 *******************************************************************/
void
op_pymt_pol_charge(
        cm_nap_connection_t	*connp,
	int			opcode,
        int			flags,
        pin_flist_t		*i_flistp,
        pin_flist_t		**o_flistpp,
        pin_errbuf_t		*ebufp)
{
	pin_flist_t		*r_flistp = NULL;
	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_PYMT_POL_CHARGE) {
		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_pymt_pol_charge opcode error", ebufp);
		return;
	}

	/***********************************************************
	 * Debug: The input Flist
	 ***********************************************************/
	PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG,
		"op_pymt_pol_charge input flist", i_flistp);
	/**********************************************************
	 * Copy the input flist to r_flsitp as. Do not change the 
	 * Input Flist
	 *********************************************************/
	r_flistp = PIN_FLIST_COPY(i_flistp,ebufp);

	fm_pymt_pol_charge(ctxp, i_flistp, r_flistp,ebufp);
	if (PIN_ERR_IS_ERR(ebufp)) {
		/***************************************************
		 * Log something and return nothing.
		 **************************************************/
		PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,
			"op_pymt_pol_charge error", ebufp);
		PIN_FLIST_DESTROY_EX(&r_flistp, NULL);
		*o_flistpp = NULL;

	} 
	else
	{

		/***************************************************
		 * Point the real return flist to the right thing.
		 ***************************************************/
		*o_flistpp = r_flistp;

		/***************************************************
		 * Debug: What we're sending back.
		 ***************************************************/
		PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG,
			"op_pymt_pol_charge return flist", r_flistp);
	}

	return;
}
/*******************************************************************
 * Main routine for the PCM_OP_ACT_POL_SPEC_GLID operation.
 *******************************************************************/
void
op_act_pol_spec_glid(
    cm_nap_connection_t	*connp,
    int			opcode,
    int			flags,
    pin_flist_t		*i_flistp,
    pin_flist_t		**r_flistpp,
    pin_errbuf_t		*ebufp)
{
    pin_cookie_t		cookie = NULL;
    pcm_context_t		*ctxp = connp->dm_ctx;
    pin_flist_t		*e_flistp = NULL;
    pin_flist_t		*s_flistp = NULL;
    pin_flist_t		*flistp = NULL;
    const char			*event_type = NULL;
    poid_t			*e_pdp = NULL;

    int			rec_id = 0;
    int			*glid = NULL;

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

    /*******************************************************************
     * Insanity check.
     *******************************************************************/
    if (opcode != PCM_OP_ACT_POL_SPEC_GLID) {
        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_spec_glid bad opcode error", ebufp);
        return;
    }

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

    /*******************************************************************
     * Our action will depend on the type of event
     * Get the event substruct to get all the needed data
     *******************************************************************/
    *r_flistpp = PIN_FLIST_COPY(i_flistp, ebufp);
    e_flistp = PIN_FLIST_SUBSTR_GET(*r_flistpp, PIN_FLD_EVENT, 0, ebufp);
    e_pdp = (poid_t *)PIN_FLIST_FLD_GET(e_flistp, PIN_FLD_POID, 0, ebufp);
    event_type = PIN_POID_GET_TYPE(e_pdp);

    /******************************************************************
     * Check PIN_FLD_RATES_USED array, add a dummy one if not.
     ******************************************************************/
    if (PIN_FLIST_ELEM_COUNT(e_flistp, PIN_FLD_BAL_IMPACTS, ebufp) == 0) {

        /**********************************************************
         * Add the bal impacts array for this pre-rates event.
         **********************************************************/
        fm_act_pol_add_event_bal_impacts(ctxp, e_flistp, ebufp);
    }

    /******************************************************************
     * Now walk the PIN_FLD_RATES_USED array and check for G/L ID.
     ******************************************************************/
    while ((flistp = PIN_FLIST_ELEM_GET_NEXT(e_flistp, PIN_FLD_BAL_IMPACTS,
                     &rec_id, 1, &cookie, ebufp)) != (pin_flist_t *)NULL) {

        /**********************************************************
         * G/L id is inside the PIN_FLD_SUBTOTAL array.
         **********************************************************/
        glid = (int *)PIN_FLIST_FLD_GET(flistp,
                                        PIN_FLD_GL_ID, 1, ebufp);

        /**********************************************************
         * We need to fill in the G/L id now.
         **********************************************************/
        if (glid == (int *)NULL) {
            fm_act_pol_spec_glid(connp, i_flistp,
                                 event_type, flistp, ebufp);
        }
    }

    /*******************************************************************
     * Error?
     *******************************************************************/
    if (PIN_ERR_IS_ERR(ebufp)) {
        PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,
                         "op_act_pol_spec_glid error", ebufp);
    } else {
        PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG,
                          "op_act_pol_spec_glid return flist", *r_flistpp);
    }

    return;
}
/*******************************************************************
 * fm_pymt_pol_collect_writeoff_account():
 * This function checks for the event type .
 * If event type is /event/billing/writeoff_reversal
 * then it writesoff the account 
 *******************************************************************/
static void
fm_pymt_pol_collect_writeoff_account(
	pcm_context_t		*ctxp,
	pin_flist_t		*i_flistp,
	int			flags,
	pin_errbuf_t		*ebufp)
{
	pin_flist_t		*flistp = NULL;
	pin_flist_t		*wa_flistp = NULL;
	pin_flist_t		*r_flistp = NULL;
	char			*writeoff_event_type = { "" };
	int			result_flag = 0;
	void			*vp = NULL;
	int32			rec_id;
	pin_cookie_t		cookie = NULL;
	int			temp = 0;
	u_int			count = 0;

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

	/***********************************************************
	 * Check for the event type /event/billing/writeoff_reversal
	 ***********************************************************/
	cookie = NULL;
	while ((flistp = PIN_FLIST_ELEM_GET_NEXT(i_flistp, PIN_FLD_EVENTS,
		&rec_id, 1, &cookie, ebufp)) != (pin_flist_t *)NULL){
		
			vp = PIN_FLIST_FLD_GET( flistp, PIN_FLD_POID, 0, ebufp);

			if (vp != NULL)
				writeoff_event_type = 
					(char *)PIN_POID_GET_TYPE((poid_t *) vp );

			if( writeoff_event_type && strcmp( writeoff_event_type, 
					PIN_OBJ_TYPE_EVENT_WRITEOFF_REVERSAL) == 0 ){
				count++;
				break;		 			
			}
	}

	/*****************************************
	 * Bail out if no WOR performed
	 *****************************************/
	if( !count ) 
		return;
	
	vp = PIN_FLIST_FLD_GET( flistp,
		PIN_FLD_RESULT,	0, ebufp);
	if ( vp != NULL ) {
		result_flag = *(int *)vp;
	}

	if( result_flag == PIN_REVERSE_RES_PASS ) {
		
		/***********************************************************
		 * Writeoff the Account by calling PCM_OP_AR_ACCOUNT_WRITEOFF
		 ***********************************************************/
		wa_flistp = PIN_FLIST_CREATE(ebufp);

		vp = PIN_FLIST_FLD_GET(i_flistp, PIN_FLD_POID, 0, ebufp);
		PIN_FLIST_FLD_SET(wa_flistp, PIN_FLD_POID, vp, ebufp);

		vp = PIN_FLIST_FLD_TAKE(i_flistp, PIN_FLD_PROGRAM_NAME, 0, ebufp);
		PIN_FLIST_FLD_PUT(wa_flistp, PIN_FLD_PROGRAM_NAME, vp, ebufp);
		/*************************************************************
		* Add the String ID and String version for the GL
		*************************************************************/
		temp = PIN_WRITEOFF_FOR_AUTO_WRITEOFF_REVERSAL;
		PIN_FLIST_FLD_SET(wa_flistp, PIN_FLD_STRING_ID, &temp, ebufp);
		temp = PIN_REASON_CODES_CREDIT_REASONS;
		PIN_FLIST_FLD_SET(wa_flistp, PIN_FLD_STR_VERSION, &temp, ebufp);
		
		PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG,
			"fm_pymt_pol_collect_writeoff_account PCM_OP_AR_ACCOUNT_WRITEOFF input flist", 
			wa_flistp);
		PCM_OP(ctxp, PCM_OP_AR_ACCOUNT_WRITEOFF, flags, wa_flistp,
			&r_flistp, ebufp);
		PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG,
			"fm_pymt_pol_collect_writeoff_account PCM_OP_AR_ACCOUNT_WRITEOFF output flist", 
			r_flistp);

		if (PIN_ERR_IS_ERR(ebufp)) {
			PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,
				"fm_pymt_pol_collect_writeoff_account", ebufp);
		}
		
		/***********************************************************
		 * Clean up.
		 ***********************************************************/
		PIN_FLIST_DESTROY_EX(&wa_flistp, NULL);
		PIN_FLIST_DESTROY_EX(&r_flistp, NULL);

	}

	if (PIN_ERR_IS_ERR(ebufp)) {
		PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,
			"fm_pymt_pol_collect_writeoff_account error", ebufp);
	}
	
	return;
}
/*******************************************************************
 * Main routine for the PCM_OP_PYMT_POL_COLLECT operation.
 *******************************************************************/
void
op_pymt_pol_collect(
        cm_nap_connection_t	*connp,
	int			opcode,
        int			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;
	int			*cmdp = NULL;
	pin_flist_t             *e_flistp = NULL;
        pin_cookie_t            cookie = NULL;
        int32                   elemid = 0;

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

	/***********************************************************
	 * Insanity check.
	 ***********************************************************/
	if (opcode != PCM_OP_PYMT_POL_COLLECT) {
		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_pymt_pol_collect opcode error", ebufp);
		return;
	}

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

	/***********************************************************
	 * Prep the return flist.
	 ***********************************************************/
	r_flistp = PIN_FLIST_CREATE(ebufp);

	/******************************************************
         * Addition of PIN_FLD_EVENTS in output flist
         ******************************************************/

        while ((e_flistp = PIN_FLIST_ELEM_GET_NEXT(i_flistp,
                PIN_FLD_EVENTS, &elemid, 1, &cookie,
                ebufp)) != (pin_flist_t *)NULL) {
                PIN_FLIST_ELEM_SET(r_flistp, e_flistp, PIN_FLD_EVENTS,
                                                        elemid, ebufp);
        }

	cmdp = (int *)PIN_FLIST_FLD_GET(i_flistp, PIN_FLD_COMMAND, 0, ebufp); 
			 	
	if (cmdp && *cmdp == PIN_CHARGE_CMD_NONE){
		
		/***********************************************************
		 * Processing for PIN_CHARGE_CMD_NONE
		 ***********************************************************/
		fm_pymt_pol_collect_command_none(ctxp, i_flistp, flags,
							 	&r_flistp, ebufp);

	} else {

		/***********************************************************
		 * Fill in the results.
		 ***********************************************************/
		fm_pymt_pol_collect_result(ctxp, i_flistp, r_flistp, ebufp);

	}

	/***********************************************************
	 * Results.
	 ***********************************************************/
	if (PIN_ERR_IS_ERR(ebufp)) {

		/***************************************************
		 * Log something and return nothing.
		 ***************************************************/
		PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,
			"op_pymt_pol_collect error", ebufp);
		PIN_FLIST_DESTROY_EX(&r_flistp, NULL);
		*o_flistpp = NULL;

	} else {

		/***************************************************
		 * Point the real return flist to the right thing.
		 ***************************************************/
		PIN_ERR_CLEAR_ERR(ebufp);
		*o_flistpp = r_flistp;

		/***************************************************
		 * Debug: What we're sending back.
		 ***************************************************/
		PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG,
			"op_pymt_pol_collect return flist", r_flistp);

	}

	return;
}
/*******************************************************************
 * Main routine for the PCM_OP_CUST_POL_GET_POPLIST operation.
 *******************************************************************/
void
op_cust_pol_get_poplist(
        cm_nap_connection_t	*connp,		/* Connection pointer	*/
	u_int			opcode,		/* Opcode in question	*/
        u_int			flags,		/* Standard flags if any*/
        pin_flist_t		*in_flistp,	/* Input flist		*/
        pin_flist_t		**ret_flistpp,	/* Results flist	*/
        pin_errbuf_t		*ebufp)		/* Error buffer		*/
{
	pcm_context_t		*ctxp = connp->dm_ctx;	/* Connection	*/
	pin_flist_t		*r_flistp = NULL;	/* Local flist	*/
	void			*vp = NULL;

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

	/***********************************************************
	 * Insanity check.
	 ***********************************************************/
	if (opcode != PCM_OP_CUST_POL_GET_POPLIST) {
		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_poplist", ebufp);
		return;
	}

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

	/***********************************************************
	 * Create the pop flist & copy the input poid to it.
	 ***********************************************************/
	r_flistp = PIN_FLIST_CREATE(ebufp);

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

	/***********************************************************
	 * Call a sub-function to actually find the pops.
	 ***********************************************************/
	fm_cust_pol_get_poplist(ctxp, in_flistp, r_flistp, ebufp);

	/***********************************************************
	 * Result.
	 ***********************************************************/
	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_poplist error", ebufp);
	} else {
		*ret_flistpp = r_flistp;
		PIN_ERR_CLEAR_ERR(ebufp);
		PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG,
			"op_cust_pol_get_poplist return flist", r_flistp);
	}

	return;
}	/* op_cust_pol_get_poplist */
/*
 * 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);
}
/*******************************************************************
 * fm_cust_pol_prep_inherited()
 *
 *	Prep the inherited info to be ready for on-line registration.
 *
 *	XXX STUBBED ONLY XXX
 *
 *	We do fill in an empty service_ip substruct if one is needed. 
 *
 *******************************************************************/
static void
fm_cust_pol_prep_inherited(
	pcm_context_t		*ctxp,
	pin_flist_t		*in_flistp,
	pin_flist_t		**out_flistpp,
        pin_errbuf_t		*ebufp)
{
	pin_flist_t		*flistp = NULL;
	pin_flist_t		*sub_flistp = NULL;
	poid_t			*s_pdp = NULL;
	int32			intValue = 0;
	int32			*intp = NULL;
	char			*strp = NULL;
	const char		*s_type = NULL;

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

	/***********************************************************
	 * Create outgoing flist
	 ***********************************************************/
	*out_flistpp = PIN_FLIST_COPY(in_flistp, ebufp);

	/***********************************************************
	 * Dummy up the inherited info if none provided 
	 ***********************************************************/
	s_pdp = (poid_t *)PIN_FLIST_FLD_GET(in_flistp, PIN_FLD_POID, 0, ebufp);

	/**********************************************************
	 * Get the type information for quick comaparisons
	 **********************************************************/
	s_type = PIN_POID_GET_TYPE(s_pdp);

	/***********************************************************
	 * Add any mandatory "inherited_info" to the input flist. This
	 * effectively gets around the problem of missing substructs
	 * on service creations.
	 ***********************************************************/
        fm_utils_cust_add_missing_service_substructs(ctxp, *out_flistpp, ebufp);
	PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG,
		"op_cust_pol_prep_inherited ouput flist after adding missing substructs...", *out_flistpp);

	/***********************************************************
	 * Next, for any services that require special initialization,
	 * do that right here.
	 ***********************************************************/
	if ( s_type ) {
		
		if (strstr(s_type, "/service/gsm")) {
			flistp = PIN_FLIST_SUBSTR_GET(*out_flistpp,
				PIN_FLD_INHERITED_INFO, 0, ebufp);
			flistp = PIN_FLIST_SUBSTR_GET(flistp,
				PIN_FLD_GSM_INFO, 0, ebufp);

			PIN_FLIST_FLD_SET(flistp, PIN_FLD_BEARER_SERVICE, (void *)" ",
						ebufp);
			PIN_FLIST_FLD_SET(flistp, PIN_FLD_PRIMARY_MSISDN,
						(void *)&intValue, ebufp);
                }
	
		if ((strcmp(s_type, "/service/telco") == 0) ||
			(strncmp(s_type, "/service/telco/", 15) == 0)) {
			flistp = PIN_FLIST_SUBSTR_GET(*out_flistpp,
				PIN_FLD_INHERITED_INFO, 0, ebufp);
			flistp = PIN_FLIST_SUBSTR_GET(flistp,
				PIN_FLD_TELCO_INFO, 0, ebufp);

			intValue = 1;
			PIN_FLIST_FLD_SET(flistp, PIN_FLD_PRIMARY_NUMBER,
				(void *)&intValue, ebufp);
        }

		if (strstr(s_type, "/service/telco/gsm") == s_type) {
			flistp = PIN_FLIST_SUBSTR_GET(*out_flistpp,
				PIN_FLD_INHERITED_INFO, 0, ebufp);
			flistp = PIN_FLIST_SUBSTR_GET(flistp,
				PIN_FLD_TELCO_INFO, 0, ebufp);

			/*
			 * By default Primary Number flag is 0 for GSM 
			 * services, so override the value set in above
			 * generic /service/telco block.
			 */
			intValue = 0;
			PIN_FLIST_FLD_SET(flistp, PIN_FLD_PRIMARY_NUMBER,
				(void *)&intValue, ebufp);

			flistp = PIN_FLIST_SUBSTR_GET(*out_flistpp,
				PIN_FLD_INHERITED_INFO, 0, ebufp);
			flistp = PIN_FLIST_SUBSTR_GET(flistp,
				PIN_FLD_GSM_INFO, 0, ebufp);

			PIN_FLIST_FLD_SET(flistp, PIN_FLD_BEARER_SERVICE,
					(void *)"Bearer Service", ebufp);
			PIN_FLIST_FLD_SET(flistp, PIN_FLD_IMEI,
					(void *)"IMEI", ebufp);
		}

		if ( !strcmp("/service/telephony", s_type ) ) { 

			flistp = PIN_FLIST_SUBSTR_GET(*out_flistpp,
				PIN_FLD_INHERITED_INFO, 0, ebufp);
			flistp = PIN_FLIST_SUBSTR_GET(flistp,
				PIN_FLD_SERVICE_TELEPHONY, 0, ebufp);

			intp = (int32 *)PIN_FLIST_FLD_GET(flistp, 
				PIN_FLD_MAX_ACTIVE_CALLS, 1, ebufp);
			if(intp == (int32 *)NULL) {
				/* Set "non-zero, non-blank" default values */
				intValue = 1;  /* Default Max Active Calls */
				PIN_FLIST_FLD_SET(flistp, PIN_FLD_MAX_ACTIVE_CALLS, 
						(void*)&intValue, ebufp);

			}

		}
	
		if ( !strcmp( "/service/ip/cable/teracomm", s_type ) ) {
			int32		zero = 0;
			int32		init_led_status;
	
			flistp = PIN_FLIST_SUBSTR_GET(*out_flistpp,
				PIN_FLD_INHERITED_INFO, 0, ebufp);
			sub_flistp = PIN_FLIST_SUBSTR_GET(flistp, 
				PIN_FLD_SERVICE_IP_CABLE, 0, ebufp);
			/*
		 	 * Set PIN_FLD_MODEM_MAC_ADDR and the bandwidth limit
		 	 * fields to known initial values, so that dm_teracomm
		 	 * can determine whether provisioning fields are set.
		 	 * The initial value for PIN_FLD_MODEM_MAC_ADDR is not
		 	 * a valid address (valid addresses are 12 hex. chars.).
		 	 */
			strp = (char *)PIN_FLIST_FLD_GET(sub_flistp, 
				PIN_FLD_MODEM_MAC_ADDR, 1, ebufp);
			if(strp == (char *)NULL) {
				PIN_FLIST_FLD_SET(sub_flistp, PIN_FLD_MODEM_MAC_ADDR,
					(void *)PIN_TERACOMM_UNSPECIFIED_MODEM_MAC_ADDR,
					ebufp);
			}
			PIN_FLIST_FLD_SET(sub_flistp, PIN_FLD_MIN_DOWNSTREAM_BANDWD,
					(void *)&zero, ebufp);
			PIN_FLIST_FLD_SET(sub_flistp, PIN_FLD_MAX_DOWNSTREAM_BANDWD,
					(void *)&zero, ebufp);
			PIN_FLIST_FLD_SET(sub_flistp, PIN_FLD_MIN_UPSTREAM_BANDWD,
					(void *)&zero, ebufp);
			PIN_FLIST_FLD_SET(sub_flistp, PIN_FLD_MAX_UPSTREAM_BANDWD,
					(void *)&zero, ebufp);
	
			/* 
		 	 * Initialize fields in /service/ip/cable/teracomm substruct.
		 	 */
			sub_flistp = PIN_FLIST_SUBSTR_GET(flistp, 
					PIN_FLD_SERVICE_IP_CABLE_TERACOMM, 0, ebufp);
			PIN_FLIST_FLD_SET(sub_flistp, PIN_FLD_IP_LIMIT,
					(void *)&zero, ebufp);
			init_led_status = PIN_TERACOMM_LED_STATUS_OFF;
			PIN_FLIST_FLD_SET(sub_flistp, PIN_FLD_LED_STATUS,
					(void *)&init_led_status, ebufp);
			strp = (char *)PIN_FLIST_FLD_GET(sub_flistp, 
					PIN_FLD_TERALINK_NAME, 1, ebufp);
			if(strp == (char *)NULL) {
				PIN_FLIST_FLD_SET(sub_flistp, PIN_FLD_TERALINK_NAME,
					(void *)"", ebufp);
			}
			strp = (char *)PIN_FLIST_FLD_GET(sub_flistp, 
					PIN_FLD_ASSOC_NETWORK, 1, ebufp);
			if(strp == (char *)NULL) {
				PIN_FLIST_FLD_SET(sub_flistp, PIN_FLD_ASSOC_NETWORK,
					(void *)"", ebufp);
			}
		}
	
		if ( !strcmp(PIN_MSEXCHANGE_SERVICE_TYPE_USER, s_type ) ) {
			char 		*int_str = "";
			flistp = PIN_FLIST_SUBSTR_GET(*out_flistpp,
				PIN_FLD_INHERITED_INFO, 0, ebufp);
			sub_flistp = PIN_FLIST_SUBSTR_GET(flistp, 
				PIN_FLD_SERVICE_MSEXCHANGE_USER, 0, ebufp);
			PIN_FLIST_FLD_SET(sub_flistp, PIN_FLD_ORG_UNIT_NAME,
					(void *)int_str, ebufp);
		}
		if ( !strcmp( PIN_MSEXCHANGE_SERVICE_TYPE_FIRSTADMIN, s_type ) ){
			int32		int_value = PIN_MSEXCHANGE_INIT_STATE_INT_VALUE;
			char 		*int_str = "";
			flistp = PIN_FLIST_SUBSTR_GET(*out_flistpp,
				PIN_FLD_INHERITED_INFO, 0, ebufp);
			sub_flistp = PIN_FLIST_SUBSTR_GET(flistp, 
				PIN_FLD_SERVICE_MSEXCHANGE_USER, 0, ebufp);
			PIN_FLIST_FLD_SET(sub_flistp, PIN_FLD_ORG_UNIT_NAME,
					(void *)int_str, ebufp);
			flistp = PIN_FLIST_SUBSTR_GET(*out_flistpp,
				PIN_FLD_INHERITED_INFO, 0, ebufp);
			sub_flistp = PIN_FLIST_SUBSTR_GET(flistp, 
				PIN_FLD_SERVICE_MSEXCHANGE_ORG, 0, ebufp);
			PIN_FLIST_FLD_SET(sub_flistp, PIN_FLD_ORG_DISPLAY_NAME,
					(void *)int_str, ebufp);
			PIN_FLIST_FLD_SET(sub_flistp, PIN_FLD_SMTP_DOMAIN_NAME,
					(void *)int_str, ebufp);
			PIN_FLIST_FLD_SET(sub_flistp, PIN_FLD_MAX_USER_COUNT,
					(void *)&int_value, ebufp);
			PIN_FLIST_FLD_SET(sub_flistp, PIN_FLD_DEFAULT_MAX_MBOX_SIZE,
					(void *)&int_value, ebufp);
		}
	}

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

	return;
}
/*******************************************************************
 * Main routine for the PCM_OP_PYMT_POL_SPEC_COLLECT operation.
 *******************************************************************/
void
op_pymt_pol_spec_collect(
        cm_nap_connection_t	*connp,
	int32			opcode,
        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;
	pin_bill_type_t		*p_type = NULL;
	int32			result = PIN_BOOLEAN_FALSE;

	char			*action = NULL;

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

	/***********************************************************
	 * Insanity check.
	 ***********************************************************/
	if (opcode != PCM_OP_PYMT_POL_SPEC_COLLECT) {
		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_pymt_pol_spec_collect opcode error", ebufp);
		return;
	}

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

	/***********************************************************
	 * Prep the return flist.
	 ***********************************************************/
	r_flistp = PIN_FLIST_CREATE(ebufp);

	/***********************************************************
	 * Get the requested action. The following are supported:
	 *	- "commit customer"
	 *
	 ***********************************************************/
	action = (char *)PIN_FLIST_FLD_GET(i_flistp, PIN_FLD_ACTION, 0, ebufp);

	if ((action != (char *)NULL) && (!strcmp(action, "commit customer"))) {

		p_type = (pin_bill_type_t *)PIN_FLIST_FLD_GET(i_flistp,
			PIN_FLD_PAY_TYPE, 0, ebufp);

		/***************************************************
		 * Credit card
		 ***************************************************/
		if ((p_type != NULL) && (*p_type == PIN_BILL_TYPE_CC)) {
			fm_pymt_pol_spec_collect_commit_cust_cc(ctxp,
				flags, i_flistp, r_flistp, ebufp);

		/***************************************************
		 * Direct Debit
		 ***************************************************/
		} else if ((p_type != NULL) && (*p_type == PIN_BILL_TYPE_DD)) {
			fm_pymt_pol_spec_collect_commit_cust_dd(ctxp,
				flags, i_flistp, r_flistp, ebufp);

		/***************************************************
		 * Assume nothing to collect
		 ***************************************************/
		} else {
			result = PIN_BOOLEAN_FALSE;
			PIN_FLIST_FLD_SET(r_flistp, PIN_FLD_BOOLEAN,
			(void *)&result, ebufp);
        	}

	} else {
		pin_set_err(ebufp, PIN_ERRLOC_FM,
			PIN_ERRCLASS_SYSTEM_DETERMINATE,
			PIN_ERR_BAD_VALUE, PIN_FLD_ACTION, 0, 0);
	}

	/***********************************************************
	 * Results.
	 ***********************************************************/
	if (PIN_ERR_IS_ERR(ebufp)) {

		/***************************************************
		 * Log something and return nothing.
		 ***************************************************/
		PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,
			"op_pymt_pol_spec_collect error", ebufp);
		PIN_FLIST_DESTROY_EX(&r_flistp, NULL);
		*o_flistpp = NULL;

	} else {

		/***************************************************
		 * Point the real return flist to the right thing.
		 ***************************************************/
		PIN_ERR_CLEAR_ERR(ebufp);
		*o_flistpp = r_flistp;

		/***************************************************
		 * Debug: What we're sending back.
		 ***************************************************/
		PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG,
			"op_pymt_pol_spec_collect return flist", r_flistp);

	}

	return;
}
/*******************************************************************
 * Main routine for the PCM_OP_PRICE_POL_DELETE_DEAL operation.
 *******************************************************************/
EXPORT_OP void
op_price_pol_delete_deal(
        cm_nap_connection_t	*connp,
	u_int32			opcode,
        u_int32			flags,
        pin_flist_t		*i_flistp,
        pin_flist_t		**r_flistpp,
        pin_errbuf_t		*ebufp)
{
	pcm_context_t		*ctxp = connp->dm_ctx;
	u_int32			result;
	void			*vp = NULL;

	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_PRICE_POL_DELETE_DEAL) {
		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_delete_deal", ebufp);
		return;
	}

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

	/*
	 * Setup the result flist
	 */
	*r_flistpp = PIN_FLIST_CREATE(ebufp);

	vp = PIN_FLIST_FLD_GET(i_flistp, PIN_FLD_POID, 0, ebufp);
	PIN_FLIST_FLD_SET(*r_flistpp, PIN_FLD_POID, vp, ebufp);

	result = PIN_PRICE_VERIFY_PASSED;
	PIN_FLIST_FLD_SET(*r_flistpp, PIN_FLD_RESULT, (void *)&result, ebufp);

	/*
	 * Error?
	 */
	if (PIN_ERR_IS_ERR(ebufp)) {
		PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_DEBUG,
			"op_price_pol_delete_deal error", ebufp);
	} else {
		PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG,
			"op_price_pol_delete_deal return flist", *r_flistpp);
	}

	return;
}
void
fm_cust_pol_create_metafield_obj(
    pcm_context_t           *ctxp,
    int32                    flags,
    pin_flist_t             *in_flistp,
    pin_flist_t            **ret_flistpp,
    pin_errbuf_t            *ebufp)

{
    void 		   *vp = NULL;
    int 		   count =0;
    int64        database  = pcm_get_current_db_no(ctxp);
    pin_flist_t   *i_flist = NULL;
    pin_flist_t   *sub_flistp = NULL;
    pin_flist_t   *r_flistp = NULL;
    char 	      *program_name = NULL;
    char 	      *class_name= NULL;
    char 	      *default_value= NULL;
    int 	       fld_type=0;

    if(PIN_ERRBUF_IS_ERR(ebufp))
        return;
    PIN_ERR_CLEAR_ERR(ebufp);

    *ret_flistpp = NULL;

    //Count FIELDS array
    count = PIN_FLIST_ELEM_COUNT(in_flistp,PIN_FLD_VALUES,ebufp);


    if (count==0)
        return;

    if(count==1)
    {

        i_flist= PIN_FLIST_CREATE(ebufp);
        vp = PIN_FLIST_FLD_GET(in_flistp,PIN_FLD_POID,1,ebufp);
        PIN_FLIST_FLD_SET(i_flist,PIN_FLD_POID,(void*)vp,ebufp);

        sub_flistp = PIN_FLIST_ELEM_GET(in_flistp, PIN_FLD_VALUES,PIN_ELEMID_ANY, 1, ebufp);
        program_name = PIN_FLIST_FLD_GET(sub_flistp,PIN_FLD_NAME,1,ebufp);
        PIN_FLIST_FLD_SET(i_flist,PIN_FLD_NAME,program_name,ebufp);

        fld_type =*(int*) PIN_FLIST_FLD_GET(sub_flistp,PIN_FLD_TYPE,1,ebufp);
        PIN_FLIST_FLD_SET(i_flist,PIN_FLD_TYPE,&fld_type,ebufp);

        class_name=PIN_FLIST_FLD_GET(sub_flistp,PIN_FLD_CLASS_NAME,1,ebufp);
        PIN_FLIST_FLD_SET(i_flist,PIN_FLD_CLASS_NAME,class_name,ebufp);

        default_value=PIN_FLIST_FLD_GET(sub_flistp,PIN_FLD_DEFAULT_VALUE,1,ebufp);
        if(default_value)
            PIN_FLIST_FLD_SET(i_flist,PIN_FLD_DEFAULT_VALUE,default_value,ebufp);

        if (PIN_ERRBUF_IS_ERR(ebufp))
        {
            PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,"Error Occured while creating the input flist",ebufp);
            return;
        }

        PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG,"input flist for metafield obj ",i_flist);


        //Call pcm_op_create_obj
        PCM_OP(ctxp,PCM_OP_CREATE_OBJ,0,i_flist,ret_flistpp,ebufp);

        if(PIN_ERRBUF_IS_ERR(ebufp))
        {
            PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,"Error Occured while calling PCM_OP_CREATE_OBJ",ebufp);
            return;
        }

    }
    else if (count >1)
    {
        //Call pcm_op_bulk_create_obj
        PCM_OP(ctxp,PCM_OP_BULK_CREATE_OBJ ,0,in_flistp,ret_flistpp,ebufp);

        if(PIN_ERRBUF_IS_ERR(ebufp))
        {
            PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,"Error Occured while calling PCM_OP_BULK_CREATE_OBJ" ,ebufp);
            return;
        }
    }

    if(ret_flistpp)
        PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG,"Output flist for metafield obj ",*ret_flistpp);

    return;

}
//****************************************************
// 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;
}
/*******************************************************************
 * Main routine for the PCM_OP_GET_METAFIELD operation.
 *******************************************************************/
void
op_get_meta_field(
        cm_nap_connection_t	*connp,
	u_int			opcode,
        u_int			flags,
        pin_flist_t		*in_flistp,
        pin_flist_t             **ret_flistp,
        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_GET_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_get_meta_field opcode error", ebufp);
                return;
        }

		/*  Debug - What we got */
		
	PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG,
		"op_get_meta_field", in_flistp);


	/***********************************************************
         * Call main function 
         ***********************************************************/
        fm_get_meta_field(ctxp, in_flistp, &r_flistp, ebufp);
        
        if (PIN_ERR_IS_ERR(ebufp)) {
                /***************************************************
                 * Log Error Buuffer and return.
                 ***************************************************/
                PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,
                        "op_get_meta_field", ebufp);
                PIN_FLIST_DESTROY_EX(&r_flistp, NULL);
                *ret_flistp = NULL;

        }
        else
        {

		*ret_flistp = PIN_FLIST_COPY(r_flistp, ebufp);
                /***************************************************
                 * Debug: What we're sending back.
                 ***************************************************/
                PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG,
                        "op_get_meta_field return flist", r_flistp);
        }

		
  /*** Print Output What We Got ***/
        PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG,"fm_get_meta_field", r_flistp);

	
		return;
		}
static void
fm_get_meta_field(
	pcm_context_t           *ctxp,
        pin_flist_t             *in_flistp,
        pin_flist_t             **out_flistpp,
        pin_errbuf_t            *ebufp)
{
	pin_flist_t     *keys_flistp = NULL;
        pin_flist_t     *search_flistp = NULL;
        pin_flist_t     *flistp = NULL; 
        poid_t          *s_pdp = NULL; 
        poid_t          *bi_pdp = NULL; 
        int64           database = 0;
        int32           sflags = 256;
        int32           result = PIN_BOOLEAN_FALSE;
        void            *vp = NULL;
        pin_decimal_t   *zero_decimal =  pin_decimal("0.0", ebufp);
	pin_flist_t	*r_flistp = NULL;
	char                    *name = NULL;
	char                    *class_name = NULL;
	char                    *default_value;
	int32           count = 0;
	int32           cnt_flds = 0;
	int32                   elemid = 1;
	pin_errbuf_t            any_field_ebuf;
        pin_cookie_t            cookie = NULL;
        pin_fld_num_t           field = 0;
        int32                   rec_id = 0;
	void            *type = NULL;

        if (PIN_ERR_IS_ERR(ebufp)) {
                return;
        }
        PIN_ERR_CLEAR_ERR(ebufp);
	PIN_ERR_CLEAR_ERR(&any_field_ebuf);
	
	PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG, "fm_get_meta_field input flistp", in_flistp);
	bi_pdp = (poid_t *) PIN_FLIST_FLD_GET(in_flistp,
                                PIN_FLD_POID,0, ebufp);

	count = PIN_FLIST_ELEM_COUNT (in_flistp,
                        PIN_FLD_KEYS, ebufp);
	if (count == 0)
        {

                 pin_set_err(ebufp, PIN_ERRLOC_FM,
                        PIN_ERRCLASS_SYSTEM_DETERMINATE,
                        PIN_ERR_BAD_OPCODE, 0, 0, count);
                PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR,
                        "op_get_meta_field search flistp", ebufp);

                *out_flistpp = NULL;
                return;
        }

	else {
	keys_flistp = PIN_FLIST_ELEM_GET (in_flistp, PIN_FLD_KEYS,
                PIN_ELEMID_ANY, 0, ebufp);
	while (PIN_FLIST_ANY_GET_NEXT(keys_flistp, &field,
                                &rec_id, &cookie, &any_field_ebuf) != NULL ){
        cnt_flds = cnt_flds + 1;
	if (field == PIN_FLD_NAME){
 	name = (char *)PIN_FLIST_FLD_GET(keys_flistp, PIN_FLD_NAME, 1, ebufp);
	}
	if (field == PIN_FLD_CLASS_NAME){
       class_name = PIN_FLIST_FLD_GET(keys_flistp, PIN_FLD_CLASS_NAME, 0, ebufp );
	}
	if (field == PIN_FLD_TYPE){
	type = PIN_FLIST_FLD_GET(keys_flistp, PIN_FLD_TYPE, 0, ebufp );			
	}
	}
	if ( cnt_flds == 1)
        {
        vp = (void *)"select X from /metafield where F1 = V1 ";
        }
        if ( cnt_flds == 2)
        {
        vp = (void *)"select X from /metafield where F1 = V1 and F2 = V2 ";
        }
        if ( cnt_flds == 3)
        {
        vp = (void *)"select X from /metafield where F1 = V1 and F2 = V2 and F3 = V3 ";
        }

	 /*********************************************************
         * Create the search flist to search in the item objects
         *********************************************************/
        search_flistp = PIN_FLIST_CREATE(ebufp);
        database = PIN_POID_GET_DB(bi_pdp);
        s_pdp = PIN_POID_CREATE(database, "/search", -1, ebufp);
        PIN_FLIST_FLD_PUT(search_flistp, PIN_FLD_POID, (void *)s_pdp, ebufp);
       /******************************************************************
         * Set the search template.
         ******************************************************************/
        PIN_FLIST_FLD_SET(search_flistp, PIN_FLD_TEMPLATE, vp, ebufp);
        PIN_FLIST_FLD_SET(search_flistp, PIN_FLD_FLAGS, (void *)&sflags, ebufp);

	/*********************************************************
         * Add the search arguments.
         *********************************************************/
	if (name != NULL) {
        flistp = PIN_FLIST_ELEM_ADD(search_flistp, PIN_FLD_ARGS, elemid++, ebufp);
        PIN_FLIST_FLD_SET(flistp, PIN_FLD_NAME, name, ebufp);
	}

        /*********************************************************
         * Add the search arguments.
         *********************************************************/
	if (class_name != NULL) {
        flistp = PIN_FLIST_ELEM_ADD(search_flistp, PIN_FLD_ARGS, elemid++, ebufp);
        PIN_FLIST_FLD_SET(flistp, PIN_FLD_CLASS_NAME, class_name, ebufp);
        }
	
	/*********************************************************
         * Add the search arguments.
         *********************************************************/
        if (type != NULL) {
        flistp = PIN_FLIST_ELEM_ADD(search_flistp, PIN_FLD_ARGS, elemid++, ebufp);
        PIN_FLIST_FLD_SET(flistp, PIN_FLD_TYPE, type, ebufp);
        }


        /*********************************************************
         * Add the result array for the search.
         *********************************************************/

        flistp = PIN_FLIST_ELEM_ADD(search_flistp, PIN_FLD_RESULTS, 0, ebufp);
	PIN_FLIST_FLD_SET(flistp, PIN_FLD_TYPE,(void *)NULL, ebufp);
        
	PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG, "op_get_meta_field search flistp", search_flistp);  

	 PCM_OP(ctxp, PCM_OP_SEARCH, 0, search_flistp, out_flistpp, ebufp);

	PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG, "op_get_meta_field search flistp", *out_flistpp);
	}
	     
 	}