Example #1
0
STDMETHODIMP CECR::GetHardwareInfo(BSTR FirmID, LONG* HardwareType, LONG* HardwareNumber, LONG* IsFiscalized, LONG* ErrorCode)
{

// серийный номер
    InitCmd();
    // команда
    to_numeric(103, m_Cmd, 3, m_Len);   //GETSERIAL
    // пароль
    to_char(OPERATOR_PASSWD, m_Cmd + m_Len, 4, m_Len);

    m_RspLen = 12;
    m_ECRList.PassCmd(FirmID, m_Cmd, m_Len, m_Rsp, m_RspLen, ErrorCode);
    if (*ErrorCode == E_SUCCESS)
        *HardwareNumber = atol((char *)m_Rsp);

// количество фискализаций
    InitCmd();
    // команда
    to_numeric(105, m_Cmd, 3, m_Len);   //GETFISCNUM
    // пароль
    to_char(OPERATOR_PASSWD, m_Cmd + m_Len, 4, m_Len);

    m_RspLen = 2;
    m_ECRList.PassCmd(FirmID, m_Cmd, m_Len, m_Rsp, m_RspLen, ErrorCode);
    if (*ErrorCode == E_SUCCESS)
        atol((char*)m_Rsp) ? *IsFiscalized = 1 : *IsFiscalized = 0;

// тип драйвера
    *HardwareType = m_ECRList.GetHardwareType();

    return S_OK;
}
Example #2
0
STDMETHODIMP CECR::Fiscalization(BSTR FirmID, LONG OldPassword, LONG NewPassword, ULONGLONG MachineRegNum, ULONGLONG TaxpayerIndNum, LONG* ErrorCode)
{
    LONG IsFiscalized = 0;
    CHAR szOldPassword[8];
    ZeroMemory(szOldPassword, 8);
    memset(szOldPassword, 32, 8);

    // количество фискализаций
    InitCmd();
    // команда
    to_numeric(105, m_Cmd, 3, m_Len);   //GETFISCNUM
    // пароль
    to_char(OPERATOR_PASSWD, m_Cmd + m_Len, 4, m_Len);

    m_RspLen = 2;
    m_ECRList.PassCmd(FirmID, m_Cmd, m_Len, m_Rsp, m_RspLen, ErrorCode);
    atol((char*)m_Rsp) ? IsFiscalized = 1 : IsFiscalized = 0;

    if (IsFiscalized)	// если ФР уже фискализован, используем старый пароль		
        sprintf(szOldPassword, "%08d", OldPassword);
    else			// если ФР не фискализован, в качестве пароля используется серийный номер
    {
        InitCmd();
        // команда
        to_numeric(103, m_Cmd, 3, m_Len);   //GETSERIAL
        // пароль
        to_char(OPERATOR_PASSWD, m_Cmd + m_Len, 4, m_Len);

        m_RspLen = 12;
        m_ECRList.PassCmd(FirmID, m_Cmd, m_Len, m_Rsp, m_RspLen, ErrorCode);

        CopyMemory(szOldPassword, m_Rsp, 8);
    }

    InitCmd();
    // команда
    to_numeric(302, m_Cmd, 3, m_Len);   //FISCALISATION
    // пароль
    to_char(szOldPassword, m_Cmd + m_Len, 8, m_Len);
    // регистрационный номер кассы
    to_numeric((LONG)MachineRegNum, m_Cmd + m_Len, 12, m_Len);   
    // ИНН
    to_numeric((LONG)TaxpayerIndNum, m_Cmd + m_Len, 12, m_Len);   
    // положение десятичной точки в суммах (резерв)
    to_numeric(2, m_Cmd + m_Len, 1, m_Len);   
    // новый пароль
    to_numeric(NewPassword, m_Cmd + m_Len, 8, m_Len);   

    m_RspLen = 0;
    m_ECRList.PassCmd(FirmID, m_Cmd, m_Len, m_Rsp, m_RspLen, ErrorCode);
    
    return S_OK;
}
Example #3
0
STDMETHODIMP CECR::Cut(BSTR FirmID, LONG CutType, LONG* ErrorCode)
{
    if(!bDocOpened)
    {
        OpenDocument(FirmID, DEP_NO, ErrorCode, NonFiskDocument);
        if (*ErrorCode == E_SUCCESS)
            PrintBuffer(FirmID, ErrorCode);
    }

    InitCmd();
    // команда
    to_numeric(215, m_Cmd, 3, m_Len);   //CLOSE
    // пароль
    to_char(OPERATOR_PASSWD, m_Cmd + m_Len, 4, m_Len);
    // обрезать чек
    to_numeric(CutType, m_Cmd + m_Len, 1, m_Len);   

    m_RspLen = 0;
    m_ECRList.PassCmd(FirmID, m_Cmd, m_Len, m_Rsp, m_RspLen, ErrorCode);
    if (*ErrorCode == E_SUCCESS)
    {
        ClearPrintBuffer();
        bDocOpened = FALSE;
    }

    return S_OK;
}
Example #4
0
STDMETHODIMP CECR::State(BSTR FirmID, LONG *Opened, LONG *Over24h, LONG *Idle, LONG *OutOfPaper, LONG *DocOpened, LONG *DrawerOpened, LONG* ErrorCode)
{
//  статус ФР
    InitCmd();
    // команда
    to_numeric(101, m_Cmd, 3, m_Len);   //GETSTATUS
    // пароль
    to_char(OPERATOR_PASSWD, m_Cmd + m_Len, 4, m_Len);
    // опрос принтера
    to_numeric(1, m_Cmd + m_Len, 1, m_Len);   

    m_RspLen = 4;
    m_ECRList.PassCmd(FirmID, m_Cmd, m_Len, m_Rsp, m_RspLen, ErrorCode);
    if (*ErrorCode == E_SUCCESS)
    {
        *Opened = ((m_Rsp[0] & 0x10) == 0x10);		// смена открыта
        *Over24h = ((m_Rsp[1] & 0x2) == 0x2);		// смена больше 24 ч.
        *DocOpened = ((m_Rsp[0] & 0x20) == 0x20);	// документ открыт

        *Idle = ((m_Rsp[3] & 0x2) == 0x2);			// принтер не отвечает
        *Idle = *Idle || (m_Rsp[1] & 0x1);			// или блокирован
        *Idle = !*Idle;

        *OutOfPaper = ((m_Rsp[3] & 0x4) == 0x4);	// бумаги нет
        if( *OutOfPaper & ((m_Rsp[0] & 0x40) == 0x40))		// команда зависла и бумаги нет
            *OutOfPaper = 2;
        else if ((m_Rsp[0] & 0x40) == 0x40)					// бумага уже есть, а команда все еще висит
            *OutOfPaper = 3;
    }

//  статус ДЯ
    CashdrawerState(DrawerOpened, ErrorCode);

    return S_OK;
}
Example #5
0
VOID CECR::OpenDocument(BSTR FirmID, LONG DepNo, LONG* ErrorCode, DWORD dwOpenType)
{
    char lpDeptName[255];
    
    ZeroMemory(lpDeptName, 255);
    sprintf(lpDeptName, "Отдел %d", DepNo);

    m_ECRList.Win1251ToCP866(lpDeptName);

    // открыть документ
    InitCmd();
    // команда
    to_numeric(205, m_Cmd, 3, m_Len);   //OPEN
    // пароль
    to_char(OPERATOR_PASSWD, m_Cmd + m_Len, 4, m_Len);
    // тип документа
    to_numeric(dwOpenType, m_Cmd + m_Len, 2, m_Len);   
    // ид. оператора
    to_bchar(m_ECRList.CashierName, m_Cmd + m_Len, strlen(m_ECRList.CashierName), m_Len);
    // код оператора
    to_numeric(13, m_Cmd + m_Len, 2, m_Len);
    // ид. отдела
    to_bchar(lpDeptName, m_Cmd + m_Len, strlen(lpDeptName), m_Len);
    // ид. подотдела
    to_bchar("", m_Cmd + m_Len, 0, m_Len);
    
    m_RspLen = 5;
    m_ECRList.PassCmd(FirmID, m_Cmd, m_Len, m_Rsp, m_RspLen, ErrorCode);
// если не удалось открыть документ, поскольку он уже открыт, команду считаем успешной
    if (*ErrorCode == 46)
        *ErrorCode = E_SUCCESS;
    
    bDocOpened = *ErrorCode == E_SUCCESS;
}
Example #6
0
STDMETHODIMP CECR::MoveCash(BSTR FirmID, LONG Money, LONG DirectionIn, LONG* ErrorCode)
{
    DWORD dwDocType;
    DirectionIn ? dwDocType = CashInDocument : dwDocType = CashOutDocument;

    // открыть документ
    OpenDocument(FirmID, DEP_NO, ErrorCode, dwDocType);
    if (*ErrorCode == E_SUCCESS)
    {
        PrintBuffer(FirmID, ErrorCode);
        if (*ErrorCode == E_SUCCESS)
        {
            InitCmd();
            // команда
            to_numeric(214, m_Cmd, 3, m_Len);   //SETTENDER
            // пароль
            to_char(OPERATOR_PASSWD, m_Cmd + m_Len, 4, m_Len);
            // тип оплаты
            to_numeric(0, m_Cmd + m_Len, 2, m_Len);   
            // сумма
            to_smoney(Money, m_Cmd + m_Len, 10, m_Len);   

            m_RspLen = 11;
            m_ECRList.PassCmd(FirmID, m_Cmd, m_Len, m_Rsp, m_RspLen, ErrorCode);

            if (*ErrorCode == E_SUCCESS)
                Cut(FirmID, 1, ErrorCode);
        }
    }
    return S_OK;
}
Example #7
0
STDMETHODIMP CECR::SetDateTime(BSTR FirmID, LONG Year, LONG Month, LONG Day, LONG Hour, LONG Minute, LONG Second, LONG* ErrorCode)
{
    InitCmd();
    // команда
    to_numeric(401, m_Cmd, 3, m_Len);   //SETTIMER
    // пароль
    to_char(OPERATOR_PASSWD, m_Cmd + m_Len, 4, m_Len);
    // день
    to_numeric(Day, m_Cmd + m_Len, 2, m_Len);   
    // месяц
    to_numeric(Month, m_Cmd + m_Len, 2, m_Len);   
    // год
    to_numeric(Year, m_Cmd + m_Len, 4, m_Len);   
    // час
    to_numeric(Hour, m_Cmd + m_Len, 2, m_Len);   
    // минута
    to_numeric(Minute, m_Cmd + m_Len, 2, m_Len);   
    // секунда
    to_numeric(Second, m_Cmd + m_Len, 2, m_Len);   

    m_RspLen = 0;
    m_ECRList.PassCmd(FirmID, m_Cmd, m_Len, m_Rsp, m_RspLen, ErrorCode);
    if (*ErrorCode == 23)
        m_ECRList.PassCmd(FirmID, m_Cmd, m_Len, m_Rsp, m_RspLen, ErrorCode);
    
    return S_OK;
}
Example #8
0
STDMETHODIMP CECR::ShiftReport(BSTR FirmID, LONG IsZReport, LONG* ErrorCode)
{
    InitCmd();
    switch (IsZReport)
    {
    case 1:
        // команда
        to_numeric(204, m_Cmd, 3, m_Len);   //ZREPORT
        // пароль
        to_char(OPERATOR_PASSWD, m_Cmd + m_Len, 4, m_Len);
        // код оператора
        to_numeric(11, m_Cmd + m_Len, 2, m_Len);
        break;
    case 2:
        // команда
        to_numeric(218, m_Cmd, 3, m_Len);   //XREPORT
        // пароль
        to_char(OPERATOR_PASSWD, m_Cmd + m_Len, 4, m_Len);
        break;
    case 3:
        // команда
        to_numeric(218, m_Cmd, 3, m_Len);   //XREPORT
        // пароль
        to_char(OPERATOR_PASSWD, m_Cmd + m_Len, 4, m_Len);
        break;
    }
    
    m_RspLen = 0;
    m_ECRList.PassCmd(FirmID, m_Cmd, m_Len, m_Rsp, m_RspLen, ErrorCode);
    ClearPrintBuffer();
    return S_OK;
}
Example #9
0
STDMETHODIMP CECR::FiscalReportD(BSTR FirmID, LONG Password, LONG Year1, LONG Month1, LONG Day1, LONG Year2, LONG Month2, LONG Day2, LONG IsFull, LONG* ErrorCode)
{
    InitCmd();
    // команда
    to_numeric(303, m_Cmd, 3, m_Len);   //FREPORTDATE
    // пароль
    to_numeric(Password, m_Cmd + m_Len, 8, m_Len);
    // начальная дата: день
    to_numeric(Day1, m_Cmd + m_Len, 2, m_Len);   
    // начальная дата: месяц
    to_numeric(Month1, m_Cmd + m_Len, 2, m_Len);   
    // начальная дата: год
    to_numeric(Year1, m_Cmd + m_Len, 4, m_Len);   
    // конечная дата: день
    to_numeric(Day2, m_Cmd + m_Len, 2, m_Len);   
    // конечная дата: месяц
    to_numeric(Month2, m_Cmd + m_Len, 2, m_Len);   
    // конечная дата: год
    to_numeric(Year2, m_Cmd + m_Len, 4, m_Len);   
    // вид отчета
    to_numeric(IsFull, m_Cmd + m_Len, 1, m_Len);   

    m_RspLen = 0;
    m_ECRList.PassCmd(FirmID, m_Cmd, m_Len, m_Rsp, m_RspLen, ErrorCode);
    
    return S_OK;
}
Example #10
0
STDMETHODIMP CECR::PrintBarcode(BSTR FirmID, BYTE nPrintText, BSTR wszData, LONG* ErrorCode)
{
    CW2A szData(wszData);
    m_ECRList.Win1251ToCP866(szData);

    BYTE nPrintBuffer[255];
    DWORD dwBufferSize;

    dwBufferSize = 0;
    memset(nPrintBuffer, 0, 255);

    // позиционирование по центру
    nPrintBuffer[dwBufferSize++] = 0x1B;
    nPrintBuffer[dwBufferSize++] = 'a';
    nPrintBuffer[dwBufferSize++] = 1;

    // высота штрих-кода
    nPrintBuffer[dwBufferSize++] = 0x1D;
    nPrintBuffer[dwBufferSize++] = 'h';
    nPrintBuffer[dwBufferSize++] = 70;

    // ширина кода
    nPrintBuffer[dwBufferSize++] = 0x1D;
    nPrintBuffer[dwBufferSize++] = 'w';
    nPrintBuffer[dwBufferSize++] = 2;

    // цифры
    nPrintBuffer[dwBufferSize++] = 0x1D;
    nPrintBuffer[dwBufferSize++] = 'H';
    nPrintBuffer[dwBufferSize++] = 2;

    // штрих-код
    nPrintBuffer[dwBufferSize++] = 0x1D;
    nPrintBuffer[dwBufferSize++] = 'k';
    nPrintBuffer[dwBufferSize++] = 0x43;
    nPrintBuffer[dwBufferSize++] = 0x0C;

    // данные
    memcpy(nPrintBuffer + dwBufferSize, szData, 12);
    dwBufferSize += 12;

    InitCmd();
    // команда
    to_numeric(237, m_Cmd, 3, m_Len);   //PRINTBARCODE
    // пароль
    to_char(OPERATOR_PASSWD, m_Cmd + m_Len, 4, m_Len);
    // устройство
    to_numeric(0, m_Cmd + m_Len, 1, m_Len);   
    // текст
    to_bchar((char *)nPrintBuffer, m_Cmd + m_Len, dwBufferSize, m_Len);

    CopyMemory(CommandBuffer[CommandBufferLen++], m_Cmd, m_Len);

    return S_OK;
}
Example #11
0
STDMETHODIMP CECR::GetDateShiftRange(BSTR FirmID, LONG Password, LONG* Year1, LONG* Month1, LONG* Day1, LONG* Year2, LONG* Month2, LONG* Day2, LONG* Shift1, LONG* Shift2, LONG* ErrorCode)
{
    LONG Hour, Minute, Second;

    GetDateTime(FirmID, Year2, Month2, Day2, &Hour, &Minute, &Second, ErrorCode);	
    *Year2 -= 2000;

    // получим дату закрытия первой смены
    InitCmd();
    // команда
    to_numeric(109, m_Cmd, 3, m_Len);   //GETСSHIFT
    // пароль
    to_char(OPERATOR_PASSWD, m_Cmd + m_Len, 4, m_Len);
    // номер смены
    to_numeric(1, m_Cmd + m_Len, 4, m_Len);   
    m_RspLen = 24;
    m_ECRList.PassCmd(FirmID, m_Cmd, m_Len, m_Rsp, m_RspLen, ErrorCode);
    if (*ErrorCode == E_SUCCESS)
    {
        *Day1	= from_numeric(m_Rsp + 4, 2);
        *Month1	= from_numeric(m_Rsp + 4 + 2, 2);
        *Year1	= from_numeric(m_Rsp + 4 + 4, 4) - 2000;
    }
    
    InitCmd();
    // команда
    to_numeric(106, m_Cmd, 3, m_Len);   //GETSHIFTNUM
    // пароль
    to_char(OPERATOR_PASSWD, m_Cmd + m_Len, 4, m_Len);
    m_RspLen = 4;
    m_ECRList.PassCmd(FirmID, m_Cmd, m_Len, m_Rsp, m_RspLen, ErrorCode);

    if (*ErrorCode == E_SUCCESS)
    {
        *Shift1 = 1;
        *Shift2 = from_numeric(m_Rsp, 4);
    }
    
    return S_OK;
}
Example #12
0
STDMETHODIMP CECR::ContinuePrint(BSTR FirmID, LONG* ErrorCode)
{
    ClearPrintBuffer();

    InitCmd();
    // команда
    to_numeric(405, m_Cmd, 3, m_Len);   //REPEAT
    // пароль
    to_char(OPERATOR_PASSWD, m_Cmd + m_Len, 4, m_Len);

    m_RspLen = 0;
    m_ECRList.PassCmd(FirmID, m_Cmd, m_Len, m_Rsp, m_RspLen, ErrorCode);
    return S_OK;
}
Example #13
0
VOID CECR::SetClisheOrFooterString(BSTR FirmID, BSTR String, LONG Row, LONG* ErrorCode, BYTE CmdNo)
{
    if(Row > 10)
    {
        *ErrorCode = E_SUCCESS;
        return;
    }

    DWORD dwLen, dwSpaces;

    CHAR lzStringToPrint[MAX_STRING_LEN];
    CW2A szString(String);
    m_ECRList.Win1251ToCP866(szString);
    ZeroMemory(lzStringToPrint, MAX_STRING_LEN);

    if (String)
    {
        dwLen = (DWORD) strlen(szString);
        if (dwLen < m_ECRList.GetStringLen())
        {
            dwSpaces = (m_ECRList.GetStringLen() - dwLen) / 2;
            FillMemory(lzStringToPrint, dwSpaces, 0x20);
            CopyMemory(lzStringToPrint + dwSpaces, szString, dwLen);
        }
        else
            CopyMemory(lzStringToPrint, szString, m_ECRList.GetStringLen());
    }

    InitCmd();
    // команда
    to_numeric(CmdNo, m_Cmd, 3, m_Len);   
    // пароль
    to_char(OPERATOR_PASSWD, m_Cmd + m_Len, 4, m_Len); 
    // номер строки
    to_numeric(Row, m_Cmd + m_Len, 2, m_Len);   
    // высота строки
    to_numeric(1, m_Cmd + m_Len, 2, m_Len);   
    // данные строки
    to_bchar(lzStringToPrint, m_Cmd + m_Len, strlen(lzStringToPrint), m_Len);

    m_RspLen = 0;
    m_ECRList.PassCmd(FirmID, m_Cmd, m_Len, m_Rsp, m_RspLen, ErrorCode);
    if(*ErrorCode == 45)			// если ФР блокирован, все равно вернем удачный код завершения, чтобы оболочка могла нормально загрузиться
        *ErrorCode = E_SUCCESS;

}
Example #14
0
STDMETHODIMP CECR::GetCashMoney(BSTR FirmID, LONG* ErrorCode, LONG* Money)
{
    InitCmd();
    // команда
    to_numeric(111, m_Cmd, 3, m_Len);   //GETSUM
    // пароль
    to_char(OPERATOR_PASSWD, m_Cmd + m_Len, 4, m_Len);
    // регистр
    to_numeric(23, m_Cmd + m_Len, 3, m_Len);   
    
    m_RspLen = 16;
    m_ECRList.PassCmd(FirmID, m_Cmd, m_Len, m_Rsp, m_RspLen, ErrorCode);
    if (*ErrorCode == E_SUCCESS)
        *Money = from_money(m_Rsp, m_RspLen);

    return S_OK;
}
Example #15
0
STDMETHODIMP CECR::GetReceiptNumber(BSTR FirmID, LONG ReceiptType, LONG* ErrorCode, LONG* ReceiptNumber)
{

    InitCmd();
    // команда
    to_numeric(112, m_Cmd, 3, m_Len);   //GETCOUNTER
    // пароль
    to_char(OPERATOR_PASSWD, m_Cmd + m_Len, 4, m_Len);
    // номер счетчика
    to_numeric(6, m_Cmd + m_Len, 2, m_Len);   

    m_RspLen = 8;
    m_ECRList.PassCmd(FirmID, m_Cmd, m_Len, m_Rsp, m_RspLen, ErrorCode);
    if (*ErrorCode == E_SUCCESS)
        *ReceiptNumber = from_numeric(m_Rsp, 8);

    return S_OK;
}
Example #16
0
STDMETHODIMP CECR::GetEKLZState(BSTR FirmID, BOOL* IsEKLZLow, LONG* ErrorCode)
{
    *IsEKLZLow = FALSE;
    // статус ФР
    InitCmd();
    // команда
    to_numeric(101, m_Cmd, 3, m_Len);   //GETSTATUS
    // пароль
    to_char(OPERATOR_PASSWD, m_Cmd + m_Len, 4, m_Len);
    // опрос принтера
    to_numeric(1, m_Cmd + m_Len, 1, m_Len);   
    m_RspLen = 4;
    m_ECRList.PassCmd(FirmID, m_Cmd, m_Len, m_Rsp, m_RspLen, ErrorCode);
    if (*ErrorCode == E_SUCCESS)
        *IsEKLZLow = ((m_Rsp[1] & 0x20) == 0x20);

    return S_OK;
}
Example #17
0
STDMETHODIMP CECR::CancelReceipt(BSTR FirmID, LONG* ErrorCode)
{

    InitCmd();
    // команда
    to_numeric(216, m_Cmd, 3, m_Len);   //ABORT
    // пароль
    to_char(OPERATOR_PASSWD, m_Cmd + m_Len, 4, m_Len);
    
    m_RspLen = 0;
    m_ECRList.PassCmd(FirmID, m_Cmd, m_Len, m_Rsp, m_RspLen, ErrorCode);
    ClearPrintBuffer();
    bDocOpened = FALSE;

    if (*ErrorCode == 34)
        *ErrorCode = E_SUCCESS;
        
    return S_OK;
}
Example #18
0
void DebugInit( void )
{
    NestedCallLevel = 0;
    UpdateFlags = 0;
    _SwitchOn( SW_ERROR_STARTUP );
    _SwitchOn( SW_CHECK_SOURCE_EXISTS );
    SET_NIL_ADDR( NilAddr );
    TxtBuff  = &DbgBuffers[0];
    *TxtBuff = '\0';
    NameBuff = &DbgBuffers[TXT_LEN+1];
    *NameBuff = '\0';
    CurrRadix = DefRadix = 10;
    DbgLevel = MIX;
    ActiveWindowLevel = MIX;
    _SwitchOn( SW_BELL );
    _SwitchOn( SW_FLIP );
    _SwitchOn( SW_RECURSE_CHECK );
    _SwitchOff( SW_ADDING_SYMFILE );
    _SwitchOff( SW_TASK_RUNNING );
    RecordInit();
    LogInit();
    InitMADInfo();
    InitMachState();
    PathInit();
    InitDbgInfo();
    InitTrap( TrapParms );
    if( !LangSetInit() ) {
        FiniTrap();
        StartupErr( LIT_ENG( STARTUP_Loading_PRS ) );
    }
    if( !InitCmd() ) {
        FiniTrap();
        StartupErr( LIT_ENG( ERR_NO_MEMORY ) );
    }
    InitScan();
    InitLook();
    InitBPs();
    InitSource();
    InitDLLList();
    DUIInit();
    InitHook();
    VarDisplayInit();
}
Example #19
0
STDMETHODIMP CECR::FiscalReportS(BSTR FirmID, LONG Password, LONG Shift1, LONG Shift2, LONG IsFull, LONG* ErrorCode)
{
    InitCmd();
    // команда
    to_numeric(304, m_Cmd, 3, m_Len);   //FREPORTSHIFT
    // пароль
    to_numeric(Password, m_Cmd + m_Len, 8, m_Len);
    // начальная смена
    to_numeric(Shift1, m_Cmd + m_Len, 4, m_Len);   
    // конечная смена
    to_numeric(Shift2, m_Cmd + m_Len, 4, m_Len);   
    // вид отчета
    to_numeric(IsFull, m_Cmd + m_Len, 1, m_Len);   

    m_RspLen = 0;
    m_ECRList.PassCmd(FirmID, m_Cmd, m_Len, m_Rsp, m_RspLen, ErrorCode);
    
    return S_OK;
}
Example #20
0
STDMETHODIMP CECR::PrintString(BSTR FirmID, BSTR StringToPrint, BYTE IsBold, BYTE Align, LONG* ErrorCode)
{
    CW2A szStringToPrint(StringToPrint);
    m_ECRList.Win1251ToCP866(szStringToPrint);
    DWORD dwLen, dwSpaces;
    CHAR lzStringToPrint[MAX_STRING_LEN];
    ZeroMemory(lzStringToPrint, MAX_STRING_LEN);

    if (szStringToPrint)
    {
        dwLen = (DWORD) strlen(szStringToPrint);
        if ((dwLen > m_ECRList.GetStringLen()) || (Align == 1))
        {
            dwLen > m_ECRList.GetStringLen() ? 
                CopyMemory(lzStringToPrint, szStringToPrint, m_ECRList.GetStringLen()) :
                CopyMemory(lzStringToPrint, szStringToPrint, dwLen);
        }
        else
        {
            (Align == 2) ? dwSpaces = ((m_ECRList.GetStringLen() - dwLen) / 2) :
                dwSpaces = (m_ECRList.GetStringLen() - dwLen);
            FillMemory(lzStringToPrint, dwSpaces, 0x20);
            CopyMemory(lzStringToPrint + dwSpaces, szStringToPrint, dwLen);
        }
    }

    InitCmd();
    // команда
    to_numeric(206, m_Cmd, 3, m_Len);   //PRINT
    // пароль
    to_char(OPERATOR_PASSWD, m_Cmd + m_Len, 4, m_Len);
    // устройство
    to_numeric(0, m_Cmd + m_Len, 1, m_Len);   
    // текст
    to_bchar(lzStringToPrint, m_Cmd + m_Len, strlen(lzStringToPrint), m_Len);

    CopyMemory(CommandBuffer[CommandBufferLen++], m_Cmd, m_Len);

    *ErrorCode = E_SUCCESS;
    return S_OK;
}
Example #21
0
STDMETHODIMP CECR::DoReturn(BSTR FirmID, BSTR ReturnText, LONG Quantity, LONG Price, LONG DepNo, LONG* ErrorCode)
{
    CW2A szGoodName(ReturnText);
    m_ECRList.Win1251ToCP866(szGoodName);

    // открыть документ
    OpenDocument(FirmID, DEP_NO, ErrorCode, ReturnDocument);

    if (*ErrorCode == E_SUCCESS)
    {
        PrintBuffer(FirmID, ErrorCode);
        if (*ErrorCode == E_SUCCESS)
        {
            InitCmd();
            // команда
            to_numeric(209, m_Cmd, 3, m_Len);   //SETITEM
            // пароль
            to_char(OPERATOR_PASSWD, m_Cmd + m_Len, 4, m_Len);
            // код отдела
            to_numeric(DepNo, m_Cmd + m_Len, 3, m_Len);   
            // штрих-код товара
            to_bchar("", m_Cmd + m_Len, 0, m_Len);
            // внутренний учетный код товара
            to_bchar("", m_Cmd + m_Len, 0, m_Len);
            // название товара
            to_bchar(szGoodName, m_Cmd + m_Len, strlen(szGoodName), m_Len);
            // цена товара
            to_money(Price, m_Cmd + m_Len, 10, m_Len);
            // количество товара
            to_numeric(Quantity, m_Cmd + m_Len, 8, m_Len);   
            // стоимость тары
            to_money(0, m_Cmd + m_Len, 10, m_Len);
            // размерность
            to_bchar("", m_Cmd + m_Len, 0, m_Len);
    
            m_RspLen = 5;
            m_ECRList.PassCmd(FirmID, m_Cmd, m_Len, m_Rsp, m_RspLen, ErrorCode);
        }
    }
    return S_OK;
}
Example #22
0
STDMETHODIMP CECR::OpenCashDrawer(LONG* ErrorCode)
{
    InitCmd();
    // команда
    to_numeric(236, m_Cmd, 3, m_Len);   //OPENDRAWER
    // пароль
    to_char(OPERATOR_PASSWD, m_Cmd + m_Len, 4, m_Len);
    // номер ящика
    to_numeric(0, m_Cmd + m_Len, 1, m_Len);   

    m_RspLen = 0;
    CECRConnection *pConnection = m_ECRList.GetDefault();
    if (pConnection == NULL)
    {
        *ErrorCode = E_NOT_FOUND;
        return S_OK;
    }
    m_ECRList.PassCmd(pConnection -> m_ID, m_Cmd, m_Len, m_Rsp, m_RspLen, ErrorCode);

    return S_OK;
}
Example #23
0
STDMETHODIMP CECR::CashdrawerState(LONG* DrawerState, LONG* ErrorCode)
{
    CECRConnection *pConnection = m_ECRList.GetDefault();
    if (pConnection == NULL)
    {
        *ErrorCode = E_NOT_FOUND;
        return S_OK;
    }
    InitCmd();
    // команда
    to_numeric(128, m_Cmd, 3, m_Len);   //GETDRAWERSTATUS
    // пароль
    to_char(OPERATOR_PASSWD, m_Cmd + m_Len, 4, m_Len);

    m_RspLen = 1;
    m_ECRList.PassCmd(pConnection -> m_ID, m_Cmd, m_Len, m_Rsp, m_RspLen, ErrorCode);
    if (*ErrorCode == E_SUCCESS)
        *DrawerState = (m_Rsp[0] == '1');
    
    return S_OK;
}
Example #24
0
STDMETHODIMP CECR::GetDateTime(BSTR FirmID, LONG* Year, LONG* Month, LONG* Day, LONG* Hour, LONG* Minute, LONG* Second, LONG* ErrorCode)
{
    InitCmd();
    // команда
    to_numeric(104, m_Cmd, 3, m_Len);   //GETTIME
    // пароль
    to_char(OPERATOR_PASSWD, m_Cmd + m_Len, 4, m_Len);

    m_RspLen = 14;
    m_ECRList.PassCmd(FirmID, m_Cmd, m_Len, m_Rsp, m_RspLen, ErrorCode);
    if (*ErrorCode == E_SUCCESS)
    {
        *Day	= from_numeric(m_Rsp, 2);
        *Month	= from_numeric(m_Rsp + 2, 2);
        *Year	= from_numeric(m_Rsp + 4, 4);

        *Hour	= from_numeric(m_Rsp + 8, 2);
        *Minute	= from_numeric(m_Rsp + 10, 2);
        *Second = from_numeric(m_Rsp + 12, 2);
    }
    return S_OK;
}
Example #25
0
STDMETHODIMP CECR::WaitForDrawerClose2(LONG InvertDrawerState, LONG* ErrorCode)
{
    CECRConnection *pConnection = m_ECRList.GetDefault();
    if (pConnection == NULL)
    {
        *ErrorCode = E_NOT_FOUND;
        return S_OK;
    }

    LONG DrawerResult;

    InitCmd();
    // команда
    to_numeric(128, m_Cmd, 3, m_Len);   //GETDRAWERSTATUS
    // пароль
    to_char(OPERATOR_PASSWD, m_Cmd + m_Len, 4, m_Len);
    m_RspLen = 1;
    do	
    {
        m_ECRList.PassCmd(pConnection -> m_ID, m_Cmd, m_Len, m_Rsp, m_RspLen, ErrorCode);

        if (InvertDrawerState)
        {
            // данные о состоянии ДЯ инвертируются
            DrawerResult = m_Rsp[0] == '1' ? 0 : 1;
        }
        else
        {
            // данные о состоянии ДЯ НЕ инвертируются
            DrawerResult = m_Rsp[0] == '1' ? 1 : 0;
        }
        if (DrawerResult) Sleep(1000);

    }
    while((*ErrorCode == E_SUCCESS)&&(DrawerResult == 1));
    
    return S_OK;
}
Example #26
0
/**
 * @brief initialize
 */
