⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 msgtrk.cpp

📁 ISO 8583 with c++ for financial transaction standard
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    // Considerar que puede haber un header opcional de N bytes....
    memcpy((LPBYTE)szTrkBuffer + cbHdrLen, lpbBuffer, cbLen);    
    // ...si corresponde, ya que es opcional, y por omision es TRUE:
    if(bLineEnd)
    {
        szTrkBuffer[cbLen+cbHdrLen]   = '\n';    // Line Feed
        szTrkBuffer[cbLen+cbHdrLen+1] =   0 ;    // Null Terminated String
        cbLen++;
    }

    // Posicionarse al final del archivo (aunque ya fue abierto _O_APPEND)
    fseek(hfFile, 0L, SEEK_END);

    // Escritura en si misma, mas el opcional del header
    // Opcionalmente se agrega un header de estadisticas.
    cbReadWrite = (SHORT)fwrite((LPBYTE)szTrkBuffer, cbLen + cbHdrLen, 1, hfFile);
    
    // Asegurar que se baje el buffer del Sistema Operativo a disco
    cbCommit = fflush(hfFile);

    // Postcondicion: cerrar y flushear el archivo a disco, y reabrirlo
    // para evitar perder el contenido ante muerte subita del proceso (Win95,Win98)
    if(bOpenCloseInWrite)
        ReOpen();
    
    // Retorno incorrecto?
    return( (cbReadWrite == NULL) || 
            (cbReadWrite == 0)         || 
            (cbReadWrite < (cbLen + cbHdrLen) ) ) 
        ? FALSE 
        : TRUE;
    }       

///////////////////////////////////////////////////////////        
// Cierre
BOOL EXPORT MessageTracker::Close()
    {        
    // Precondicion: Handle valido
    if (NULL == hfFile) 
        return FALSE;
    // Cierre
    if (fclose(hfFile) == NULL) 
        return FALSE;
    // Asegurar handle en NULL
    hfFile = NULL;
    // Retorno Ok
    return TRUE;
    }

///////////////////////////////////////////////////////////    
// Creacion
BOOL MessageTracker::Create(LPCSTR pszFName)
    {    
    // Precondicion : NO DEBE haber handle : Debe estar cerrado
    if(NULL != hfFile)
        return FALSE;
    // Creacion    
    hfFile = fopen(pszFName, "tw") ;
    return (NULL == hfFile) ? FALSE 
                            : TRUE;
    }    

///////////////////////////////////////////////////////////        
// Re-Apertura
BOOL EXPORT MessageTracker::ReOpen(BOOL bTrackByDay)
    {   
    // Nombre temporal de archivo actual
    char szTempName[SZFNAMELEN];
    
    // Copiar nombre actual como temporal
    strcpy(szTempName, szFileName);
    // Abrirlo, chequeando tracking diario : No usar "freopen".
    return( Open((LPCSTR)szTempName, bTrackByDay) );
    }    

///////////////////////////////////////////////////////////
// Re-Creacion
BOOL MessageTracker::ReCreate(void)
    {    
    // Precondicion: Archivo cerrado
    Close();
    // Creacion de archivo
    return Create(szFileName);
    }



///////////////////////////////////////////////////////////
// Por dia?
BOOL EXPORT MessageTracker::IsByDay(void)
    {
    // Booleano de Tracking dia por dia
    return (bByDay);
    }

