/*
 * Processes a response from a channel.  This consists of
 * performing a high level decode of the message and then
 * calling the applicable specific function for further
 * processing.
 * chnl - The channel of the response
 * buffer - The message buffer containing the response
 */
static RsslRet processResponse(RsslChannel* chnl, RsslBuffer* buffer)
{
	RsslRet ret = 0;
	RsslMsg msg = RSSL_INIT_MSG;
	RsslDecodeIterator dIter;
	RsslLoginResponseInfo *loginRespInfo = NULL;
	
	/* clear decode iterator */
	rsslClearDecodeIterator(&dIter);
	
	/* set version info */
	rsslSetDecodeIteratorRWFVersion(&dIter, chnl->majorVersion, chnl->minorVersion);

	if((ret = rsslSetDecodeIteratorBuffer(&dIter, buffer)) != RSSL_RET_SUCCESS)
	{
		printf("\nrsslSetDecodeIteratorBuffer() failed with return code: %d\n", ret);
		return RSSL_RET_FAILURE;
	}
	ret = rsslDecodeMsg(&dIter, &msg);				
	if (ret != RSSL_RET_SUCCESS)
	{
		printf("\nrsslDecodeMsg(): Error %d on SessionData fd="SOCKET_PRINT_TYPE" Size %d \n", ret, chnl->socketId, buffer->length);	
		return RSSL_RET_FAILURE;
	}

	switch ( msg.msgBase.domainType )
	{
		case RSSL_DMT_LOGIN:
			if (processLoginResponse(chnl, &msg, &dIter) != RSSL_RET_SUCCESS)
			{
				if (isLoginStreamClosed())
				{
					return RSSL_RET_FAILURE;
				}
				else if (isLoginStreamClosedRecoverable())
				{
					recoverConnection();
				}
				else if (isLoginStreamSuspect())
				{
					loginRespInfo = getLoginResponseInfo();
					/* if not single open provider, close source directory stream and item streams */
					if (!loginRespInfo->SingleOpen)
					{
						if (closeSourceDirectoryStream(rsslConsumerChannel) != RSSL_RET_SUCCESS)
							return RSSL_RET_FAILURE;

						if (closeSymbolListStream(rsslConsumerChannel) != RSSL_RET_SUCCESS)
							return RSSL_RET_FAILURE;

						if (closeYieldCurveItemStreams(rsslConsumerChannel) != RSSL_RET_SUCCESS)
							return RSSL_RET_FAILURE;

						if (closeMarketPriceItemStreams(rsslConsumerChannel) != RSSL_RET_SUCCESS)
							return RSSL_RET_FAILURE;

						if (closeMarketByOrderItemStreams(rsslConsumerChannel) != RSSL_RET_SUCCESS)
							return RSSL_RET_FAILURE;

						if (closeMarketByPriceItemStreams(rsslConsumerChannel) != RSSL_RET_SUCCESS)
							return RSSL_RET_FAILURE;
					}
					isInLoginSuspectState = RSSL_TRUE;
				}
			}
			else
			{
				if (isInLoginSuspectState)
				{
					isInLoginSuspectState = RSSL_FALSE;
				}
			}
			break;
		case RSSL_DMT_SOURCE:
			if (processSourceDirectoryResponse(chnl, &msg, &dIter) != RSSL_RET_SUCCESS)
				return RSSL_RET_FAILURE;

			/* if we have loaded the dictionaries, now that we have the directory, set up posting if its enabled */
			if ((isFieldDictionaryLoaded() || isEnumTypeDictionaryLoaded()) && ((onPostEnabled || offPostEnabled) && !postInit))
			{
				/* Initialize Post Processing after sending the login request message */
				/* ensure that provider supports posting - if not, disable posting */
				RsslLoginResponseInfo* loginInfo = getLoginResponseInfo();
					
				if (loginInfo->SupportOMMPost == RSSL_TRUE)
				{
					/* This sets up our basic timing so post messages will be sent periodically */
					initPostHandler();
					/* posting has been initialized */
					postInit = RSSL_TRUE;
				}
				else
				{
					/* provider does not support posting, disable it */
					onPostEnabled = RSSL_FALSE;
					offPostEnabled = RSSL_FALSE;
					disableOnstreamPost();
					disableOffstreamPost();
					printf("\nConnected Provider does not support OMM Posting.  Disabling Post functionality.\n");
				}
			}

			break;
		case RSSL_DMT_DICTIONARY:
			if (processDictionaryResponse(chnl, &msg, &dIter) != RSSL_RET_SUCCESS)
				return RSSL_RET_FAILURE;

			/* Now that we have downloaded dictionaries and directory set up posting if its enabled */
			if ((onPostEnabled || offPostEnabled) && !postInit)
			{
				/* Initialize Post Processing after sending the login request message */
				/* ensure that provider supports posting - if not, disable posting */
				RsslLoginResponseInfo* loginInfo = getLoginResponseInfo();
					
				if (loginInfo->SupportOMMPost == RSSL_TRUE)
				{
					/* This sets up our basic timing so post messages will be sent periodically */
					initPostHandler();
					/* posting has been initialized */
					postInit = RSSL_TRUE;
				}
				else
				{
					/* provider does not support posting, disable it */
					onPostEnabled = RSSL_FALSE;
					offPostEnabled = RSSL_FALSE;
					disableOnstreamPost();
					disableOffstreamPost();
					printf("\nConnected Provider does not support OMM Posting.  Disabling Post functionality.\n");
				}
			}

			break;
		case RSSL_DMT_MARKET_PRICE:
			if (!isInLoginSuspectState)
			{
				if (processMarketPriceResponse(chnl, &msg, &dIter) != RSSL_RET_SUCCESS)
					return RSSL_RET_FAILURE;
			}
			break;
		case RSSL_DMT_MARKET_BY_ORDER:
			if (!isInLoginSuspectState)
			{
				if (processMarketByOrderResponse(chnl, &msg, &dIter) != RSSL_RET_SUCCESS)
					return RSSL_RET_FAILURE;
			}
			break;
		case RSSL_DMT_MARKET_BY_PRICE:
			if (!isInLoginSuspectState)
			{
				if (processMarketByPriceResponse(chnl, &msg, &dIter)  != RSSL_RET_SUCCESS)
					return RSSL_RET_FAILURE;
			}
			break;
		case RSSL_DMT_YIELD_CURVE:
			if(!isInLoginSuspectState)
			{
				if (processYieldCurveResponse(chnl, &msg, &dIter) != RSSL_RET_SUCCESS)
					return RSSL_RET_FAILURE;
			}
			break;
		case RSSL_DMT_SYMBOL_LIST:
			if(!isInLoginSuspectState)
			{
				if (processSymbolListResponse(&msg, &dIter) != RSSL_RET_SUCCESS)
					return RSSL_RET_FAILURE;
			}
			break;
		default:
			printf("Unhandled Domain Type: %d\n", msg.msgBase.domainType);
			break;
	}

	return RSSL_RET_SUCCESS;
}
Example #2
0
void forwardLoginDetails(){
	char url[600] = "";
	char domain[100] = "";
	char rsp[10240] = "";
	char err_msg[200] = "";
	char socketBody[2048] = "";

	//char formatted_num[15]="";
	char sample_rsp[200]="";
	unsigned char keyPressed;
	uchar serial_num[32] = "";

	APP_PARA    stPara;
	ACTIVE_NETWORK network;
	SERVER_IP ip;
	SERVER_RESPONSE sResp;

	int iFile=0,iRet=0;

	memset(&network, 0, sizeof(network));
	memset(&stPara, 0, sizeof(stPara));
	memset(&ip, 0, sizeof(ip));
	memset(&sResp, 0, sizeof(sResp));

	iFile = open("network", O_RDWR|O_CREATE);
	iRet = read(iFile, (uchar *)&network, sizeof(network));

	if(iRet==0){
		strcpy(err_msg,"Please select \nSIM and network");
		keyPressed = show_msg(err_msg);
		return;
	}
	
	loadPreferredSettings(network.szSim,network.szNetworkFilename);

	iFile = open("sim_para", O_RDWR|O_CREATE);
    iRet = read(iFile, (uchar *)&stPara, sizeof(stPara));
	if(iRet==0){
		sprintf(err_msg,"%s %s","Please configure\nsettings for\n",network.szNetworkFilename);
		keyPressed = show_msg(err_msg);
		return;
	}

	iFile = open("ip_add", O_RDWR|O_CREATE);
    iRet = read(iFile, (uchar *)&ip, sizeof(ip));
	if(iRet==0){
		sprintf(err_msg,"%s","IP address has\nnot been set");
		keyPressed = show_msg(err_msg);
		return;
	}
	

	//reads the device's serial number
	ReadSN(serial_num);


	//we build up the socket body	
	sprintf(url,"/myauthserver/login?username=%s&password=%s&serialNumber=%s","user1","user2",serial_num);


	strcpy(socketBody,"GET ");
	strcat(socketBody,url);

	strcat(socketBody," HTTP/1.1\r\n");
	strcat(socketBody,"Host: ");
	strcat(socketBody,ip.szIp);
	strcat(socketBody,"\r\n");
	strcat(socketBody,"User-Agent: SMSGH_PAX_httplib\r\n");
	strcat(socketBody,"Connection: keep-alive\r\n");
	strcat(socketBody,"Cache-Control: no-cache\r\n");
	strcat(socketBody,"Accept: */*\r\n");
	strcat(socketBody,"\r\n");

	ScrCls();
	ScrGotoxy(0, 0);

	ScrAttrSet(0);
		
	Lcdprintf("Processing...\nplease wait...");

	if(dwnld_string(ip.szIp,socketBody,rsp,err_msg,stPara)<0){ //todo: check for each int returned from method, whether -1,-2, etc


		kbflush();

		
		keyPressed = show_msg(err_msg);
		

		
	}
	else{
		
		sResp = parse_http_headers(rsp);
	
		processLoginResponse(sResp);
	}
	
}