}
int do_interaction(struct eu_context_t *euc){	int rc = W_OK;#ifdef PHASE1	/*	 * Zero out the memory because of union odbc_data_t to prevent data	 * overflow from lingering data when the stored procedure is called.     */	bzero(&euc->odbcd, sizeof(union odbc_data_t));#endif /* PHASE1 */	/* Call the appropriate function to generate the input data. */	switch (euc->interaction)	{		case ADMIN_CONFIRM:			prepare_admin_confirm(euc);#ifdef PHASE1			rc = copy_in_admin_confirm(euc, &euc->odbcd);			if (rc != W_OK)			{				return W_ERROR;			}			rc = execute_admin_confirm(&euc->odbcc, &euc->odbcd);			if (rc != W_OK)			{				return W_ERROR;			}			copy_out_admin_confirm(euc, &euc->odbcd);#endif /* PHASE1 */			break;		case ADMIN_REQUEST:			prepare_admin_request(euc);#ifdef PHASE1			rc = copy_in_admin_request(euc, &euc->odbcd);			if (rc != W_OK)			{				return W_ERROR;			}			rc = execute_admin_request(&euc->odbcc, &euc->odbcd);			if (rc == W_OK)			{				copy_out_admin_request(euc, &euc->odbcd);			}#endif /* PHASE1 */			break;		case BEST_SELLERS:			prepare_best_sellers(euc);#ifdef PHASE1			copy_in_best_sellers(euc, &euc->odbcd);			rc = execute_best_sellers(&euc->odbcc, &euc->odbcd);			switch (rc)			{				case W_ZERO_ITEMS:					LOG_ERROR_MESSAGE("%s returned %d items for %s.\n",						interaction_short_name[euc->interaction],						euc->best_sellers_data.items,						euc->best_sellers_data.i_subject);				case W_ERROR:					return W_ERROR;			}			copy_out_best_sellers(euc, &euc->odbcd);#endif /* PHASE1 */			break;		case BUY_CONFIRM:			prepare_buy_confirm(euc);#ifdef PHASE1			copy_in_buy_confirm(euc, &euc->odbcd);			rc = execute_buy_confirm(&euc->odbcc, &euc->odbcd);			if (rc == W_OK)			{				copy_out_buy_confirm(euc, &euc->odbcd);			}			euc->sc_id = UNKNOWN_SHOPPING_CART;#endif /* PHASE1 */			break;		case BUY_REQUEST:			prepare_buy_request(euc);#ifdef PHASE1			copy_in_buy_request(euc, &euc->odbcd);			rc = execute_buy_request(&euc->odbcc, &euc->odbcd);			if (rc == W_OK)			{				copy_out_buy_request(euc, &euc->odbcd);			}			euc->c_id = euc->buy_request_data.c_id;#endif /* PHASE1 */			break;		case CUSTOMER_REGISTRATION:			/*			 * This isn't a database interaction so we can just return at this			 * point.			 */			return W_OK;		case HOME:			rc = prepare_home(euc);			if (rc != W_OK)			{				return W_ERROR;			}#ifdef PHASE1			copy_in_home(euc, &euc->odbcd);			rc = execute_home(&euc->odbcc, &euc->odbcd);			if (rc == W_OK)			{				copy_out_home(euc, &euc->odbcd);			}#endif /* PHASE1 */			break;		case NEW_PRODUCTS:			prepare_new_products(euc);#ifdef PHASE1			copy_in_new_products(euc, &euc->odbcd);			rc = execute_new_products(&euc->odbcc, &euc->odbcd);			switch (rc)			{				case W_ZERO_ITEMS:					LOG_ERROR_MESSAGE("%s returned %d items for %s.\n",						interaction_short_name[euc->interaction],						euc->new_products_data.items,						euc->new_products_data.i_subject);				case W_ERROR:					return W_ERROR;			}			copy_out_new_products(euc, &euc->odbcd);#endif /* PHASE1 */			break;		case ORDER_DISPLAY:			rc = prepare_order_display(euc);			if (rc != W_OK)			{				return W_ERROR;			}#ifdef PHASE1			copy_in_order_display(euc, &euc->odbcd);			rc = execute_order_display(&euc->odbcc, &euc->odbcd);			if (rc == W_OK)			{				copy_out_order_display(euc, &euc->odbcd);			}#endif /* PHASE1 */			break;		case ORDER_INQUIRY:			if (euc->c_id == UNKNOWN_CUSTOMER)			{				return W_OK;			}			prepare_order_inquiry(euc);#ifdef PHASE1			copy_in_order_inquiry(euc, &euc->odbcd);			rc = execute_order_inquiry(&euc->odbcc, &euc->odbcd);			if (rc == W_OK)			{				copy_out_order_inquiry(euc, &euc->odbcd);			}#endif /* PHASE1 */			break;		case PRODUCT_DETAIL:			rc = prepare_product_detail(euc);/*#ifdef DEBUG			DEBUGMSG("product detail id %lld", euc->product_detail_data.i_id);#endif*/			if (rc != W_OK)			{				return W_ERROR;			}#ifdef PHASE1			copy_in_product_detail(euc, &euc->odbcd);			rc = execute_product_detail(&euc->odbcc, &euc->odbcd);			if (rc == W_OK)			{				copy_out_product_detail(euc, &euc->odbcd);			}#endif /* PHASE1 */			break;		case SEARCH_REQUEST:#ifdef PHASE1			rc = execute_search_request(euc, &euc->odbcd);			if (rc == W_OK)			{				copy_out_search_request(euc, &euc->odbcd);			}#endif /* PHASE1 */			break;		case SEARCH_RESULTS:			rc = prepare_search_results(euc);			if (rc != W_OK)			{				return W_ERROR;			}#ifdef PHASE1#ifdef SEARCH_RESULTS_CACHE			if (euc->search_results_data.search_type != SEARCH_SUBJECT)			{				rc = send_search_results(euc->cache_s, &euc->search_results_data);				/* if send fails, reopen a new socket */				if (rc!=W_OK)				{					LOG_ERROR_MESSAGE("send search_results to cache host failed");					close(euc->cache_s);					euc->cache_s=_connect(cache_host, cache_port);					if (euc->cache_s==-1)					{						LOG_ERROR_MESSAGE("connect to cache failed\n");						return W_ERROR;					}					return W_ERROR;				}				rc = receive_search_results(euc->cache_s, &euc->search_results_data);				if (rc!=W_OK)				{					LOG_ERROR_MESSAGE("receive search_results from cache host failed");					close(euc->cache_s);					euc->cache_s=_connect(cache_host, cache_port);					if (euc->cache_s==-1)					{						LOG_ERROR_MESSAGE("connect to cache failed\n");						return W_ERROR;					}					return W_ERROR;				}/*				if (rc==0)				{					LOG_ERROR_MESSAGE("cache host closed socket");					return SOCKET_CLOSE;				}*/			}			else			{				copy_in_search_results(euc, &euc->odbcd);				rc = execute_search_results(&euc->odbcc, &euc->odbcd);				if (rc == W_OK)				{					copy_out_search_results(euc, &euc->odbcd);				}			}#else			copy_in_search_results(euc, &euc->odbcd);			rc = execute_search_results(&euc->odbcc, &euc->odbcd);			if (rc == W_OK)			{				copy_out_search_results(euc, &euc->odbcd);			}#endif /*SEARCH_RESULTS_CACHE*/#endif /* PHASE1 */			break;		case SHOPPING_CART:			prepare_shopping_cart(euc);#ifdef PHASE1			copy_in_shopping_cart(euc, &euc->odbcd);			rc = execute_shopping_cart(&euc->odbcc, &euc->odbcd);			if (rc == W_OK)			{				copy_out_shopping_cart(euc, &euc->odbcd);			}			euc->sc_id = euc->shopping_cart_data.sc_id;#endif /* PHASE1 */			break;		default:			LOG_ERROR_MESSAGE("unknown interaction %d\n", euc->interaction);			rc = W_ERROR;			break;	}#ifdef PHASE2	/* Send and receive data to the middle tier program. */	if (send_interaction_packet(euc->s, euc) == W_ERROR)	{		LOG_ERROR_MESSAGE("send failed");		return W_ERROR;	}	if ( (rc=receive_interaction_packet(euc->s, euc)) == W_ERROR)	{		LOG_ERROR_MESSAGE("receive failed");		return W_ERROR;	}	if (rc==SOCKET_CLOSE)	{		LOG_ERROR_MESSAGE("appServer socket closed");		return SOCKET_CLOSE;	}	if (euc->interaction == SHOPPING_CART) 		euc->sc_id = euc->shopping_cart_data.sc_id;	else if (euc->interaction == BUY_REQUEST) 		euc->c_id = euc->buy_request_data.c_id;	/* reset sc_id after buy_confirm */	else if (euc->interaction == BUY_CONFIRM) 		euc->sc_id = UNKNOWN_SHOPPING_CART;//#ifdef DEBUG//	dump_interaction_output(euc);//#endif /* DEBUG */#endif /* PHASE2 */	return rc;}