///////////////////////////////////////////////////////////
// Nombre de archivo formateado al dia de la fecha
// Esta es la unica funcion no estandard segun Sistema Operativo en que 
// se implemente, debido al formato de los nombres en el File System
BOOL MessageTracker::SetTodayFileName(LPCSTR pszInFName, LPSTR pszOutFName)
    {
    char    szTempFName[SZFNAMELEN];  // Nombre de archivo temporal
    char    szTodayDate[SZFNAMELEN];  // Fecha ASCII de hoy
    char   *pszExtension = NULL;      // Ptr a CharId de Extension "."
    char   *pszFile      = NULL;      // Ptr a CharId de File "\"

    // Precondicion: Nombre base
    if(pszInFName == NULL) 
        return FALSE;
    // Precondicion: Extension "." presente
    if((pszExtension = strrchr(pszInFName,'.')) == NULL) 
        pszExtension = ".trk"; // default
        
    
    // Inicio del Nombre de Archivo, denotada por el ultimo "\"
#ifdef _WIN32
    pszFile = strrchr(pszInFName,'\\');    
#else
    pszFile = strrchr(pszInFName,'/');    
#endif // _WIN32,_AS400,_RS6000

    // Si no existe... 
    if (pszFile == NULL) pszFile = (LPSTR)pszInFName; // Inicio en 1er caracter alfabetico
    else                 pszFile++;                   // sino en siguiente despues de '\'

    // Fecha y Hora actuales y locales del Sistema
    time_t tSystemTime   = time(NULL);               // System Time
    tm     *ptmLocalTime = localtime(&tSystemTime);  // Local System Time
    // Formateo ISO-YYMMDD para fecha
    strftime(szTodayDate, sizeof szTodayDate, "%y%m%d", ptmLocalTime);

    // Copia del Path hasta el Folder/Directorio
    // Verifica longitud de nombre, asegurando "xxYYMMDD.ext"
    if((pszFile-pszInFName) > (SZFNAMELEN-sizeof("xxYYMMDD.ext"))) 
        return FALSE;
    // Copia del Path hasta el Folder/Directorio
    strncpy(szTempFName, pszInFName, (size_t)(pszFile-pszInFName));
    szTempFName[(size_t)(pszFile-pszInFName)] = 0x00;

    // Si existe un Path previo, concatenar el separador de Paths:
    if((size_t)(pszFile-pszInFName) != 0)        
#ifdef _WIN32
        strcat(szTempFName, "\\");
#else
        strcat(szTempFName, "/");
#endif // _WIN32
        
    // Concatenar iniciales, de MessageTracker por default
    // si no hay caracteres iniciales alfabeticos en el nombre del archivo:
    if( isalpha((int)(*pszFile)) && isalpha((int)(*(pszFile+1))) )
        strncat(szTempFName, pszFile, 2);
    else
        // Concatenar prefijo por default "MT"
        strcat(szTempFName, "MT");    

    // Concatenar formato fecha
    strcat(szTempFName, szTodayDate);
    // Concatenar extension
    strcat(szTempFName, pszExtension);

    // Copia externa?
    if(pszOutFName != NULL) 
        strcpy(pszOutFName, szTempFName);    
    // Retorno Ok
    return TRUE;
    }

///////////////////////////////////////////////////////////
// Hora de Inicio del Tracking
time_t EXPORT MessageTracker::StartTime(void)
    {
    // Retorno hora de inicio del tracking
    return (tTrackStartTime);
    }

///////////////////////////////////////////////////////////
// Chequeo de distinto dia de Tracking con respecto al Sistema
BOOL EXPORT MessageTracker::CheckTrackingDay(void)
    {    

    // Precondicion: Tracking a diario establecido
    if(!bByDay) 
        return FALSE;

    // Variables y estructuras auxiliares de Time y Date del Sistema
    time_t tSystemTime        = time(NULL);                 // System Time
    tm     *ptmSystemTime     = localtime(&tSystemTime); // Local System Time
    int    iSystemDay         = ptmSystemTime->tm_yday;  // Local System Day of Year
    // Variables y estructuras auxiliares de Time y Date del Tracker
    tm     *ptmTrackStartTime = localtime(&tTrackStartTime); // Local Trk StartTime
    int    iTrackStartDay     = ptmTrackStartTime->tm_yday;  // Local Trk Day of Year    

    // Chequeo de distinto dia de Tracking con respecto al Sistema
    return (iSystemDay != iTrackStartDay) 
        ? ReOpen(bByDay)
        : FALSE ;

    }


///////////////////////////////////////////////////////////
// Recuperar el HFILE interno
///////////////////////////////////////////////////////////
PFILE EXPORT MessageTracker::GetFileHandle()                
{
    return hfFile;
}

///////////////////////////////////////////////////////////

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -