📄 iso8583.cpp
字号:
memmove((PBYTE)szValue, // Destiny
(PBYTE)&chMsg[wOffset+wType], // Source + Offset
wValueLen ); // Length
// ...terminada en NULL para tratarla como STRING de BYTES
szValue[wValueLen] = 0;
// Longitud de Valor de Campo informada
(*pwFieldLen) = wValueLen;
}
else
{
// Copia directa...
memmove((PBYTE)szValue, // Destiny
(PBYTE)&chMsg[wOffset+wType], // Source + Offset
wImpLength ); // Implicit Length
// ...terminada en NULL para tratarla como STRING de BYTES
szValue[wImpLength] = 0;
// Longitud de Valor de Campo informada
(*pwFieldLen) = wImpLength;
}
// Ok
return (TRUE);
}
// Valor de Longitud Implicita
BOOL ISO8583MSG::GetImplicitLength(WORD wField,
PWORD pwLength)
{
// Precondicion: Mensaje existente
if(!cbMsgLen)
return (FALSE);
// Precondicion: Field ISO 1..128
// Es campo valido?
if(!IsValidField(wField))
return (FALSE);
BYTE szLength[6]; // ASCII Length
WORD wImpLength; // Implicit Length
WORD wDigit; // Digit Index
// Propiedades del Campo especifico
WORD wType = FieldType(wField) ,
wOffset = FieldOffset(wField),
wLength = FieldLength(wField);
// Retorno de Longitud Implicita...
switch (wType)
{
case 0 : // Campo fijo, sin longitud implicita
return (FALSE);
break;
case 1 :
case 2 :
case 3 :
case 4 : // Campo variable, longitud implicita de 1 a 3 digitos
memmove((PBYTE)szLength,(PBYTE)&chMsg[wOffset], wType);
// Cada caracter debe ser un digito numerico
for(wDigit = 0; wDigit < wType; wDigit++)
if(!isdigit((int)szLength[wDigit]))
return (FALSE);
// STRING de BYTES terminada en NULL
szLength[wType] = 0x00;
// Conversion a entero binario
wImpLength = atoi((PSTR)szLength);
// Ok
(*pwLength) = wImpLength;
return (TRUE);
break;
default: // Error
return (FALSE);
break;
}
// Return x default
return (FALSE);
}
// Valor a Campo
BOOL ISO8583MSG::SetField(WORD wField,PWORD pwFieldLen,
PBYTE szValue,WORD wValueLen)
{
// Precondicion: Mensaje existente
if(!cbMsgLen)
return (FALSE);
// Precondicion: campo valido
if( !IsValidField(wField) )
return (FALSE);
// Precondicion: Origen no nulo
if((pwFieldLen == NULL) || (szValue == NULL) || (wValueLen == 0))
return (FALSE);
// Propiedades del Campo especifico
WORD wOffset = FieldOffset(wField),
wLength = FieldLength(wField),
wType = FieldType(wField);
// Longitud implicita en Campos variables
WORD wImpLength = 0;
// Segun tipo de campo
switch(wType)
{
case 0: // Campos fijos
// Chequear la longitud exacta...
if(wLength != wValueLen)
return (FALSE);
// Copia plana del campo especifico
memmove( (PBYTE)&chMsg[wOffset],
(PBYTE)szValue,
wLength);
// Longitud de Campo informada
(*pwFieldLen) = wLength;
// Ok
return (TRUE);
break;
case 1:
case 2:
case 3:
case 4: // Campos variables, pero solo de longitud equivalente
if(!GetImplicitLength( wField, &wImpLength ))
return (FALSE);
// Chequear la longitud...
if(wImpLength == wValueLen)
{
// Copia del campo especifico
memmove( (PBYTE)&chMsg[wOffset+wType],
(PBYTE)szValue, wValueLen);
// Longitud de Campo informada
(*pwFieldLen) = wValueLen;
// Ok
return (TRUE);
}
else
return (FALSE);
break;
default:
return (FALSE);
break;
}
}
// Insercion de Campo
BOOL ISO8583MSG::InsertField(WORD wField ,PWORD pwFieldLen,
PBYTE lpszValue,WORD cbValueLen)
{
// Precondicion: Mensaje existente
if(!cbMsgLen)
return (FALSE);
// Precondicion: No debe ser campo valido... porque se va a insertar:
if( IsValidField(wField) )
return (FALSE);
// Precondicion: Origen no nulo
if((pwFieldLen == NULL) || (lpszValue == NULL) || (cbValueLen == 0))
return (FALSE);
// Buffer auxiliar de copia (NO estatico por threads multiples)
memset(chAuxMsg,0x00,sizeof chAuxMsg);
cbAuxMsgLen = 0;
// Mascara de formateo de longitud implicita
BYTE szPrintMask[16];
// Propiedades del Campo Anterior/Siguiente
WORD wAuxField = 0,
wOffset = 0,
wLength = 0,
wType = 0;
// Propiedades del Nuevo Campo
WORD wNewType = 0;
// Buscar el campo anterior valido
for(wAuxField = wField-1;
wAuxField >= 1 &&
wAuxField < CISOFIELDS &&
!IsValidField(wAuxField);
wAuxField--);
// Hallado?
if(IsValidField(wAuxField))
{
// Propiedades del Campo especifico
wOffset = FieldOffset(wAuxField),
wLength = FieldLength(wAuxField),
wType = FieldType(wAuxField);
}
else
{
// Buscar el campo siguiente valido
for(wAuxField = wField+1;
wAuxField > 1 &&
wAuxField <= CISOFIELDS &&
!IsValidField(wAuxField);
wAuxField++);
// Hallado?
if(IsValidField(wAuxField))
{
// Propiedades del Campo especifico
wOffset = FieldOffset(wAuxField),
wLength = FieldLength(wAuxField),
wType = FieldType(wAuxField);
// Por ser campo siguiente, el nuevo campo se
// inserta antes, por lo tanto, no se tiene en cuenta
// la longitud de aquel para la copia, sino solo su
// desplazamiento u offset:
wLength = 0;
}
else
{
// Es el primer campo a insertar
// Es el Secondary Bitmap?
if(wField==1)
{
wOffset = 32; // Secondary Bitmap
wLength = 16;
wType = 0;
wAuxField = 0;
}
else
{
wOffset = 48; // Other
wLength = FieldLength(wField),
wType = FieldType(wField);
wLength = 0;
wAuxField = 0;
}
}
}
// Set a nulo del buffer local
memset( (PBYTE)chAuxMsg, 0, sizeof chAuxMsg);
// Copia a area local de trabajo,
// hasta el campo anterior/siguiente especifico
memmove( (PBYTE)chAuxMsg,
(PBYTE)chMsg,
wOffset+wLength );
// Longitud copiada hasta el campo anterior/siguiente especifico
cbAuxMsgLen = wOffset+wLength;
// Hacerlo valido al Campo a insertar
if( !MakeValidField( chAuxMsg, wField) )
return (FALSE);
// Insercion en si misma del nuevo campo, segun sea variable o fijo
wNewType = FieldType(wField);
switch ( wNewType )
{
case 0: // Copia plana hasta campo anterior/siguiente
memmove( (PBYTE)&chAuxMsg[wOffset+wLength],
(PBYTE)lpszValue,
cbValueLen );
// Longitud adicionada del campo insertado
cbAuxMsgLen += cbValueLen;
break;
case 1:
case 2:
case 3:
case 4: // Mascara de formateo de longitud implicita "%0#d"
sprintf( (PSTR)szPrintMask, "%%0%1i%1s", wNewType, "d");
sprintf( (PSTR)&chAuxMsg[wOffset+wLength],
(PSTR)szPrintMask, cbValueLen );
// Copia variable hasta campo anterior/siguiente
if((wOffset+wLength+wNewType) >= sizeof(chAuxMsg))
return (FALSE);
if((wOffset+wLength+wNewType+cbValueLen) >= sizeof(chAuxMsg))
return (FALSE);
memmove( (PBYTE)&chAuxMsg[wOffset+wLength+wNewType],
(PBYTE)lpszValue,
cbValueLen );
// Longitud adicionada del campo insertado
cbAuxMsgLen += cbValueLen+wNewType;
break;
default:// Error
return (FALSE);
}
// Copia a area local de trabajo, desde el campo anterior/siguiente
if((wOffset+wLength+cbValueLen+wNewType) > sizeof(chAuxMsg))
return (FALSE);
if( cbMsgLen < (wOffset+wLength) )
return (FALSE);
memmove( (PBYTE)&chAuxMsg[wOffset+wLength+cbValueLen+wNewType],
(PBYTE)&chMsg[wOffset+wLength],
cbMsgLen-(wOffset+wLength) );
cbAuxMsgLen += cbMsgLen-(wOffset+wLength);
// Copia a area externa
memmove( (PBYTE)chMsg,
(PBYTE)chAuxMsg,
cbAuxMsgLen);
cbMsgLen = cbAuxMsgLen;
// Postcondicion: Recalculo de Offsets Ok?
return RecalculateOffsets();
}
// Borrado de Campo
BOOL ISO8583MSG::DeleteField(WORD wAuxField)
{
// Precondicion: Mensaje existente
if(!cbMsgLen)
return (FALSE);
// Precondicion: debe ser campo valido
if( !IsValidField(wAuxField) )
return (FALSE);
// Buffer auxiliar de copia, (NO estatico por threads multiples)
memset(chAuxMsg,0x00,sizeof chAuxMsg);
cbAuxMsgLen = 0;
// Copia a area local de trabajo
memmove( (PBYTE)chAuxMsg, (PBYTE)chMsg, sizeof chAuxMsg);
cbAuxMsgLen = min(cbMsgLen,sizeof chAuxMsg);
// Propiedades del Campo especifico
WORD wOffset = FieldOffset(wAuxField),
wLength = FieldLength(wAuxField),
wType = FieldType(wAuxField);
// Longitud implicita en campos variables
WORD wImpLength = 0;
// Verificar longitudes, y corregirlas
if(wLength >= cbMsgLen)
{
if(((INT)cbMsgLen-(INT)wOffset) < 0)
// Error
return FALSE;
else
wLength = cbMsgLen-wOffset;
}//end-if-length
// Borrado en si mismo del campo, segun sea variable o fijo
switch ( wType )
{
case 0: // Copia exceptuada del resto del mensaje sobre el campo
// memmove(...)
if(cbAuxMsgLen < (wOffset+wLength))
return (FALSE);
memmove( (PBYTE)&chAuxMsg[wOffset],
(PBYTE)&chAuxMsg[wOffset+wLength],
cbAuxMsgLen-(wOffset+wLength) );
// Longitud restada del campo borrado
cbAuxMsgLen -= wLength;
break;
case 1:
case 2:
case 3:
case 4: // Longitud implicita?
if(!GetImplicitLength( wAuxField, &wImpLength ))
return (FALSE);
// Chequeo de longitudes
if((INT)cbAuxMsgLen-(wOffset+wImpLength+wType) < 0)
return (FALSE);
// Copia exceptuada del resto del mensaje sobre el campo
// memmove(...)
memmove( (PBYTE)&chAuxMsg[wOffset],
(PBYTE)&chAuxMsg[wOffset+wImpLength+wType],
cbAuxMsgLen-(wOffset+wImpLength+wType) );
// Longitud implicita restada del campo borrado
cbAuxMsgLen -= (wImpLength+wType);
// Set a NULL del resto
memset( (PBYTE)&chAuxMsg[cbAuxMsgLen], 0,
sizeof(chAuxMsg) - cbAuxMsgLen);
break;
default:// Error
return (FALSE);
}
// Invalidar lo borrado
if(!MakeInvalidField( chAuxMsg, wAuxField ))
return (FALSE);
// Copia a area externa
memmove( (PBYTE)chMsg, (PBYTE)chAuxMsg, sizeof chMsg);
cbMsgLen = cbAuxMsgLen;
// Postcondicion: Recalculos Ok?
return RecalculateOffsets();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -