int socket_receiv_data(FOURD *cnx,FOURD_RESULT *state)
{
	int iResult=0;
	int offset=0;
	int len=0;
	int end_row=0;
	unsigned int nbCol=state->row_type.nbColumn;
	unsigned int nbRow=state->row_count_sent;
	unsigned int r,c;
	FOURD_TYPE *colType=NULL;
	FOURD_ELEMENT *pElmt=NULL;
	char status_code=0;
	int elmt_size=0;
	int elmts_offset=0;
	Printf("---Debut de socket_receiv_data\n");
	colType=calloc(nbCol,sizeof(FOURD_TYPE));
	//bufferize Column type
	for(c=0;c<state->row_type.nbColumn;c++)
		colType[c]=state->row_type.Column[c].type;
	Printf("nbCol*nbRow:%d\n",nbCol*nbRow);
	/* allocate nbElmt in state->elmt */
	state->elmt=calloc(nbCol*nbRow,sizeof(FOURD_ELEMENT));
	
	Printf("Debut de socket_receiv_data\n");
	Printf("state->row_count:%d\t\tstate->row_count_sent:%d\n",state->row_count,state->row_count_sent);
	Printf("NbRow to read: %d\n",nbRow);
	/* read all row */
	for(r=0;r<nbRow;r++)
	{
		/* read status_code and row_id */
		if(state->updateability)  /* rowId is send only if row updateablisity */
		{
			int row_id=0;
			status_code=0;
			iResult = frecv(cnx->socket,&status_code,sizeof(status_code), 0);
			//Printf("status_code for row:0x%X\n",status_code);
			len+=iResult;
			switch(status_code)
			{
			case '0':
				break;
			case '1':
				/* pElmt->elmt=calloc(vk_sizeof(colType[0]),1); */
				iResult = frecv(cnx->socket,(char*)&row_id,sizeof(row_id), 0);
				/* Printf("row_id:%d\n",row_id); */
				len+=iResult;
				break;
			case '2':
				Printferr("Error during reading data\n");
				iResult = frecv(cnx->socket,(char*)&(state->error_code),sizeof(state->error_code), 0);
				len+=iResult;
				return 1;	/* return on error */
				break;
			default:
				Printferr("Status code 0x%X not supported in data at row %d column %d\n",status_code,(elmts_offset-c+1)/nbCol+1,c+1);
				break;
			}
		}
		else {
			Printf("Not read rowid\n");
		}
		/* read all columns */
		for(c=0;c<nbCol;c++,elmts_offset++)
		{
			pElmt=&(state->elmt[elmts_offset]);
			pElmt->type=colType[c];

			//read column status code
			status_code=0;
			iResult = frecv(cnx->socket,&status_code,1, 0);
			Printf("status: %2X\n",status_code);
			len+=iResult;
			switch(status_code)
			{
			case '2'://error
				Printferr("Error during reading data\n");
				iResult = frecv(cnx->socket,(char*)&(state->error_code),sizeof(state->error_code), 0);
				len+=iResult;
				return 1;//on sort en erreur
				break;
			case '0'://null value
				Printf("Read null value\n");
				pElmt->null=1;
				break;
			case '1'://value
				pElmt->null=0;
				switch(colType[c])
				{
				case VK_BOOLEAN:
				case VK_BYTE:
				case VK_WORD:
				case VK_LONG:
				case VK_LONG8:
				case VK_REAL:
				case VK_DURATION:
					pElmt->pValue=calloc(1,vk_sizeof(colType[c]));
					iResult = frecv(cnx->socket,(pElmt->pValue),vk_sizeof(colType[c]), 0);
					len+=iResult;
					//Printf("Long: %d\n",*((int*)pElmt->pValue));
					break;
				case VK_TIMESTAMP:
					{
						FOURD_TIMESTAMP *tmp;
						tmp=calloc(1,sizeof(FOURD_TIMESTAMP));
						pElmt->pValue=tmp;
						iResult = frecv(cnx->socket,(char*)&(tmp->year),sizeof(short), 0);
						Printf("year: %04X",tmp->year);
						len+=iResult;
						iResult = frecv(cnx->socket,&(tmp->mounth),sizeof(char), 0);
						Printf("    mounth: %02X",tmp->mounth);
						len+=iResult;
						iResult = frecv(cnx->socket,&(tmp->day),sizeof(char), 0);
						Printf("    day: %02X",tmp->day);
						len+=iResult;
						iResult = frecv(cnx->socket,(char*)&(tmp->milli),sizeof(unsigned int), 0);
						Printf("    milli: %08X\n",tmp->milli);
						len+=iResult;
					}
					break;
				case VK_FLOAT:
					{
						//int exp;char sign;int data_length;void* data;
						FOURD_FLOAT *tmp;
						tmp=calloc(1,sizeof(FOURD_FLOAT));
						pElmt->pValue=tmp;

						iResult = frecv(cnx->socket,(char*)&(tmp->exp),sizeof(int), 0);
						len+=iResult;
						iResult = frecv(cnx->socket,&(tmp->sign),sizeof(char), 0);
						len+=iResult;
						iResult = frecv(cnx->socket,(char*)&(tmp->data_length),sizeof(int), 0);
						len+=iResult;
						iResult = frecv(cnx->socket,(tmp->data),tmp->data_length, 0);
						len+=iResult;

						Printferr("Float not supported\n");
					}
					break;
				case VK_STRING:
					{
						int data_length=0;
						FOURD_STRING *str;
						//read negative value of length of string
						str=calloc(1,sizeof(FOURD_STRING));
						pElmt->pValue=str;					
						iResult = frecv(cnx->socket,(char*)&data_length,4, 0);
						len+=iResult;
						Printf("String length: %08X\n",data_length);
						data_length=-data_length;
						str->length=data_length;
						str->data=calloc(data_length*2+2,1);
						if(data_length==0){	//correct read for empty string  
							str->data[0]=0;
							str->data[1]=0;
						}
						else {
							iResult = frecv(cnx->socket,(str->data),(data_length*2), 0);
							str->data[data_length*2]=0;
							str->data[data_length*2+1]=0;
							len+=iResult;
						}
						/*
						{
							int length=0;
							char *chaine=NULL;
							chaine=base64_encode((unsigned char*)str->data,data_length*2,&length);
							Printf("Chaine: %s\n",chaine);
							free(chaine);
						}*/
					}
					break;
				case VK_IMAGE:
					//Printferr("Image-Type not supported\n");
					//break;
				case VK_BLOB:
					{
						int data_length=0;
						FOURD_BLOB *blob;
						//read negative value of length of string
						blob=calloc(1,sizeof(FOURD_BLOB));
						pElmt->pValue=blob;
						iResult = frecv(cnx->socket,(char*)&data_length,4, 0);
						Printf("Blob length: %08X\n",data_length);
						len+=iResult;
						if(data_length==0){
							blob->length=0;
							blob->data=NULL;
							pElmt->null=1;
						}else{
							blob->length=data_length;
							blob->data=calloc(data_length,1);
							iResult = frecv(cnx->socket,blob->data,data_length, 0);
							len+=iResult;
						}
						//Printf("Blob: %d Bytes\n",data_length);
					}
					//Printferr("Blob not supported\n");
					break;
				default:
					Printferr("Type not supported (%s) at row %d column %d\n",stringFromType(colType[c]),(elmts_offset-c+1)/nbCol+1,c+1);
					break;
				}
				break;
			default:
				Printferr("Status code 0x%X not supported in data at row %d column %d\n",status_code,(elmts_offset-c+1)/nbCol+1,c+1);
				break;
			}
		}
	}
	Printf("---Fin de socket_receiv_data\n");
	return 0;
}
Exemple #2
0
QString XmltvCrewMember::display() const
{
    return QString("%1 (%2)").arg(name(), stringFromType(type()));
}