コード例 #1
0
ファイル: iso_8583s.cpp プロジェクト: BaixiangLiu/ykt4sungard
/***********************************************************************
		module		:	[8583协议]
		function		:	[把buf中数据按定义好的格式解包到ISO_MSG变量m中]
  		return			:	[-1:异常
								其他:buf的长度]
		comment	:	[全局普通函数]
		machine		:	[无]
		language	:	[CHN]
 		keyword		:	[内部有MALLOC操作,用完需要函数iso8583_free进行释放]
		date			:	[11/08/10]
 		author		:	[chen-zhengkai]
************************************************************************/
int iso8583_unpack(ISO_MSG *m, const char *buf)
{
	const char* start = buf;
	int flds, i;
	char fmt[8];
	memset(fmt, 0, sizeof(fmt));

	//0域的操作
	if (m->fld[0].buf != NULL || s_isodef[0].fmt != FMT_FIXED) {	//异常处理
		MY_TRACE("flds = %d", 0);
		return -1;
	}
	m->fld[0].len = s_isodef[0].len;
	memset(m->fld[0].buf, 0x00, NUM);
	if (s_iCompress) {
		buf += BCD2ASC((char*)m->fld[0].buf, (unsigned char*)buf, m->fld[0].len, s_isodef[0].fmt);
	}
	else {
		memcpy(m->fld[0].buf, buf, m->fld[0].len);
		buf += m->fld[0].len;
	}

	//操作1域,位图域
#if ISO_FLDS==128
	if(buf[0] & 0x80) {		//128位版
		flds = 128;
	} 
	else {
		flds = 64;
	}
#else
	if( buf[0] & 0x80 ) {	//128位版
		MY_TRACE("flds = %d", 1);
		return -1;
	}
	flds = 64;
#endif
	m->fld[1].len = flds/8;		//64位8字节,128位16字节
	memset(m->fld[1].buf, 0x00, NUM);
	memcpy(m->fld[1].buf, buf, m->fld[1].len);
	buf += m->fld[1].len;	//偏移
	//2--64(128)域操作
	for (i = 2; i <= flds; i++) {
		if (BITGET(m->fld[1].buf, i)) {	//第i字段不为零
			//长度处理
			if ( s_isodef[i].fmt) {	//不定长
				if ( s_iCompress ) {	//需解压
					buf += BCD2INT(&(m->fld[i].len), (unsigned char*)buf, s_isodef[i].fmt, 0);
				}
				else {
					sprintf(fmt, "%%0%dd", s_isodef[i].fmt);		//格式化成 %0?d
					sscanf(buf, fmt, &(m->fld[i].len));		//把buf内容格式化成整数存入len
					buf += s_isodef[i].fmt;	//偏移
				}
				if (m->fld[i].len > s_isodef[i].len) {	//异常处理
					MY_TRACE("flds = %d", i);
					return -1;
				}
			}
			else {	//定长
				m->fld[i].len = s_isodef[i].len;
			}
			//内容处理
			memset(m->fld[i].buf, 0x00, NUM);
			switch (s_isodef[i].typ) {
				case TYP_BCD:
					if (s_iCompress) {
						buf += BCD2ASC((char*)m->fld[i].buf, (unsigned char*)buf, m->fld[i].len, s_isodef[i].fmt); 
						break;
					}
				case TYP_ASC:
				case TYP_BIN:
					memcpy(m->fld[i].buf, buf, m->fld[i].len);
					buf += m->fld[i].len;
					break;
				default:
					MY_TRACE("flds = %d", i);
					return -1;
			}
		}
	}
	return (buf-start);	//返回长度
}
コード例 #2
0
ファイル: iso_8583s.cpp プロジェクト: BaixiangLiu/ykt4sungard
/***********************************************************************
		module		:	[8583协议]
		function		:	[把ISO_MSG变量m中数据按定义好的格式组包到buf中]
  		return			:	[-1:异常
								其他:buf的长度]
		comment	:	[全局普通函数]
		machine		:	[无]
		language	:	[CHN]
 		keyword		:	[buf格式:0字段--1位图字段--(2-128)中有数据的字段......]
		date			:	[11/08/10]
 		author		:	[chen-zhengkai]
************************************************************************/
int iso8583_pack(const ISO_MSG *m, char *buf)
{
	char *start = buf;
	int flds, i;
	char fmt[8] = {0};
	char tmp[8] = {0};

	//0域操作
	if (m->fld[0].len != s_isodef[0].len || s_isodef[0].fmt != FMT_FIXED) {
		MY_TRACE("flds = %d", 0);
		return -1;
	}

	if (s_iCompress) {	//是否压缩数据,asc2bcd
		buf += ASC2BCD((unsigned char*)buf, (char*)m->fld[0].buf, s_isodef[0].len, s_isodef[0].fmt);
	}
	else {
		memcpy(buf, m->fld[0].buf, s_isodef[0].len);		//0字段(消息类型)操作
		buf += s_isodef[0].len;
	}

	//(1域)位图域操作
	if (m->fld[1].buf == NULL || s_isodef[1].len != 16) {
		MY_TRACE("flds = %d", 1);
		return -1;
	}
#if ISO_FLDS==128
	if ((m->fld[1].len == s_isodef[1].len) && (m->fld[1].buf[0] & 0x80)) {
		memcpy(buf, m->fld[1].buf, s_isodef[0].len);
		buf += s_isodef[1].len;
		flds = 128;
	}
	else {
		if ((m->fld[1].len == 8) && !(m->fld[1].buf[0] & 0x80)) {
			memcpy(buf, m->fld[1].buf, 8);
			buf += 8;
			flds = 64;
		}
		else {
			MY_TRACE("flds = %d", 1);
			return -1;
		}
	}
#else
	if ((m->fld[1].len != 8) || (m->fld[1].buf[0] & 0x80)) {	//不是64位版则返回
		MY_TRACE("flds = %d", 1);
		return -1;
	}
	memcpy(buf, m->fld[1].buf, m->fld[1].len);	//位图字段操作
	buf += m->fld[1].len;
	flds = 64;
#endif
	for (i = 2; i <= flds; i++) {
		if (BITGET(m->fld[1].buf, i)) {	//第i字段不为零
			if (m->fld[i].buf == NULL || m->fld[i].len <= 0 || m->fld[i].len > s_isodef[i].len) {	//异常情况
				MY_TRACE("flds = %d", i);
				return -1;
			}
			if (s_isodef[i].fmt) {  //不定长
				if (s_iCompress) {	//需要压缩
					sprintf(fmt, "%%0%dd", s_isodef[i].fmt);		//格式化成 %0?d
					sprintf(tmp, fmt, m->fld[i].len);		//最终格式化,  tmp里面存的是长度
					buf += ASC2BCD((unsigned char*)buf, tmp, s_isodef[i].fmt, 0);		//把长度转BCD压缩
				}
				else {	//无需压缩
					sprintf(fmt, "%%0%dd", s_isodef[i].fmt);	//格式化成 %0?d
					sprintf(buf, fmt, m->fld[i].len);	//最终格式化,  tmp里面存的是长度
					buf += s_isodef[i].fmt;		//把长度存入BUFF
				}
			}
			switch (s_isodef[i].typ) {	//确认类型,BCD,ASC,BIN
				case TYP_BCD:
					if (s_iCompress) {		//需要压缩
						buf += ASC2BCD((unsigned char*)buf, (char*)m->fld[i].buf, m->fld[i].len, s_isodef[i].fmt);
						break;
					}
				case TYP_ASC:
				case TYP_BIN:
					memcpy(buf, m->fld[i].buf, m->fld[i].len);
					buf += m->fld[i].len;
					break;
				default:
					MY_TRACE("flds = %d", i);
					return -1;
					break;
			}
		}
	}
	return (buf-start);		//返回总的buf长度
}
コード例 #3
0
ファイル: iso8583.cpp プロジェクト: nykma/ykt4sungard
/*
 * Using the definition d, unpack the content of buf into the ISO 
 * message struct m.
 * Returns 0. FIXME: Should be something different.
 */
int iso8583_unpack(ISO_MSG *m, const char *buf)
{
 const char *start = buf;
 int flds, i;
    char fmt[8];

 memset(fmt, 0, sizeof(fmt));

 /* Field 0 is mandatory and fixed length. */
 if (m->fld[0].buf != NULL || s_isodef[0].fmt != FMT_FIXED) {
  MY_TRACE("flds = %d", 0);
  return -1;
 }

 m->fld[0].len = s_isodef[0].len;
 m->fld[0].buf = (unsigned char *) malloc((m->fld[0].len) * sizeof(char));
 if(s_iCompress)
 {
  buf += BCD2ASC((char*)m->fld[0].buf,(const unsigned char*) buf, m->fld[0].len, s_isodef[0].fmt);
 }
 else
 {
  memcpy(m->fld[0].buf, buf, m->fld[0].len);
  buf += m->fld[0].len;
 }


 /*
  * First bit in the bitmap (field 1) defines if the message is 
  * extended or not.
  * 0: not exteded - i.e. only (some of) the fields 0 to 64 are 
  *    used
  * 1: extended - i.e. (some of) the fields 0 to 128 are used
  * I.e. if one or more of the fields 65 to 128 is used, the 
  * bit is 1.
  */
#if ISO_FLDS==128
 if(buf[0] & 0x80) {
  flds = 128;
 } else {
  flds = 64;
 }
#else /*ISO_FLDS==128*/
 if(buf[0] & 0x80) {
  MY_TRACE("flds = %d", 1);
  return -1;
 }
 flds = 64;
#endif /*ISO_FLDS==128*/

 m->fld[1].len = flds/8;
 m->fld[1].buf = (unsigned char *) calloc((m->fld[1].len), sizeof(char));
 memcpy(m->fld[1].buf, buf, m->fld[1].len);
 buf += m->fld[1].len;

 for (i = 2; i <= flds; i++) 
 {
  if (MY_BITGET(m->fld[1].buf, i)) 
  { /* i'th bit != 0 */
   if ( s_isodef[i].fmt)
   { /* Variable length */
    if(s_iCompress) 
    {
     buf += BCD2INT(&(m->fld[i].len),(const unsigned char*) buf, s_isodef[i].fmt, 0);
    }
    else
    {
     sprintf(fmt, "%%0%dd", s_isodef[i].fmt);
     sscanf(buf, fmt, &(m->fld[i].len));
     buf += s_isodef[i].fmt;     
    }    

    if (m->fld[i].len > s_isodef[i].len) {
     MY_TRACE("flds = %d", i);
     return -1;
    }
   }
   else
   {
    m->fld[i].len = s_isodef[i].len;
   }

   m->fld[i].buf = (unsigned char *) malloc((m->fld[i].len) * sizeof(char));
   
   switch (s_isodef[i].typ) {
   case TYP_BCD: /* Fallthrough */
    if(s_iCompress)
    {
     buf += BCD2ASC((char*)m->fld[i].buf,(const unsigned char*) buf, m->fld[i].len, s_isodef[i].fmt); 
     break;
    }
   case TYP_ASC:
   case TYP_BIN:
    memcpy(m->fld[i].buf, buf, m->fld[i].len);
    buf += m->fld[i].len;
    break;
   default:
    MY_TRACE("flds = %d", i);
    return -1;
    break;
   }
  }
 }

 return (buf-start);
}
コード例 #4
0
/*============================================================================
 * method which implements the Read service.
 *===========================================================================*/