int  TraverseChildInit()
{
  InitCmd();
  return 0;
}
Example #27
0
STDMETHODIMP CECR::DoCloseEx(BSTR FirmID, LONG MoneyCash, LONG MoneyClearing, LONG MoneyPrepay, BYTE ReturnDocument, LONG* ErrorCode)
{
    if (MoneyCash)
    {
        InitCmd();
        // команда
        to_numeric(214, m_Cmd, 3, m_Len);   //SETTENDER
        // пароль
        to_char(OPERATOR_PASSWD, m_Cmd + m_Len, 4, m_Len);
        // тип оплаты
        to_numeric(0, m_Cmd + m_Len, 2, m_Len);   
        // сумма
        to_smoney(MoneyCash, m_Cmd + m_Len, 10, m_Len);   

        m_RspLen = 11;
        m_ECRList.PassCmd(FirmID, m_Cmd, m_Len, m_Rsp, m_RspLen, ErrorCode);

        if (*ErrorCode != E_SUCCESS)
            return S_OK;
    }

    if (MoneyClearing)
    {
        InitCmd();
        // команда
        to_numeric(214, m_Cmd, 3, m_Len);   //SETTENDER
        // пароль
        to_char(OPERATOR_PASSWD, m_Cmd + m_Len, 4, m_Len);
        // тип оплаты
        to_numeric(2, m_Cmd + m_Len, 2, m_Len);   
        // сумма
        to_smoney(MoneyClearing, m_Cmd + m_Len, 10, m_Len);   

        m_RspLen = 11;
        m_ECRList.PassCmd(FirmID, m_Cmd, m_Len, m_Rsp, m_RspLen, ErrorCode);

        if (*ErrorCode != E_SUCCESS)
            return S_OK;
    }

    if (MoneyPrepay)
    {
        InitCmd();
        // команда
        to_numeric(214, m_Cmd, 3, m_Len);   //SETTENDER
        // пароль
        to_char(OPERATOR_PASSWD, m_Cmd + m_Len, 4, m_Len);
        // тип оплаты
        to_numeric(2, m_Cmd + m_Len, 2, m_Len);   
        // сумма
        to_smoney(MoneyClearing, m_Cmd + m_Len, 10, m_Len);   

        m_RspLen = 11;
        m_ECRList.PassCmd(FirmID, m_Cmd, m_Len, m_Rsp, m_RspLen, ErrorCode);

        if (*ErrorCode != E_SUCCESS)
            return S_OK;
    }

    // обрезать чек
    Cut(FirmID, 1, ErrorCode);
/*
    InitCmd();
    // команда
    to_numeric(215, m_Cmd, 3, m_Len);   //CLOSE
    // пароль
    to_char(OPERATOR_PASSWD, m_Cmd + m_Len, 4, m_Len);
    // обрезать чек
    to_numeric(1, m_Cmd + m_Len, 1, m_Len);   
    m_RspLen = 0;
    m_ECRList.PassCmd(FirmID, m_Cmd, m_Len, m_Rsp, m_RspLen, ErrorCode);
    if (*ErrorCode == E_SUCCESS)
        ClearPrintBuffer();
*/

    return S_OK;
}
Example #28
0
int	main(int argc, char *argv[])
{
  int Pid;
  int c;
  int rvExist1=0, rvExist2=0;
  PGresult *result;
  char *NewDir=".";
  char *AgentName = "ununpack";
  char *AgentARSName = "ununpack_ars";
  char *agent_desc = "Unpacks archives (iso, tar, etc)";
  int   Recurse=0;
  int   ars_pk = 0;
  int   user_pk = 0;
  long  Pfile_size = 0;
  char *ListOutName=NULL;
  char *Fname = NULL;
  char *FnameCheck = NULL;
  char *COMMIT_HASH;
  char *VERSION;
  char agent_rev[PATH_MAX];
  struct stat Stat;

  /* connect to the scheduler */
  fo_scheduler_connect(&argc, argv, &pgConn);

  while((c = getopt(argc,argv,"ACc:d:FfHhL:m:PQiqRr:T:t:U:VvXx")) != -1)
  {
    switch(c)
    {
      case 'A':	SetContainerArtifact=0; break;
      case 'C':	ForceContinue=1; break;
      case 'c':	break;  /* handled by fo_scheduler_connect() */
      case 'd':	
        /* if there is a %U in the path, substitute a unique ID */
        NewDir=PathCheck(optarg);
        break;
      case 'F':	UseRepository=1; break;
      case 'f':	ForceDuplicate=1; break;
      case 'L':	ListOutName=optarg; break;
      case 'm':
        MaxThread = atoi(optarg);
        if (MaxThread < 1) MaxThread=1;
        break;
      case 'P':	PruneFiles=1; break;
      case 'R':	Recurse=-1; break;
      case 'r':	Recurse=atoi(optarg); break;
      case 'i':
        if (!IsExe("dpkg-source",Quiet))
          LOG_WARNING("dpkg-source is not available on this system.  This means that debian source packages will NOT be unpacked.");
        SafeExit(0);
        break; /* never reached */
      case 'Q':
        UseRepository=1;

        user_pk = fo_scheduler_userID(); /* get user_pk for user who queued the agent */

        /* Get the upload_pk from the scheduler */
        if((Upload_Pk = fo_scheduler_next()) == NULL) SafeExit(0);
        break;
      case 'q':	Quiet=1; break;
      case 'T':
        memset(REP_GOLD,0,sizeof(REP_GOLD));
        strncpy(REP_GOLD,optarg,sizeof(REP_GOLD)-1);
        break;
      case 't':
        memset(REP_FILES,0,sizeof(REP_FILES));
        strncpy(REP_FILES,optarg,sizeof(REP_FILES)-1);
        break;
      case 'U':	
        UseRepository = 1;
        Recurse = -1;
        Upload_Pk = optarg; 
        break;
      case 'V': printf("%s", BuildVersion);SafeExit(0);
      case 'v':	Verbose++; break;
      case 'X':	UnlinkSource=1; break;
      case 'x':	UnlinkAll=1; break;
      default:
        Usage(argv[0], BuildVersion);
        SafeExit(25);
    }
  }

  /* Open DB and Initialize CMD table */
  if (UseRepository) 
  {
    /* Check Permissions */
    if (GetUploadPerm(pgConn, atoi(Upload_Pk), user_pk) < PERM_WRITE)
    {
      LOG_ERROR("You have no update permissions on upload %s", Upload_Pk);
      SafeExit(100);
    }
        
    COMMIT_HASH = fo_sysconfig(AgentName, "COMMIT_HASH");
    VERSION = fo_sysconfig(AgentName, "VERSION");
    sprintf(agent_rev, "%s.%s", VERSION, COMMIT_HASH);
    /* Get the unpack agent key */
    agent_pk = fo_GetAgentKey(pgConn, AgentName, atoi(Upload_Pk), agent_rev,agent_desc);

    InitCmd();

    /* Make sure ars table exists */
    if (!fo_CreateARSTable(pgConn, AgentARSName)) SafeExit(0);

    /* Has this user previously unpacked this upload_pk successfully?
     *    In this case we are done.  No new ars record is needed since no
     *    processing is initiated.
     * The unpack version is ignored.
     */
    snprintf(SQL,MAXSQL,
        "SELECT ars_pk from %s where upload_fk='%s' and ars_success=TRUE",
           AgentARSName, Upload_Pk);
    result =  PQexec(pgConn, SQL);
    if (fo_checkPQresult(pgConn, result, SQL, __FILE__, __LINE__)) SafeExit(101);

    if (PQntuples(result) > 0) /* if there is a value */
    {  
      PQclear(result);
      LOG_WARNING("Upload_pk %s, has already been unpacked.  No further action required", 
              Upload_Pk)
      SafeExit(0);
    }
    PQclear(result);

    /* write the unpack_ars start record */
    ars_pk = fo_WriteARS(pgConn, ars_pk, atoi(Upload_Pk), agent_pk, AgentARSName, 0, 0);

    /* Get Pfile path and Pfile_Pk, from Upload_Pk */
  snprintf(SQL,MAXSQL,
        "SELECT pfile.pfile_sha1 || '.' || pfile.pfile_md5 || '.' || pfile.pfile_size AS pfile, pfile_fk, pfile_size FROM upload INNER JOIN pfile ON upload.pfile_fk = pfile.pfile_pk WHERE upload.upload_pk = '%s'", 
           Upload_Pk);
    result =  PQexec(pgConn, SQL);
    if (fo_checkPQresult(pgConn, result, SQL, __FILE__, __LINE__)) SafeExit(102);

    if (PQntuples(result) > 0) /* if there is a value */
    {  
      Pfile = strdup(PQgetvalue(result,0,0));
      Pfile_Pk = strdup(PQgetvalue(result,0,1));
      Pfile_size = atol(PQgetvalue(result, 0, 2));
      if (Pfile_size == 0)
      {  
        PQclear(result);
        LOG_WARNING("Uploaded file (Upload_pk %s), is zero length.  There is nothing to unpack.", 
                      Upload_Pk)
        SafeExit(0);
      }

      PQclear(result);
    }

    // Determine if uploadtree records should go into a separate table.
    // If the input file size is > 500MB, then create a separate uploadtree_{upload_pk} table
    // that inherits from the master uploadtree table.
    // Save uploadtree_tablename, it will get written to upload.uploadtree_tablename later.
    if (Pfile_size > 500000000)
    {
      sprintf(uploadtree_tablename, "uploadtree_%s", Upload_Pk);
      if (!fo_tableExists(pgConn, uploadtree_tablename))
      {
        snprintf(SQL,MAXSQL,"CREATE TABLE %s (LIKE uploadtree INCLUDING DEFAULTS INCLUDING CONSTRAINTS INCLUDING INDEXES); ALTER TABLE %s ADD CONSTRAINT %s CHECK (upload_fk=%s); ALTER TABLE %s INHERIT uploadtree", 
               uploadtree_tablename, uploadtree_tablename, uploadtree_tablename, Upload_Pk, uploadtree_tablename);
        PQsetNoticeProcessor(pgConn, SQLNoticeProcessor, SQL);  // ignore notice about implicit primary key index creation
        result =  PQexec(pgConn, SQL);
        // Ignore postgres notice about creating an implicit index
        if (PQresultStatus(result) != PGRES_NONFATAL_ERROR)
          if (fo_checkPQcommand(pgConn, result, SQL, __FILE__, __LINE__)) SafeExit(103);
        PQclear(result);
      }
    }
    else
      strcpy(uploadtree_tablename, "uploadtree_a");

  }

  CheckCommands(Quiet);
  if (NewDir) MkDir(NewDir);
  if (Verbose) { fclose(stderr) ; stderr=stdout; } /* don't interlace! */
  if (ListOutName != NULL)
  {
    if ((ListOutName[0]=='-') && (ListOutName[1]=='\0'))
      ListOutFile=stdout;
    else ListOutFile = fopen(ListOutName,"w");
    if (!ListOutFile)
    {
      LOG_ERROR("pfile %s Unable to write to %s\n",Pfile_Pk,ListOutName)
      SafeExit(104);
    }
    else
    {
      /* Start the file */
      fputs("<xml tool=\"ununpack\" ",ListOutFile);
      fputs("version=\"",ListOutFile);
      fputs(Version,ListOutFile);
      fputs("\" ",ListOutFile);
      fputs("compiled_date=\"",ListOutFile);
      fputs(__DATE__,ListOutFile);
      fputs(" ",ListOutFile);
      fputs(__TIME__,ListOutFile);
      fputs("\"",ListOutFile);
      fputs(">\n",ListOutFile);
    }
    /* Problem: When parallel processing, the XML may be generated out
	   of order.  Solution?  When using XML, only use 1 thread. */
    MaxThread=1;
  }

  // Set ReunpackSwitch if the uploadtree records are missing from the database.
  if (!ReunpackSwitch && UseRepository)
  {
    snprintf(SQL,MAXSQL,"SELECT uploadtree_pk FROM uploadtree WHERE upload_fk=%s limit 1;",Upload_Pk);
    result =  PQexec(pgConn, SQL);
    if (fo_checkPQresult(pgConn, result, SQL, __FILE__, __LINE__)) SafeExit(105);
    if (PQntuples(result) == 0) ReunpackSwitch=1;
    PQclear(result);
  }

  /*** process files from command line ***/
  for( ; optind<argc; optind++)
  {
    CksumFile *CF=NULL;
    Cksum *Sum;
    int i;
    if (Fname) { free(Fname); Fname=NULL; }
    if (ListOutName != NULL)
    {
      fprintf(ListOutFile,"<source source=\"%s\" ",argv[optind]);
      if (UseRepository && !fo_RepExist(REP_FILES,argv[optind]))
      {
        /* make sure the source exists in the src repository */
        if (fo_RepImport(argv[optind],REP_FILES,argv[optind],1) != 0)
        {
          LOG_ERROR("Failed to import '%s' as '%s' into the repository",argv[optind],argv[optind])
          SafeExit(106);
        }
      }
    }

    if (UseRepository)
    {
      if (fo_RepExist(REP_FILES,argv[optind]))
      {
        Fname=fo_RepMkPath(REP_FILES,argv[optind]);
      }
      else if (fo_RepExist(REP_GOLD,argv[optind]))
      {
        Fname=fo_RepMkPath(REP_GOLD,argv[optind]);
        if (fo_RepImport(Fname,REP_FILES,argv[optind],1) != 0)
        {
          LOG_ERROR("Failed to import '%s' as '%s' into the repository",Fname,argv[optind])
          SafeExit(107);
        }
      }

      if (Fname)
      {
        FnameCheck = Fname;
        CF = SumOpenFile(Fname);
      }
      else
      {
        LOG_ERROR("NO file unpacked.  File %s does not exist either in GOLD or FILES", Pfile);
        SafeExit(108);
      }
      /* else: Fname is NULL and CF is NULL */
    }
    else 
    {
      FnameCheck = argv[optind];
      CF = SumOpenFile(argv[optind]);
    }

    /* Check file to unpack.  Does it exist?  Is it zero length? */
    if (stat(FnameCheck,&Stat)) 
    {
      LOG_ERROR("File to unpack is unavailable: %s, error: %s", Fname, strerror(errno));
      SafeExit(109);
    }
    else
    if (Stat.st_size < 1)
    {
      LOG_WARNING("File to unpack is empty: %s", Fname);
      SafeExit(110);
    }

    if (ListOutFile)
    {
      if (CF)
      {
        Sum = SumComputeBuff(CF);
        SumCloseFile(CF);
        if (Sum)
        {
          fputs("fuid=\"",ListOutFile);
          for(i=0; i<20; i++)
          { fprintf(ListOutFile,"%02X",Sum->SHA1digest[i]); }
          fputs(".",ListOutFile);
          for(i=0; i<16; i++)
          { fprintf(ListOutFile,"%02X",Sum->MD5digest[i]); }
          fputs(".",ListOutFile);
          fprintf(ListOutFile,"%Lu",(long long unsigned int)Sum->DataLen);
          fputs("\" ",ListOutFile);
          free(Sum);
        } /* if Sum */
      } /* if CF */
      else /* file too large to mmap (probably) */
      {
        FILE *Fin;
        Fin = fopen(argv[optind],"rb");
        if (Fin)
        {
          Sum = SumComputeFile(Fin);
          if (Sum)
          {
            fputs("fuid=\"",ListOutFile);
            for(i=0; i<20; i++)
            { fprintf(ListOutFile,"%02X",Sum->SHA1digest[i]); }
            fputs(".",ListOutFile);
            for(i=0; i<16; i++)
            { fprintf(ListOutFile,"%02X",Sum->MD5digest[i]); }
            fputs(".",ListOutFile);
            fprintf(ListOutFile,"%Lu",(long long unsigned int)Sum->DataLen);
            fputs("\" ",ListOutFile);
            free(Sum);
          }
          fclose(Fin);
        }
      } /* else no CF */
      fprintf(ListOutFile,">\n"); /* end source XML */
    }
    if (Fname)	TraverseStart(Fname,"called by main via args",NewDir,Recurse);
    else		TraverseStart(argv[optind],"called by main",NewDir,Recurse);
    if (ListOutName != NULL) fprintf(ListOutFile,"</source>\n");
  } /* end for */

  /* free memory */
  if (Fname) { free(Fname); Fname=NULL; }

  /* process pfile from scheduler */
  if (Pfile)
  {
    if (0 == (rvExist1 = fo_RepExist2(REP_FILES,Pfile)))
    {
      Fname=fo_RepMkPath(REP_FILES,Pfile);
    }
    else if (0 == (rvExist2 = fo_RepExist2(REP_GOLD,Pfile)))
    {
      Fname=fo_RepMkPath(REP_GOLD,Pfile);
      if (fo_RepImport(Fname,REP_FILES,Pfile,1) != 0)
      {
        LOG_ERROR("Failed to import '%s' as '%s' into the repository",Fname,Pfile)
        SafeExit(111);
      }
    }
    if (Fname)
    {
      TraverseStart(Fname,"called by main via env",NewDir,Recurse);
      free(Fname);
      Fname=NULL;
    }
    else
    {
      LOG_ERROR("NO file unpacked!");
      if (rvExist1 > 0)
      {
        Fname=fo_RepMkPath(REP_FILES, Pfile);
        LOG_ERROR("Error is %s for %s", strerror(rvExist1), Fname);
      }
      if (rvExist2 > 0)
      {
        Fname=fo_RepMkPath(REP_GOLD, Pfile);
        LOG_ERROR("Error is %s for %s", strerror(rvExist2), Fname);
      }
      SafeExit(112);
    }
  }

  /* recurse on all the children */
  if (Thread > 0) do
  {
    Pid = ParentWait();
    Thread--;
    if (Pid >= 0)
    {
      if (!Queue[Pid].ChildEnd)
      {
        /* copy over data */
        if (Recurse > 0)
          Traverse(Queue[Pid].ChildRecurse,NULL,"called by wait",NULL,Recurse-1,&Queue[Pid].PI);
        else if (Recurse < 0)
          Traverse(Queue[Pid].ChildRecurse,NULL,"called by wait",NULL,Recurse,&Queue[Pid].PI);
      }
    }
  } while(Pid >= 0);

  if (MagicCookie) magic_close(MagicCookie);
  if (ListOutFile)
  {
    fprintf(ListOutFile,"<summary files_regular=\"%d\" files_compressed=\"%d\" artifacts=\"%d\" directories=\"%d\" containers=\"%d\" />\n",
        TotalFiles,TotalCompressedFiles,TotalArtifacts,
        TotalDirectories,TotalContainers);
    fputs("</xml>\n",ListOutFile);
  }
  if (pgConn)
  {
    /* If it completes, mark it! */
    if (Upload_Pk)
    {
      snprintf(SQL,MAXSQL,"UPDATE upload SET upload_mode = (upload_mode | (1<<5)), uploadtree_tablename='%s' WHERE upload_pk = '%s';",uploadtree_tablename, Upload_Pk);
      result =  PQexec(pgConn, SQL); /* UPDATE upload */
      if (fo_checkPQcommand(pgConn, result, SQL, __FILE__ ,__LINE__)) SafeExit(113);
      PQclear(result);

      snprintf(SQL,MAXSQL,"UPDATE %s SET realparent = getItemParent(uploadtree_pk) WHERE upload_fk = '%s'",uploadtree_tablename, Upload_Pk);
      result =  PQexec(pgConn, SQL); /* UPDATE uploadtree */
      if (fo_checkPQcommand(pgConn, result, SQL, __FILE__ ,__LINE__)) SafeExit(114);
      PQclear(result);
    }

    if (ars_pk) fo_WriteARS(pgConn, ars_pk, atoi(Upload_Pk), agent_pk, AgentARSName, 0, 1);
  }
  if (ListOutFile && (ListOutFile != stdout))
  {
    fclose(ListOutFile);
  }

  if (UnlinkAll && MaxThread > 1)
  {
    /* Delete temporary files */
    if (strcmp(NewDir, ".")) RemoveDir(NewDir);
  }
 
  SafeExit(0);
  return(0);  // never executed but makes the compiler happy
} 
Example #29
0
TextManager::TextManager():
    m_Language( "" )
{
    InitCmd();
}
Example #30
0
/*
** ===================================================================
**     Method      : UFFS_ParseCommand 
**     Description :
**         Shell Command Line parser.
**     Parameters  :
**         NAME            - DESCRIPTION
**       * cmd             - Pointer to command string
**       * handled         - Pointer to variable which tells if
**                           the command has been handled or not
**       * io              - Pointer to I/O structure
**     Returns     :
**         ---             - Error code
** ===================================================================
*/
byte UFFS_ParseCommand(const unsigned char *cmd, bool *handled, const CLS1_StdIOType *io)
{
	if (UTIL1_strcmp((char*)cmd, CLS1_CMD_HELP) == 0
			|| UTIL1_strcmp((char*)cmd, "UFFS help") == 0)
	{
		*handled = TRUE;
		return PrintHelp(io);
	}
	else if ((UTIL1_strcmp((char*)cmd, CLS1_CMD_STATUS) == 0)
			|| (UTIL1_strcmp((char*)cmd, "UFFS status") == 0))
	{
		*handled = TRUE;
		return PrintStatus(io);
	}
	else if ((UTIL1_strcmp((char*)cmd, CLS1_CMD_STATUS) == 0)
			|| (UTIL1_strcmp((char*)cmd, "UFFS init") == 0))
	{
		*handled = TRUE;
		return InitCmd(io);
	}
	else if ((UTIL1_strcmp((char*)cmd, CLS1_CMD_STATUS) == 0)
			|| (UTIL1_strcmp((char*)cmd, "UFFS uninit") == 0))
	{
		*handled = TRUE;
		return UninitCmd(io);
	}
	else if (UTIL1_strncmp((char*)cmd, "UFFS cd", sizeof("UFFS cd")-1) == 0)
	{
		*handled = TRUE;
		return CdCmd(cmd + sizeof("UFFS"), io);
	}
	else if (UTIL1_strncmp((char*)cmd, "UFFS dir", sizeof("UFFS dir")-1) == 0)
	{
		*handled = TRUE;
		return DirCmd(cmd + sizeof("UFFS"), io);
	}
	else if (UTIL1_strncmp((char*)cmd, "UFFS delete", sizeof("UFFS delete")-1) == 0)
	{
		*handled = TRUE;
		return DeleteCmd(cmd + sizeof("UFFS"), io);
	}
	else if (UTIL1_strncmp((char*)cmd, "UFFS mkdir", sizeof("UFFS mkdir")-1) == 0)
	{
		*handled = TRUE;
		return MkdirCmd(cmd + sizeof("UFFS"), io);
	}
	else if (UTIL1_strncmp((char*)cmd, "UFFS format", sizeof("UFFS format")-1) == 0)
	{
		*handled = TRUE;
		return FormatCmd(cmd + sizeof("UFFS"), io);
	}
	else if (UTIL1_strncmp((char*)cmd, "UFFS rename", sizeof("UFFS rename")-1) == 0)
	{
		*handled = TRUE;
		return RenameCmd(cmd + sizeof("UFFS"), io);
	}
#ifdef FAT_SUPPORT
	else if (UTIL1_strncmp((char*)cmd, "UFFS copy", sizeof("UFFS copy")-1) == 0) 
	{
	    *handled = TRUE;
	    return CopyCmd(cmd+sizeof("UFFS"), io);
	}
#endif
	else if (UTIL1_strcmp((char*)cmd, "UFFS diskinfo") == 0)
	{
		*handled = TRUE;
		return UFFS_PrintDiskInfo(io);
	}
	else if (UTIL1_strcmp((char*)cmd, "UFFS benchmark") == 0)
	{
		*handled = TRUE;
		return UFFS_Benchmark(cmd + sizeof("UFFS"), io);
	}
	return ERR_OK;
}