OpcUa_StatusCode my_Read(
							OpcUa_Endpoint             a_hEndpoint,
							OpcUa_Handle               a_hContext,
							const OpcUa_RequestHeader* a_pRequestHeader,
							OpcUa_Double               a_nMaxAge,
							OpcUa_TimestampsToReturn   a_eTimestampsToReturn,
							OpcUa_Int32                a_nNoOfNodesToRead,
							const OpcUa_ReadValueId*   a_pNodesToRead,
							OpcUa_ResponseHeader*      a_pResponseHeader,
							OpcUa_Int32*               a_pNoOfResults,
							OpcUa_DataValue**          a_pResults,
							OpcUa_Int32*               a_pNoOfDiagnosticInfos,
							OpcUa_DiagnosticInfo**     a_pDiagnosticInfos)
{
	OpcUa_Int i,n;
	OpcUa_Void* p_Node;
	extern OpcUa_UInt32		securechannelId;
	extern OpcUa_UInt32		session_flag;
	extern OpcUa_Double		msec_counter;
	extern OpcUa_String*	p_user_name;

    OpcUa_InitializeStatus(OpcUa_Module_Server, "OpcUa_ServerApi_Read");

    /* validate arguments. */
    OpcUa_ReturnErrorIfArgumentNull(a_hEndpoint);
    OpcUa_ReturnErrorIfArgumentNull(a_hContext);
    OpcUa_ReturnErrorIfArgumentNull(a_pRequestHeader);
    OpcUa_ReferenceParameter(a_nMaxAge);
    OpcUa_ReferenceParameter(a_eTimestampsToReturn);
    OpcUa_ReturnErrorIfArrayArgumentNull(a_nNoOfNodesToRead, a_pNodesToRead);
    OpcUa_ReturnErrorIfArgumentNull(a_pResponseHeader);
    OpcUa_ReturnErrorIfArrayArgumentNull(a_pNoOfResults, a_pResults);
    OpcUa_ReturnErrorIfArrayArgumentNull(a_pNoOfDiagnosticInfos, a_pDiagnosticInfos);

	*a_pNoOfDiagnosticInfos=0;
	*a_pDiagnosticInfos=OpcUa_Null;

	RESET_SESSION_COUNTER

 #ifndef NO_DEBUGING_
	MY_TRACE("\n\n\nRREADSERVICE==============================================\n");
	if(p_user_name!=OpcUa_Null)
		MY_TRACE("\nUser:%s\n",OpcUa_String_GetRawString(p_user_name)); 
#endif /*_DEBUGING_*/
  

	if(OpcUa_IsBad(session_flag))
	{
		//teile client mit , dass Session geschlossen ist
#ifndef NO_DEBUGING_
		MY_TRACE("\nSession nicht aktiv\n"); 
#endif /*_DEBUGING_*/
		uStatus=OpcUa_BadSessionNotActivated;
		OpcUa_GotoError;
	}

	
	uStatus=check_authentication_token(a_pRequestHeader);
	if(OpcUa_IsBad(uStatus))
	{
#ifndef NO_DEBUGING_
		MY_TRACE("\nAuthentication Token ungültig.\n"); 
#endif /*_DEBUGING_*/
		OpcUa_GotoError;
	}

	*a_pResults=OpcUa_Alloc(a_nNoOfNodesToRead*sizeof(OpcUa_DataValue));
	OpcUa_GotoErrorIfAllocFailed((*a_pResults))
	

	for(n=0;n<a_nNoOfNodesToRead;n++)
	{
		OpcUa_DataValue_Initialize((*a_pResults)+n);
		((*a_pResults)+n)->StatusCode=OpcUa_BadAttributeIdInvalid;
		p_Node=search_for_node((a_pNodesToRead+n)->NodeId);
		if(p_Node!= OpcUa_Null)   //pruefe ob Knoten existiert
		{
			if(((a_pNodesToRead+n)->AttributeId)<=7 && ((a_pNodesToRead+n)->AttributeId)>=1)
			{
				if((a_pNodesToRead+n)->AttributeId==OpcUa_Attributes_NodeId)
				{
					((*a_pResults)+n)->Value.Value.NodeId=OpcUa_Memory_Alloc(sizeof(OpcUa_NodeId));
					if(((*a_pResults)+n)->Value.Value.NodeId !=OpcUa_Null)
					{
						OpcUa_NodeId_Initialize(((*a_pResults)+n)->Value.Value.NodeId);
						*(((*a_pResults)+n)->Value.Value.NodeId)=((_ObjectKnoten_*)p_Node)->BaseAttribute.NodeId; 
						fill_datatype_arraytype_in_my_Variant(((*a_pResults)+n),OpcUaId_NodeId, OpcUa_VariantArrayType_Scalar,0);
						((*a_pResults)+n)->StatusCode=OpcUa_Good;
					}
					else
					{
						((*a_pResults)+n)->StatusCode=OpcUa_BadOutOfMemory;
					}
				}
				if((a_pNodesToRead+n)->AttributeId==OpcUa_Attributes_NodeClass)
				{
					((*a_pResults)+n)->Value.Value.Int32=((_ObjectKnoten_*)p_Node)->BaseAttribute.NodeClass;
					fill_datatype_arraytype_in_my_Variant(((*a_pResults)+n),OpcUaId_Int32, OpcUa_VariantArrayType_Scalar,0);
					((*a_pResults)+n)->StatusCode=OpcUa_Good;
				}
				if((a_pNodesToRead+n)->AttributeId==OpcUa_Attributes_BrowseName)
				{
					((*a_pResults)+n)->Value.Value.QualifiedName=OpcUa_Memory_Alloc(sizeof(OpcUa_QualifiedName));
					if(((*a_pResults)+n)->Value.Value.QualifiedName!=OpcUa_Null)
					{
						OpcUa_QualifiedName_Initialize(((*a_pResults)+n)->Value.Value.QualifiedName);
						OpcUa_String_AttachCopy(&((*a_pResults)+n)->Value.Value.QualifiedName->Name,((_ObjectKnoten_*)p_Node)->BaseAttribute.BrowseName);
						((*a_pResults)+n)->Value.Value.QualifiedName->NamespaceIndex=((_ObjectKnoten_*)p_Node)->BaseAttribute.NodeId.NamespaceIndex;     
						fill_datatype_arraytype_in_my_Variant(((*a_pResults)+n),OpcUaId_QualifiedName, OpcUa_VariantArrayType_Scalar,0);
						((*a_pResults)+n)->StatusCode=OpcUa_Good;
					}
					else
					{
						((*a_pResults)+n)->StatusCode=OpcUa_BadOutOfMemory;
					}
				}
				if((a_pNodesToRead+n)->AttributeId==OpcUa_Attributes_DisplayName)
				{
					((*a_pResults)+n)->Value.Value.LocalizedText=OpcUa_Memory_Alloc(sizeof(OpcUa_LocalizedText));
					if(((*a_pResults)+n)->Value.Value.LocalizedText!=OpcUa_Null)
					{
						OpcUa_LocalizedText_Initialize(((*a_pResults)+n)->Value.Value.LocalizedText);
						OpcUa_String_AttachCopy(&((*a_pResults)+n)->Value.Value.LocalizedText->Text,((_ObjectKnoten_*)p_Node)->BaseAttribute.DisplayName);
						OpcUa_String_AttachCopy(&((*a_pResults)+n)->Value.Value.LocalizedText->Locale,"en");
						fill_datatype_arraytype_in_my_Variant(((*a_pResults)+n),OpcUaId_LocalizedText, OpcUa_VariantArrayType_Scalar,0);
						((*a_pResults)+n)->StatusCode=OpcUa_Good;
					}
					else
					{
						((*a_pResults)+n)->StatusCode=OpcUa_BadOutOfMemory;
					}

				}
				if(((a_pNodesToRead+n)->AttributeId==OpcUa_Attributes_Description || (a_pNodesToRead+n)->AttributeId==OpcUa_Attributes_WriteMask) || (a_pNodesToRead+n)->AttributeId==OpcUa_Attributes_UserWriteMask)
				{
						((*a_pResults)+n)->StatusCode=OpcUa_BadNotReadable;
				}
			}
			else
			{
				switch((((_ObjectKnoten_*)p_Node)->BaseAttribute.NodeClass))
				{
				case OpcUa_NodeClass_Variable:
					{
						if((a_pNodesToRead+n)->AttributeId<=20 && (a_pNodesToRead+n)->AttributeId>=13)
						{
							if((a_pNodesToRead+n)->AttributeId==OpcUa_Attributes_Value)
							{
								 ((*a_pResults)+n)->StatusCode=fill_Variant_for_value_attribute((_VariableKnoten_*)p_Node, OpcUa_Null,((*a_pResults)+n));
								if(a_eTimestampsToReturn!=OpcUa_TimestampsToReturn_Neither)
								{
									uStatus=assigne_Timestamp(((*a_pResults)+n),a_eTimestampsToReturn);
									if(OpcUa_IsBad(uStatus))
									{
										((*a_pResults)+n)->StatusCode=OpcUa_BadInternalError;
										uStatus=OpcUa_Good;
									}
								}
							}
							if((a_pNodesToRead+n)->AttributeId==OpcUa_Attributes_DataType)
							{
								((*a_pResults)+n)->Value.Value.NodeId=OpcUa_Memory_Alloc(sizeof(OpcUa_NodeId));
								if(((*a_pResults)+n)->Value.Value.NodeId!=OpcUa_Null)
								{
									OpcUa_NodeId_Initialize(((*a_pResults)+n)->Value.Value.NodeId);
									*(((*a_pResults+n)->Value.Value.NodeId))=((_VariableKnoten_*)p_Node)->DataType;
									fill_datatype_arraytype_in_my_Variant(((*a_pResults)+n),OpcUaId_NodeId, OpcUa_VariantArrayType_Scalar,0);
									((*a_pResults)+n)->StatusCode=OpcUa_Good;
								}
								else
								{
									((*a_pResults)+n)->StatusCode=OpcUa_BadOutOfMemory;
								}
							}
							if((a_pNodesToRead+n)->AttributeId==OpcUa_Attributes_ValueRank)
							{
								((*a_pResults)+n)->Value.Value.Int32=((_VariableKnoten_*)p_Node)->ValueRank;
								fill_datatype_arraytype_in_my_Variant(((*a_pResults)+n),OpcUaId_Int32, OpcUa_VariantArrayType_Scalar,0);
								((*a_pResults)+n)->StatusCode=OpcUa_Good;
							}
							if((a_pNodesToRead+n)->AttributeId==OpcUa_Attributes_ArrayDimensions)
							{
								
								((*a_pResults)+n)->Value.Value.UInt32=(((_VariableKnoten_*)p_Node)->ArrayDimensions);
								fill_datatype_arraytype_in_my_Variant(((*a_pResults)+n),OpcUaId_UInt32, OpcUa_VariantArrayType_Scalar,0);
								((*a_pResults)+n)->StatusCode=OpcUa_Good;

							}
							if((a_pNodesToRead+n)->AttributeId==OpcUa_Attributes_AccessLevel)
							{
								((*a_pResults)+n)->Value.Value.Byte=((_VariableKnoten_*)p_Node)->AccessLevel;
								fill_datatype_arraytype_in_my_Variant(((*a_pResults)+n),OpcUaId_Byte, OpcUa_VariantArrayType_Scalar,0);
								((*a_pResults)+n)->StatusCode=OpcUa_Good;
							}
							if((a_pNodesToRead+n)->AttributeId==OpcUa_Attributes_UserAccessLevel)
							{
								((*a_pResults)+n)->Value.Value.Byte=((_VariableKnoten_*)p_Node)->UserAccessLevel;
								fill_datatype_arraytype_in_my_Variant(((*a_pResults)+n),OpcUaId_Byte, OpcUa_VariantArrayType_Scalar,0);
								((*a_pResults)+n)->StatusCode=OpcUa_Good;
							}
							if((a_pNodesToRead+n)->AttributeId==OpcUa_Attributes_MinimumSamplingInterval)
							{
								((*a_pResults)+n)->Value.Value.Double=OpcUa_MinimumSamplingIntervals_Indeterminate;
								fill_datatype_arraytype_in_my_Variant(((*a_pResults)+n),OpcUaId_Double, OpcUa_VariantArrayType_Scalar,0);
								((*a_pResults)+n)->StatusCode=OpcUa_Good;
							}
							if((a_pNodesToRead+n)->AttributeId==OpcUa_Attributes_Historizing)
							{
								((*a_pResults)+n)->Value.Value.Boolean=((_VariableKnoten_*)p_Node)->Historizing;
								fill_datatype_arraytype_in_my_Variant(((*a_pResults)+n),OpcUaId_Boolean, OpcUa_VariantArrayType_Scalar,0);
								((*a_pResults)+n)->StatusCode=OpcUa_Good;
							}
						}
						break;
					}
				case OpcUa_NodeClass_VariableType:
					{
						if(((a_pNodesToRead+n)->AttributeId<=16 && (a_pNodesToRead+n)->AttributeId>=13) ||((a_pNodesToRead+n)->AttributeId==8))
						{
							if((a_pNodesToRead+n)->AttributeId==OpcUa_Attributes_Value)
							{
								 ((*a_pResults)+n)->StatusCode=fill_Variant_for_value_attribute((_VariableKnoten_*)p_Node, OpcUa_Null,((*a_pResults)+n));
								if(a_eTimestampsToReturn!=OpcUa_TimestampsToReturn_Neither)
								{
									uStatus=assigne_Timestamp(((*a_pResults)+n),a_eTimestampsToReturn);
									if(OpcUa_IsBad(uStatus))
									{
										((*a_pResults)+n)->StatusCode=OpcUa_BadInternalError;
										uStatus=OpcUa_Good;
									}
								}
							}
							if((a_pNodesToRead+n)->AttributeId==OpcUa_Attributes_DataType)
							{
								((*a_pResults)+n)->Value.Value.NodeId=OpcUa_Memory_Alloc(sizeof(OpcUa_NodeId));
								if(((*a_pResults)+n)->Value.Value.NodeId!=OpcUa_Null)
								{
									OpcUa_NodeId_Initialize(((*a_pResults)+n)->Value.Value.NodeId);
									*((*a_pResults)+n)->Value.Value.NodeId=((_VariableTypeKnoten_*)p_Node)->DataType;
									fill_datatype_arraytype_in_my_Variant(((*a_pResults)+n),OpcUaId_NodeId, OpcUa_VariantArrayType_Scalar,0);
									((*a_pResults)+n)->StatusCode=OpcUa_Good;
								}
								else
								{
									((*a_pResults)+n)->StatusCode=OpcUa_BadOutOfMemory;
								}
							}
							if((a_pNodesToRead+n)->AttributeId==OpcUa_Attributes_ArrayDimensions)
							{
								((*a_pResults)+n)->Value.Value.UInt32=((_VariableTypeKnoten_*)p_Node)->ArrayDimensions; 
								fill_datatype_arraytype_in_my_Variant(((*a_pResults)+n),OpcUaId_UInt32, OpcUa_VariantArrayType_Scalar,0);
								((*a_pResults)+n)->StatusCode=OpcUa_Good;
							}
							if((a_pNodesToRead+n)->AttributeId==OpcUa_Attributes_IsAbstract)
							{
								((*a_pResults)+n)->Value.Value.Boolean=((_VariableTypeKnoten_*)p_Node)->IsAbstract;
								fill_datatype_arraytype_in_my_Variant(((*a_pResults)+n),OpcUaId_Boolean, OpcUa_VariantArrayType_Scalar,0);
								((*a_pResults)+n)->StatusCode=OpcUa_Good;
							}
							
						}
						break;
					}
				case OpcUa_NodeClass_Object:
					{
						if((a_pNodesToRead+n)->AttributeId==OpcUa_Attributes_EventNotifier)
						{
							((*a_pResults)+n)->Value.Value.Byte=((_ObjectKnoten_*)p_Node)->EventNotifier;
							fill_datatype_arraytype_in_my_Variant(((*a_pResults)+n),OpcUaId_Byte, OpcUa_VariantArrayType_Scalar,0);
							((*a_pResults)+n)->StatusCode=OpcUa_Good;
						}
						break;
					}
					
				case OpcUa_NodeClass_ObjectType:
					{
						if((a_pNodesToRead+n)->AttributeId==OpcUa_Attributes_IsAbstract)
						{
							((*a_pResults)+n)->Value.Value.Boolean=((_ObjectTypeKnoten_*)p_Node)->IsAbstract;
							fill_datatype_arraytype_in_my_Variant(((*a_pResults)+n),OpcUaId_Boolean, OpcUa_VariantArrayType_Scalar,0);
							((*a_pResults)+n)->StatusCode=OpcUa_Good;
						}
						break;
					}
					
				case OpcUa_NodeClass_DataType:
					{

						if((a_pNodesToRead+n)->AttributeId==OpcUa_Attributes_IsAbstract)
						{
							((*a_pResults)+n)->Value.Value.Boolean=((_DataTypeKnoten_*)p_Node)->IsAbstract;
							fill_datatype_arraytype_in_my_Variant(((*a_pResults)+n),OpcUaId_Boolean, OpcUa_VariantArrayType_Scalar,0);
							((*a_pResults)+n)->StatusCode=OpcUa_Good;
						}
						break;
					}
				
				case OpcUa_NodeClass_ReferenceType:
					{
						if((a_pNodesToRead+n)->AttributeId<=10 && (a_pNodesToRead+n)->AttributeId>=8)
						{
							if((a_pNodesToRead+n)->AttributeId==OpcUa_Attributes_IsAbstract)
							{
								((*a_pResults)+n)->Value.Value.Boolean=((_ReferenceTypeKnoten_*)p_Node)->IsAbstract;
								fill_datatype_arraytype_in_my_Variant(((*a_pResults)+n),OpcUaId_Boolean, OpcUa_VariantArrayType_Scalar,0);
								((*a_pResults)+n)->StatusCode=OpcUa_Good;
							}
							if((a_pNodesToRead+n)->AttributeId==OpcUa_Attributes_Symmetric)
							{
								((*a_pResults)+n)->Value.Value.Boolean=((_ReferenceTypeKnoten_*)p_Node)->Symmetric;
								fill_datatype_arraytype_in_my_Variant(((*a_pResults)+n),OpcUaId_Boolean, OpcUa_VariantArrayType_Scalar,0);
								((*a_pResults)+n)->StatusCode=OpcUa_Good;
							}
							if((a_pNodesToRead+n)->AttributeId==OpcUa_Attributes_InverseName)
							{
								((*a_pResults)+n)->Value.Value.LocalizedText=OpcUa_Memory_Alloc(sizeof(OpcUa_LocalizedText));
								if(((*a_pResults)+n)->Value.Value.NodeId!=OpcUa_Null)
								{
									OpcUa_LocalizedText_Initialize(((*a_pResults)+n)->Value.Value.LocalizedText);
									OpcUa_String_AttachCopy(&((*a_pResults)+n)->Value.Value.LocalizedText->Text, ((_ReferenceTypeKnoten_*)p_Node)->InverseName_text);
									OpcUa_String_AttachCopy(&((*a_pResults)+n)->Value.Value.LocalizedText->Locale, ((_ReferenceTypeKnoten_*)p_Node)->InverseName_locale);
									fill_datatype_arraytype_in_my_Variant(((*a_pResults)+n),OpcUaId_LocalizedText, OpcUa_VariantArrayType_Scalar,0);
									((*a_pResults)+n)->StatusCode=OpcUa_Good;
								}
								else
								{
									((*a_pResults)+n)->StatusCode=OpcUa_BadOutOfMemory;
								}
							}
						}
						break;
					}
				default:
					break;
					
				
				}
			}
			
		
		}
		else
		{
			((*a_pResults)+n)->StatusCode=OpcUa_BadNodeIdUnknown;
		}
		
	}
	
	

	*a_pNoOfResults=a_nNoOfNodesToRead;

#ifndef NO_DEBUGING_
	MY_TRACE("\nanzahl der nodes :%d\n",a_nNoOfNodesToRead);
	for(i=0;i<a_nNoOfNodesToRead;i++)
	{
		MY_TRACE("\n|%d|, |%d| attributeId:%u\n",(a_pNodesToRead+i)->NodeId.NamespaceIndex,(a_pNodesToRead+i)->NodeId.Identifier.Numeric,(a_pNodesToRead+i)->AttributeId);
		
	}
#endif /*_DEBUGING_*/


	
	uStatus = response_header_ausfuellen(a_pResponseHeader,a_pRequestHeader,uStatus);
	if(OpcUa_IsBad(uStatus))
	{
       a_pResponseHeader->ServiceResult=OpcUa_BadInternalError;
	}
#ifndef NO_DEBUGING_
	MY_TRACE("\nSERVICE===ENDE============================================\n\n\n"); 
#endif /*_DEBUGING_*/

	RESET_SESSION_COUNTER

    OpcUa_ReturnStatusCode;
    OpcUa_BeginErrorHandling;

    
	uStatus = response_header_ausfuellen(a_pResponseHeader,a_pRequestHeader,uStatus);
	if(OpcUa_IsBad(uStatus))
	{
       a_pResponseHeader->ServiceResult=OpcUa_BadInternalError;
	}
#ifndef NO_DEBUGING_
	MY_TRACE("\nSERVICEENDE (IM SERVICE SIND FEHLER AUFGETRETTEN)===========\n\n\n"); 
#endif /*_DEBUGING_*/
	RESET_SESSION_COUNTER
    OpcUa_FinishErrorHandling;
}
コード例 #5
0
ファイル: iso8583.cpp プロジェクト: nykma/ykt4sungard
/*
 * Using the definition d, pack the content of the ISO message m into 
 * buf. NOTE: buf must be large enough to contain the packed message.
 * Returns the length of the data written to buf.
 */
int iso8583_pack(const ISO_MSG *m, char *buf)
{
 char *start = buf;
 int flds, i;
 char fmt[8], tmp[8]={0};

 /* Field 0 is mandatory and fixed length. */
 if (m->fld[0].len != s_isodef[0].len || s_isodef[0].fmt != FMT_FIXED) {
  MY_TRACE("flds = %d", 0);
  return -1;
 }

 if (s_iCompress) 
 {
  buf += ASC2BCD((unsigned char*)buf, (const char*)m->fld[0].buf, s_isodef[0].len, s_isodef[0].fmt);
 }
 else
 {
  memcpy(buf, m->fld[0].buf, s_isodef[0].len);
  buf += s_isodef[0].len;  
 }

 /*
  * The bitmap contains either 64 or 128 fields - flds is the 
  * number of allowed fields, i.e. either 64 or 128.
  */
 if (m->fld[1].buf == NULL || s_isodef[1].len != 16) {
  MY_TRACE("flds = %d", 1);
  return -1;
 }
 
#if ISO_FLDS==128
 if ((m->fld[1].len == s_isodef[1].len) && (m->fld[1].buf[0] & 0x80))
 {
  memcpy(buf, m->fld[1].buf, s_isodef[0].len);
  buf += s_isodef[1].len;
  flds = 128;
 }
 else
 {
  if ((m->fld[1].len == 8) && !(m->fld[1].buf[0] & 0x80))
  {
   memcpy(buf, m->fld[1].buf, 8);
   buf += 8;
   flds = 64;
  }
  else
  {
   MY_TRACE("flds = %d", 1);
   return -1;
  }
 }
#else /*ISO_FLDS==128*/
 if ((m->fld[1].len != 8) || (m->fld[1].buf[0] & 0x80)) {
  MY_TRACE("flds = %d", 1);
  return -1;
 }
 
 memcpy(buf, m->fld[1].buf, m->fld[1].len);
 buf += m->fld[1].len;
 flds = 64;
#endif /*ISO_FLDS==128*/

 for (i = 2; i <= flds; i++) 
 {
  if (MY_BITGET(m->fld[1].buf, i)) 
  { /* i'th bit != 0 */
   if (m->fld[i].buf == NULL || m->fld[i].len <= 0 || m->fld[i].len > s_isodef[i].len)
   {
    MY_TRACE("flds = %d", i);
    return -1;
   }

   if (s_isodef[i].fmt) 
   { /* Variable length */
    if (s_iCompress)
    {
     sprintf(fmt, "%%0%dd", s_isodef[i].fmt);
     sprintf(tmp, fmt, m->fld[i].len);
     buf += ASC2BCD((unsigned char*)buf, tmp, s_isodef[i].fmt, 0);
    }
    else
    {
     sprintf(fmt, "%%0%dd", s_isodef[i].fmt);
     sprintf(buf, fmt, m->fld[i].len);
     buf += s_isodef[i].fmt;
    }   
   }

   switch (s_isodef[i].typ) {
   case TYP_BCD: /* Fallthrough */
    if (s_iCompress)
    {
     buf += ASC2BCD((unsigned char*)buf,(const char*) m->fld[i].buf, m->fld[i].len, s_isodef[i].fmt); 
     break;
    }
   case TYP_ASC:
   case TYP_BIN:
    memcpy(buf, m->fld[i].buf, m->fld[i].len);
    buf += m->fld[i].len;
    break;
   default:
    MY_TRACE("flds = %d", i);
    return -1;
    break;
   }
     }
 }

 return (buf-start);
}