/* Copyright (C) 2016-2020, Dirk Krause SPDX-License-Identifier: BSD-3-Clause */ /* WARNING: This file was generated by the dkct program (see http://dktools.sourceforge.net/ for details). Changes you make here will be lost if dkct is run again! You should modify the original source and run dkct on it. Original source: WxpqdicFrame.wxc */ /** @file WxpqdicFrame.cpp The WxpqdicFrame module. */ #line 419 "WxpqdicFrame.wxc" #include "dk4conf.h" #ifndef DK4_SIZEOF_WXCHAR #ifndef DK4WXCS_H_INCLUDED #include "dk4wxcs.h" #endif #endif #include "wxpqdic.h" #include "dk4user.h" #include "dk4enc.h" #include "dk4strd.h" #include "dk4rec.h" #include "dk4str8.h" #include "dk4strx.h" #include "dk4recwx.h" #include "dk4maasz.h" #include "dk4mai8ddu.h" #include "dk4mai8dii.h" #include "dk4mao8d.h" #include "dk4maowd.h" #include "dk4numco.h" #include "gui-img/shared/toolbar/exit-program.xpm" #include "gui-img/shared/toolbar/run-conversion.xpm" #include "dk4verswx.h" #if !defined(__WXMSW__) #include "gui-img/icons/dkicon.xpm" #endif #line 456 "WxpqdicFrame.wxc" /* __CHANGE__ 017: Add further events. */ /* __CHANGE__ 008: Remove OnIdle if no idle processing required. */ #if wxCHECK_VERSION(3,0,0) wxBEGIN_EVENT_TABLE(WxpqdicFrame,wxFrame) #else BEGIN_EVENT_TABLE(WxpqdicFrame,wxFrame) #endif EVT_MENU(WxpqdicFrame_View_Update, WxpqdicFrame::OnRun) EVT_MENU(WxpqdicFrame_Quit, WxpqdicFrame::OnQuit) EVT_MENU(WxpqdicFrame_Help_About, WxpqdicFrame::OnAbout) EVT_MENU(WxpqdicFrame_Help_Contents, WxpqdicFrame::OnHelpContents) EVT_TIMER(WxpqdicFrame_Timer, WxpqdicFrame::OnTimer) EVT_IDLE(WxpqdicFrame::OnIdle) #if wxCHECK_VERSION(3,0,0) wxEND_EVENT_TABLE() #else END_EVENT_TABLE() #endif static const wxChar versionNumber[] = { DKT_VERSION_WX }; #if __GNUC__ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wmissing-field-initializers" #endif static const wxCmdLineEntryDesc wxpqdic_cmd_line_entries[] = { { wxCMD_LINE_OPTION, wxT_2("h"), wxT_2("host"), wxT_2("Host to connect to."), wxCMD_LINE_VAL_STRING, 0 }, { wxCMD_LINE_OPTION, wxT_2("p"), wxT_2("port"), wxT_2("Port number to connect to."), wxCMD_LINE_VAL_NUMBER, 0 }, { wxCMD_LINE_OPTION, wxT_2("l"), wxT_2("local-port"), wxT_2("Local port number to use."), wxCMD_LINE_VAL_NUMBER, 0 }, { wxCMD_LINE_OPTION, wxT_2("q"), wxT_2("queue"), wxT_2("Queue name to check."), wxCMD_LINE_VAL_STRING, 0 }, { wxCMD_LINE_OPTION, wxT_2("u"), wxT_2("user"), wxT_2("User name to check."), wxCMD_LINE_VAL_STRING, 0 }, { wxCMD_LINE_OPTION, wxT_2("i"), wxT_2("interval"), wxT_2("Time interval for automatic update."), wxCMD_LINE_VAL_NUMBER, 0 }, { wxCMD_LINE_OPTION, wxT_2("a"), wxT_2("ascii"), wxT_2("Remote host uses ASCII encoding, not UTF-8."), wxCMD_LINE_VAL_NONE, 0 }, { wxCMD_LINE_NONE } }; #if __GNUC__ #pragma GCC diagnostic pop #endif /** Key names for preferences. */ static const wxChar * const wxpqdic_pref_key_names[] = { /* 0 */ wxT("printqd.host"), /* 1 */ wxT("printqd.port"), /* 2 */ wxT("printqd.queue"), /* 3 */ wxT("printqd.interval"), /* 4 */ wxT("printqd.local"), /* 5 */ wxT("printqd.encoding"), NULL #line 566 "WxpqdicFrame.wxc" }; /** Constant 8-bit strings, not localized. */ static const char * const wxpqdic_kw[] = { /* 0 */ "\n", /* 1 */ " ", /* 2 */ "info", NULL #line 587 "WxpqdicFrame.wxc" }; #line 591 "WxpqdicFrame.wxc" WxpqdicFrame::WxpqdicFrame( int wxid, Dk4WxApplicationHelper *applicationHelper, Dk4WxHelpController *hc, int argc, wxChar **argv, wxChar const * const *localizedTexts, wxChar const * const *nlWx, dkChar const * const *nlDk, bool bSocketsInitialized, dk4_er_t *psockerr ) : Dk4WxFrame(nlWx[0], applicationHelper, hc, wxid), sHostname(wxT("")), sQueuename(wxT("")), sUsername(wxT("")), cBlack(0, 0, 0), cRed(127, 0, 0), cGreen(0, 127, 0), timer(this, WxpqdicFrame_Timer) { /* __CHANGE__ 012: Add further local variables. */ /* __CHANGE__ 012: Initialize further local variables. */ sTexts = localizedTexts; sNlWx = nlWx; sNlDk = nlDk; #if defined(__WXMSW__) wxIcon wxpqdic_icon(sNlWx[4]); #else wxIcon wxpqdic_icon(xpm_dkicon); #endif /* __CHANGE__ 011: Initialize further class members. */ bSockInit = bSocketsInitialized; DK4_MEMCPY(&sockerr, psockerr, sizeof(dk4_er_t)); pHostname = NULL; pQueuename = NULL; pUsername = NULL; pRequest = NULL; szRequest = (size_t)0UL; lUpdateInterval = 30L; lWaitResponse = 1L; usPortnumber = 9100; usLocalPort = 9100; bIsUtf8 = true; bFirstIdle = true; bFirstResponse = true; bIsInitialized = false; copyArgc = argc; copyArgv = argv; sock = INVALID_SOCKET; iState = WXPQDIC_STATE_OK; tRequestSended = (dk4_time_t)0UL; szResponse = sizeof(bResponse); DK4_MEMRES(&(aAddresses[0]), (2*sizeof(dk4_sockaddr_storage_t))); dkctGUILayoutOK = false; dkctGUIContentsPanel = NULL; mainSizer = NULL; mbMain = NULL; tbMain = NULL; menuFile = NULL; menuView = NULL; menuHelp = NULL; miFileExit = NULL; miViewUpdate = NULL; miHelpAbout = NULL; miHelpContents = NULL; verticalSizer = NULL; contentsSizer = NULL; lLimit = NULL; tLimit = NULL; lUsed = NULL; tUsed = NULL; lAccount = NULL; tAccount = NULL; lAllowed = NULL; tAllowed = NULL; lStatus = NULL; bUpdate = NULL; bExit = NULL; dkctGUIContentsPanel = new wxPanel(this); if(!(dkctGUIContentsPanel)) { goto dkctGUILayoutFinished; } #if wxUSE_MENUS mbMain = new wxMenuBar( ); if(!(mbMain)) { goto dkctGUILayoutFinished; } menuFile = new wxMenu( ); if(!(menuFile)) { goto dkctGUILayoutFinished; } miFileExit = menuFile->Append( WxpqdicFrame_Quit, sTexts[1], sTexts[2] ); if(!(miFileExit)) { goto dkctGUILayoutFinished; } mbMain->Append(menuFile, sTexts[0]); menuView = new wxMenu( ); if(!(menuView)) { goto dkctGUILayoutFinished; } miViewUpdate = menuView->Append( WxpqdicFrame_View_Update, sTexts[23], sTexts[24] ); if(!(miViewUpdate)) { goto dkctGUILayoutFinished; } mbMain->Append(menuView, sTexts[22]); menuHelp = new wxMenu( ); if(!(menuHelp)) { goto dkctGUILayoutFinished; } miHelpAbout = menuHelp->Append( WxpqdicFrame_Help_About, sTexts[4], sTexts[5] ); if(!(miHelpAbout)) { goto dkctGUILayoutFinished; } miHelpContents = menuHelp->Append( WxpqdicFrame_Help_Contents, sTexts[6], sTexts[7] ); if(!(miHelpContents)) { goto dkctGUILayoutFinished; } mbMain->Append(menuHelp, sTexts[3]); SetMenuBar(mbMain); #endif #if wxUSE_TOOLBAR tbMain = new wxToolBar( this, wxID_ANY ); if(!(tbMain)) { goto dkctGUILayoutFinished; } bUpdate = tbMain->AddTool( WxpqdicFrame_View_Update, sTexts[25], xpm_run_conversion, wxNullBitmap, wxITEM_NORMAL, sTexts[24] ); if(!(bUpdate)) { goto dkctGUILayoutFinished; } bExit = tbMain->AddTool( WxpqdicFrame_Quit, sTexts[26], xpm_exit_program, wxNullBitmap, wxITEM_NORMAL, sTexts[2] ); if(!(bExit)) { goto dkctGUILayoutFinished; } tbMain->Realize(); SetToolBar(tbMain); #endif mainSizer = new wxBoxSizer( wxHORIZONTAL ); if(!(mainSizer)) { goto dkctGUILayoutFinished; } mainSizer->Add(10, 10, 0); verticalSizer = new wxBoxSizer( wxVERTICAL ); if(!(verticalSizer)) { goto dkctGUILayoutFinished; } verticalSizer->Add(10, 10, 0); contentsSizer = new wxGridBagSizer( 2, 2 ); if(!(contentsSizer)) { goto dkctGUILayoutFinished; } lLimit = new wxStaticText( dkctGUIContentsPanel, wxID_ANY, sTexts[13] ); if(!(lLimit)) { goto dkctGUILayoutFinished; } contentsSizer->Add( lLimit, wxGBPosition(0, 0), wxGBSpan(1, 1), wxALIGN_RIGHT ); tLimit = new wxStaticText( dkctGUIContentsPanel, wxID_ANY, sTexts[14] ); if(!(tLimit)) { goto dkctGUILayoutFinished; } contentsSizer->Add( tLimit, wxGBPosition(0, 1), wxGBSpan(1, 1) ); lUsed = new wxStaticText( dkctGUIContentsPanel, wxID_ANY, sTexts[15] ); if(!(lUsed)) { goto dkctGUILayoutFinished; } contentsSizer->Add( lUsed, wxGBPosition(1, 0), wxGBSpan(1, 1), wxALIGN_RIGHT ); tUsed = new wxStaticText( dkctGUIContentsPanel, wxID_ANY, sTexts[27] ); if(!(tUsed)) { goto dkctGUILayoutFinished; } contentsSizer->Add( tUsed, wxGBPosition(1, 1), wxGBSpan(1, 1) ); contentsSizer->Add(5, 5, wxGBPosition(2, 0), wxGBSpan(1, 1)); lAccount = new wxStaticText( dkctGUIContentsPanel, wxID_ANY, sTexts[17] ); if(!(lAccount)) { goto dkctGUILayoutFinished; } contentsSizer->Add( lAccount, wxGBPosition(3, 0), wxGBSpan(1, 1), wxALIGN_RIGHT ); tAccount = new wxStaticText( dkctGUIContentsPanel, wxID_ANY, sTexts[16] ); if(!(tAccount)) { goto dkctGUILayoutFinished; } contentsSizer->Add( tAccount, wxGBPosition(3, 1), wxGBSpan(1, 1) ); contentsSizer->Add(5, 5, wxGBPosition(4, 0), wxGBSpan(1, 1)); lAllowed = new wxStaticText( dkctGUIContentsPanel, wxID_ANY, sTexts[18] ); if(!(lAllowed)) { goto dkctGUILayoutFinished; } contentsSizer->Add( lAllowed, wxGBPosition(5, 0), wxGBSpan(1, 1), wxALIGN_RIGHT ); tAllowed = new wxStaticText( dkctGUIContentsPanel, wxID_ANY, sTexts[27] ); if(!(tAllowed)) { goto dkctGUILayoutFinished; } contentsSizer->Add( tAllowed, wxGBPosition(5, 1), wxGBSpan(1, 1) ); contentsSizer->Add(5, 5, wxGBPosition(6, 0), wxGBSpan(1, 1)); lStatus = new wxStaticText( dkctGUIContentsPanel, wxID_ANY, sTexts[21] ); if(!(lStatus)) { goto dkctGUILayoutFinished; } contentsSizer->Add( lStatus, wxGBPosition(7, 0), wxGBSpan(1, 2) ); verticalSizer->Add( contentsSizer ); verticalSizer->Add(10, 10, 0); mainSizer->Add( verticalSizer, 1, wxGROW ); mainSizer->Add(10, 10, 0); dkctGUIContentsPanel->SetSizer(mainSizer); SetIcon(wxpqdic_icon); dkctGUILayoutOK = true; dkctGUILayoutFinished: #if wxUSE_STATUSBAR if(dkctGUILayoutOK) { CreateStatusBar(1); SetStatusText(sTexts[8]); } #endif if(dkctGUILayoutOK) { mainSizer->Fit(this); mainSizer->SetSizeHints(this); } #line 653 "WxpqdicFrame.wxc" if(dkctGUILayoutOK) { SetTitle(nlWx[0]); } /* __CHANGE__ 012: Release resources allocated by local variables. */ } #line 663 "WxpqdicFrame.wxc" WxpqdicFrame::~WxpqdicFrame() { /* __CHANGE__ 011: Release resources allocated by further class members. */ } bool WxpqdicFrame::CanClose(bool WXUNUSED(isLast)) { bool back = true; return back; } void WxpqdicFrame::OnQuit(wxCommandEvent & WXUNUSED(event)) { { wxCriticalSectionLocker lockCsProtect(csProtect); if (bIsInitialized) { timer.Stop(); bIsInitialized = false; } } if (INVALID_SOCKET != sock) { dk4socket_close(sock, NULL); sock = INVALID_SOCKET; } dk4mem_release(pUsername); dk4mem_release(pQueuename); dk4mem_release(pHostname); dk4mem_release(pRequest); Show(false); /* !!!!! TODO: Release resources */ Close(); } void WxpqdicFrame::OnAbout(wxCommandEvent & WXUNUSED(event)) { wxString text(wxT("")); wxString title(wxT("")); /* Construct message text. */ text.Append(sNlWx[0]); text.Append(sNlWx[7]); #if 0 text.Append(sNlWx[1]); #endif text.Append(versionNumber); text.Append(sNlWx[8]); text.Append(sTexts[9]); text.Append(sNlWx[2]); text.Append(sNlWx[8]); text.Append(sNlWx[8]); text.Append(sTexts[11]); text.Append(sNlWx[8]); text.Append(sNlWx[9]); text.Append(sNlWx[8]); text.Append(sNlWx[8]); text.Append(sTexts[12]); text.Append(sNlWx[8]); text.Append(sNlWx[10]); text.Append(sNlWx[8]); text.Append(sNlWx[11]); text.Append(sNlWx[8]); text.Append(sNlWx[12]); text.Append(sNlWx[8]); text.Append(sNlWx[13]); text.Append(sNlWx[8]); text.Append(sNlWx[14]); text.Append(sNlWx[8]); text.Append(sNlWx[15]); text.Append(sNlWx[8]); /* Construct dialog box title. */ title.Append(sTexts[10]); title.Append(sNlWx[0]); /* Show dialog box. */ wxMessageBox(text, title); } void WxpqdicFrame::OnHelpContents(wxCommandEvent & WXUNUSED(event)) { DisplayContents(); } /* __CHANGE__ 017: Event handlers for further events. */ /* __CHANGE__ 014: Implementation of further methods. */ bool WxpqdicFrame::ConfigureAndCheckNeedToClose(int *perrc) { wxString dummy(wxT("")); dkChar buf[1024]; char c8b[1024]; dk4_er_t er; wxChar *pv[] = { NULL, NULL, NULL, NULL, NULL, NULL }; wxCStrData hnstrdata = dummy.c_str(); wxCStrData qnstrdata = dummy.c_str(); wxCStrData unstrdata = dummy.c_str(); const wxChar *cptr; const size_t szbuf = DK4_SIZEOF(buf,dkChar); const size_t szc8b = sizeof(c8b); long l = 0L; int res = 0; bool back = true; /* Retrieve some fallback values from preferences. */ pAppHelp->GetMultiple(wxpqdic_pref_key_names, pv, 6); #line 793 "WxpqdicFrame.wxc" #line 794 "WxpqdicFrame.wxc" #line 795 "WxpqdicFrame.wxc" #line 796 "WxpqdicFrame.wxc" #line 797 "WxpqdicFrame.wxc" #line 798 "WxpqdicFrame.wxc" /* Check command line arguments */ { wxLogNull log; wxCmdLineParser parser(wxpqdic_cmd_line_entries, copyArgc, copyArgv); res = parser.Parse(false); /* Check overall parsing of arguments */ if (0 != res) { #line 809 "WxpqdicFrame.wxc" /* ERROR: Failed to parse command line arguments */ *perrc = WXPQDIC_FRAME_ERROR_PARSE; goto finished; } /* Option -a means the remote host wants ASCII data. */ if (parser.Found(wxT_2("a"))) { bIsUtf8 = false; } else { if (NULL != pv[5]) { if (0 != dk4strx_casecmp(pv[5], sNlWx[16])) { if (0 != dk4strx_casecmp(pv[5], sNlWx[17])) { bIsUtf8 = false; } } } } /* Try to obtain host name from arguments or from preferences. */ dk4error_init(&er); cptr = NULL; if (parser.Found(wxT_2("h"), &sHostname)) { hnstrdata = sHostname.c_str(); cptr = (wxChar const *)hnstrdata; } else { cptr = pv[0]; } if (NULL != cptr) { if (pAppHelp->StringToDk(buf, szbuf, cptr, &er)) { pHostname = dk4str_dup(buf, NULL); if (NULL == pHostname) { #line 843 "WxpqdicFrame.wxc" /* ERROR: Memory */ *perrc = WXPQDIC_FRAME_ERROR_MEMORY; goto finished; } } else { /* ERROR: Failed to convert string */ *perrc = WXPQDIC_FRAME_ERROR_STRCONV_HOSTNAME; goto finished; } } if (NULL == pHostname) { /* ERROR: Missing host name */ *perrc = WXPQDIC_FRAME_ERROR_HOSTNAME; goto finished; } /* Queue name is required. */ cptr = NULL; if (parser.Found(wxT_2("q"), &sQueuename)) { qnstrdata = sQueuename.c_str(); cptr = (wxChar const *)qnstrdata; } else { cptr = pv[2]; } if (NULL != cptr) { res = dk4recwx_wxchar_to_char( c8b, szc8b, ((bIsUtf8) ? (DK4_ENCODING_UTF8) : (DK4_ENCODING_PLAIN)), cptr, pAppHelp->GetWxEncoding(), NULL ); if (0 != res) { pQueuename = dk4str8_dup(c8b, NULL); if (NULL == pQueuename) { #line 877 "WxpqdicFrame.wxc" /* ERROR: Memory */ *perrc = WXPQDIC_FRAME_ERROR_MEMORY; goto finished; } } else { /* ERROR: String conversion failed */ *perrc = WXPQDIC_FRAME_ERROR_STRCONV_QUEUENAME; goto finished; } } else { /* ERROR: Missing queue name */ *perrc = WXPQDIC_FRAME_ERROR_QUEUENAME; goto finished; } if (NULL == pQueuename) { /* ERROR: Missing queue name */ *perrc = WXPQDIC_FRAME_ERROR_QUEUENAME; goto finished; } /* Port number is optional. */ { bool portnoFound = false; l = 0L; if (parser.Found(wxT_2("p"), &l)) { portnoFound = true; } else { if (NULL != pv[1]) { wxString s(pv[1]); if (s.ToLong(&l, 0)) { portnoFound = true; } } } if (portnoFound) { if ((long)(USHRT_MAX) < l) { /* ERROR: Port number out of range */ *perrc = WXPQDIC_FRAME_ERROR_PORT_OOR; goto finished; } if (0L == l) { /* ERROR: Illegal port number 0 */ *perrc = WXPQDIC_FRAME_ERROR_PORT_ZERO; goto finished; } usPortnumber = (unsigned short)l; } } /* Local port number is optional. */ { bool portnoFound = false; l = 0L; if (parser.Found(wxT_2("l"), &l)) { portnoFound = true; } else { if (NULL != pv[4]) { wxString s(pv[4]); if (s.ToLong(&l, 0)) { portnoFound = true; } } } if (portnoFound) { if ((long)(USHRT_MAX) < l) { /* ERROR: Port number out of range */ *perrc = WXPQDIC_FRAME_ERROR_LOCALPORT_OOR; goto finished; } if (0L == l) { /* ERROR: Illegal port number 0 */ *perrc = WXPQDIC_FRAME_ERROR_LOCALPORT_ZERO; goto finished; } usLocalPort = (unsigned short)l; } } /* User name is optional, use current user by default. */ if (parser.Found(wxT_2("u"), &sUsername)) { unstrdata = sUsername.c_str(); res = dk4recwx_wxchar_to_char( c8b, szc8b, ((bIsUtf8) ? (DK4_ENCODING_UTF8) : (DK4_ENCODING_PLAIN)), (wxChar const *)unstrdata, pAppHelp->GetWxEncoding(), NULL ); if (0 != res) { pUsername = dk4str8_dup(c8b, NULL); if (NULL == pUsername) { /* ERROR: Memory */ *perrc = WXPQDIC_FRAME_ERROR_MEMORY; goto finished; } } else { /* ERROR: Failed to convert user name */ *perrc = WXPQDIC_FRAME_ERROR_STRCONV_USERNAME; goto finished; } } else { res = dk4user_get_logname(buf, szbuf, 0, NULL); if (0 != res) { res = dk4recode_dk_to_any( c8b, szc8b, ((bIsUtf8) ? (DK4_ENCODING_UTF8) : (DK4_ENCODING_PLAIN)), buf, pAppHelp->GetDkEncoding(), NULL ); if (0 != res) { pUsername = dk4str8_dup(c8b, NULL); if (NULL == pUsername) { /* ERROR: Memory */ *perrc = WXPQDIC_FRAME_ERROR_MEMORY; goto finished; } } else { /* ERROR: Failed to convert user name */ *perrc = WXPQDIC_FRAME_ERROR_STRCONV_USERNAME; goto finished; } } else { /* ERROR: User name not found! */ *perrc = WXPQDIC_FRAME_ERROR_USERNAME; goto finished; } } if (NULL == pUsername) { /* ERROR: No user name */ *perrc = WXPQDIC_FRAME_ERROR_USERNAME; goto finished; } /* Interval length is optional. */ { bool intervalFound = false; l = 0L; if (parser.Found(wxT_2("p"), &l)) { intervalFound = true; } else { if (NULL != pv[3]) { wxString s(pv[3]); if (s.ToLong(&l, 0)) { intervalFound = true; } } } if (intervalFound) { if (5L <= l) { lUpdateInterval = l; } else { lUpdateInterval = 5L; } } } /* Now build request */ dk4error_init(&er); szRequest = strlen(wxpqdic_kw[2]); szRequest = dk4ma_size_t_add(szRequest, dk4str8_len(pQueuename), &er); szRequest = dk4ma_size_t_add(szRequest, dk4str8_len(pUsername), &er); szRequest = dk4ma_size_t_add(szRequest, dk4str8_len(wxpqdic_kw[2]), &er); szRequest = dk4ma_size_t_add(szRequest, 4, &er); if (DK4_E_NONE == er.ec) { pRequest = dk4mem_new(char,szRequest,NULL); if (NULL != pRequest) { if (0 == dk4str8_cpy_s(pRequest, szRequest, wxpqdic_kw[2], NULL)) { /* ERROR: BUG */ *perrc = WXPQDIC_FRAME_ERROR_BUG; goto finished; } if (0 == dk4str8_cat_s(pRequest, szRequest, wxpqdic_kw[1], NULL)) { /* ERROR: BUG */ *perrc = WXPQDIC_FRAME_ERROR_BUG; goto finished; } if (0 == dk4str8_cat_s(pRequest, szRequest, pQueuename, NULL)) { /* ERROR: BUG */ *perrc = WXPQDIC_FRAME_ERROR_BUG; goto finished; } if (0 == dk4str8_cat_s(pRequest, szRequest, wxpqdic_kw[1], NULL)) { /* ERROR: BUG */ *perrc = WXPQDIC_FRAME_ERROR_BUG; goto finished; } if (0 == dk4str8_cat_s(pRequest, szRequest, pUsername, NULL)) { /* ERROR: BUG */ *perrc = WXPQDIC_FRAME_ERROR_BUG; goto finished; } if (0 == dk4str8_cat_s(pRequest, szRequest, wxpqdic_kw[0], NULL)) { /* ERROR: BUG */ *perrc = WXPQDIC_FRAME_ERROR_BUG; goto finished; } szRequest = dk4str8_len(pRequest); #line 1082 "WxpqdicFrame.wxc" } else { /* ERROR: Memory */ *perrc = WXPQDIC_FRAME_ERROR_MEMORY; goto finished; } } else { /* ERROR: Numeric overflow in size calculation */ *perrc = WXPQDIC_FRAME_ERROR_SIZE_CALC_OVERFLOW; goto finished; } /* Create socket. */ sock = dk4socket_udp_client_for_host( aAddresses, pHostname, usPortnumber, usLocalPort, 1, NULL ); if (INVALID_SOCKET == sock) { *perrc = WXPQDIC_FRAME_ERROR_SOCKET; goto finished; } } #line 1106 "WxpqdicFrame.wxc" tLimit->SetLabel(sTexts[27]); tUsed->SetLabel(sTexts[27]); tAccount->SetLabel(sTexts[27]); /* Finally indicate success. */ timer.Start(500); bIsInitialized = true; back = false; /* Clean up at end and return result. */ finished: pAppHelp->ReleaseWxcharStringArray(pv, 6); if (back) { if (INVALID_SOCKET != sock) { dk4socket_close(sock, NULL); sock = INVALID_SOCKET; } dk4mem_release(pUsername); dk4mem_release(pQueuename); dk4mem_release(pHostname); dk4mem_release(pRequest); } return back; } void WxpqdicFrame::OnIdle(wxIdleEvent & event) { int errorCode = WXPQDIC_FRAME_ERROR_NONE; bool mustClose = false; #line 1142 "WxpqdicFrame.wxc" /* __CHANGE__ */ { wxCriticalSectionLocker lockCsProtect(csProtect); if (bFirstIdle) { bFirstIdle = false; mustClose = ConfigureAndCheckNeedToClose(&errorCode); } } if (mustClose) { #line 1152 "WxpqdicFrame.wxc" const wxChar *ti; const wxChar *tx; ti = sTexts[58]; tx = sTexts[59]; switch (errorCode) { case WXPQDIC_FRAME_ERROR_PARSE : { ti = sTexts[30]; tx = sTexts[31]; } break; case WXPQDIC_FRAME_ERROR_MEMORY : { ti = sTexts[32]; tx = sTexts[33]; } break; case WXPQDIC_FRAME_ERROR_STRCONV_HOSTNAME : { ti = sTexts[34]; tx = sTexts[35]; } break; case WXPQDIC_FRAME_ERROR_HOSTNAME : { ti = sTexts[36]; tx = sTexts[37]; } break; case WXPQDIC_FRAME_ERROR_STRCONV_QUEUENAME : { ti = sTexts[38]; tx = sTexts[39]; } break; case WXPQDIC_FRAME_ERROR_QUEUENAME : { ti = sTexts[40]; tx = sTexts[41]; } break; case WXPQDIC_FRAME_ERROR_PORT_OOR : { ti = sTexts[42]; tx = sTexts[43]; } break; case WXPQDIC_FRAME_ERROR_PORT_ZERO : { ti = sTexts[42]; tx = sTexts[44]; } break; case WXPQDIC_FRAME_ERROR_STRCONV_USERNAME : { ti = sTexts[45]; tx = sTexts[46]; } break; case WXPQDIC_FRAME_ERROR_USERNAME : { ti = sTexts[47]; tx = sTexts[48]; } break; case WXPQDIC_FRAME_ERROR_LOCALPORT_OOR : { ti = sTexts[49]; tx = sTexts[50]; } break; case WXPQDIC_FRAME_ERROR_LOCALPORT_ZERO : { ti = sTexts[49]; tx = sTexts[51]; } break; case WXPQDIC_FRAME_ERROR_BUG : { ti = sTexts[52]; tx = sTexts[53]; } break; case WXPQDIC_FRAME_ERROR_SIZE_CALC_OVERFLOW : { ti = sTexts[54]; tx = sTexts[55]; } break; case WXPQDIC_FRAME_ERROR_SOCKET : { ti = sTexts[56]; tx = sTexts[57]; } break; } wxMessageBox(tx, ti, (wxICON_ERROR | wxOK), this); Show(false); Close(); } /* Allow idle handlers from the base class. */ #line 1210 "WxpqdicFrame.wxc" event.Skip(); } void WxpqdicFrame::OnTimer(wxTimerEvent & WXUNUSED(event)) { bool mustUpdate = false; #line 1219 "WxpqdicFrame.wxc" { wxCriticalSectionLocker lockCsProtect(csProtect); #line 1222 "WxpqdicFrame.wxc" if (bIsInitialized) { #line 1223 "WxpqdicFrame.wxc" mustUpdate = DataExchangeWithServer(); } #if TRACE_DEBUG else { #line 1227 "WxpqdicFrame.wxc" } #endif #line 1230 "WxpqdicFrame.wxc" } if (mustUpdate) { Refresh(); Update(); } #line 1236 "WxpqdicFrame.wxc" } bool WxpqdicFrame::ProcessResponse(bool & found) { wxChar wxb[16*sizeof(dk4_um_t)]; char *tokens[8]; /* Tokens in the response */ const char *ep; /* End part of text */ dk4_um_t limit; /* Print limit */ dk4_um_t used; /* Pages used with in limit */ dk4_um_t account; /* Personal account */ size_t sz; /* Number of tokens used */ size_t szwxb; /* Size of wxb */ int founddet; /* Details found. */ int res; /* Text to number conversion result */ int summary; /* Flag: Can print */ bool force; /* Flag: Force use of values */ bool back = false; #line 1257 "WxpqdicFrame.wxc" sz = dk4str8_tokenize(tokens, 8, bResponse, NULL, NULL); if (4 == sz) { #line 1259 "WxpqdicFrame.wxc" founddet = 0; force = bFirstResponse; switch (iState) { case WXPQDIC_STATE_TIMEOUT : case WXPQDIC_STATE_SEND_FAILED : { force = true; #line 1266 "WxpqdicFrame.wxc" } break; } #line 1268 "WxpqdicFrame.wxc" if (0 == dk4str8_cmp("-1", tokens[0])) { #line 1269 "WxpqdicFrame.wxc" limit = DK4_UM_MAX; founddet |= 1; } else { limit = (dk4_um_t)0UL; ep = NULL; res = dk4ma_input_c8_dec_dk4_um_t(&limit, tokens[0], &ep, 1, NULL); if (0 != res) { #line 1276 "WxpqdicFrame.wxc" founddet |= 1; } #if TRACE_DEBUG else { #line 1280 "WxpqdicFrame.wxc" } #endif } used = (dk4_um_t)0UL; ep = NULL; res = dk4ma_input_c8_dec_dk4_um_t(&used, tokens[1], &ep, 1, NULL); if (0 != res) { #line 1287 "WxpqdicFrame.wxc" founddet |= 2; } #if TRACE_DEBUG else { #line 1291 "WxpqdicFrame.wxc" } #endif account = (dk4_um_t)0UL; ep = NULL; res = dk4ma_input_c8_dec_dk4_um_t(&account, tokens[2], &ep, 1, NULL); if (0 != res) { #line 1297 "WxpqdicFrame.wxc" founddet |= 4; } #if TRACE_DEBUG else { #line 1301 "WxpqdicFrame.wxc" } #endif summary = 0; ep = NULL; res = dk4ma_input_c8_dec_int(&summary, tokens[3], &ep, 1, NULL); if (0 != res) { #line 1307 "WxpqdicFrame.wxc" founddet |= 8; } #if TRACE_DEBUG else { #line 1311 "WxpqdicFrame.wxc" } #endif if (15 == (15 & founddet)) { #line 1314 "WxpqdicFrame.wxc" /* Renew text labels */ #if DK4_SIZEOF_WXCHAR > 1 szwxb = DK4_SIZEOF(wxb,wxChar); if ((force) || (limit != uLimit)) { if (DK4_UM_MAX == limit) { tLimit->SetLabel(sTexts[14]); } else { res = dk4ma_write_wc_decimal_unsigned(wxb, szwxb, limit, 0, NULL); if (0 != res) { wxString s(wxb); tLimit->SetLabel(s); } } back = true; } if ((force) || (used != uUsed)) { res = dk4ma_write_wc_decimal_unsigned(wxb, szwxb, used, 0, NULL); if (0 != res) { wxString s(wxb); tUsed->SetLabel(s); } back = true; } if ((force) || (account != uAccount)) { res = dk4ma_write_wc_decimal_unsigned(wxb, szwxb, account, 0, NULL); if (0 != res) { wxString s(wxb); tAccount->SetLabel(s); } back = true; } #else if ((force) || (limit != uLimit)) { if (DK4_UM_MAX == limit) { tLimit->SetLabel(sTexts[14]); } else { wxString s(tokens[0]); tLimit->SetLabel(s); } back = true; #line 1355 "WxpqdicFrame.wxc" } if ((force) || (used != uUsed)) { wxString s(tokens[1]); tUsed->SetLabel(s); back = true; #line 1360 "WxpqdicFrame.wxc" } if ((force) || (account != uAccount)) { wxString s(tokens[2]); tAccount->SetLabel(s); back = true; #line 1365 "WxpqdicFrame.wxc" } #endif if ((force) || (summary != iSummary)) { wxString s(sTexts[(0 != summary) ? 19 : 20]); tAllowed->SetLabel(s); if (0 != summary) { tAllowed->SetForegroundColour(cGreen); } else { tAllowed->SetForegroundColour(cRed); } back = true; #line 1376 "WxpqdicFrame.wxc" } if (force) { lStatus->SetLabel(sNlWx[5]); switch (iState) { case WXPQDIC_STATE_TIMEOUT : case WXPQDIC_STATE_SEND_FAILED : { lStatus->SetForegroundColour(cBlack); } break; } } /* Save values for later comparisons */ uLimit = limit; uUsed = used; uAccount = account; iSummary = summary; bFirstResponse = false; /* Change state */ iState = WXPQDIC_STATE_OK; found = true; } #if TRACE_DEBUG else { #line 1401 "WxpqdicFrame.wxc" } #endif } #if TRACE_DEBUG else { #line 1406 "WxpqdicFrame.wxc" } #endif #line 1409 "WxpqdicFrame.wxc" return back; } bool WxpqdicFrame::RetrieveResponse(void) { dk4_sockaddr_storage_t remaddr; /* Source address */ size_t sz; /* Buffer size */ size_t szrema; /* Address size */ int res; /* Conversion result */ bool back = false; bool found = false; /* Flag: Found */ #line 1424 "WxpqdicFrame.wxc" sz = szResponse; szrema = sizeof(remaddr); res = dk4socket_recvfrom( sock, bResponse, &sz, 0, (struct sockaddr *)(&remaddr), &szrema, 0L, 10000L, NULL ); switch (res) { case DK4_SOCKET_RESULT_SUCCESS : case DK4_SOCKET_RESULT_IN_PROGRESS : { #line 1435 "WxpqdicFrame.wxc" if (0 < sz) { #line 1436 "WxpqdicFrame.wxc" bResponse[(szResponse > sz) ? (sz) : (szResponse - 1)] = '\0'; #if TRACE_DEBUG dk4str8_delnl(bResponse); #line 1439 "WxpqdicFrame.wxc" #endif if (1 /* ##### TODO: Compare addresses */ ) { #line 1441 "WxpqdicFrame.wxc" back = ProcessResponse(found); } #if TRACE_DEBUG else { #line 1445 "WxpqdicFrame.wxc" } #endif } #if TRACE_DEBUG else { #line 1450 "WxpqdicFrame.wxc" } #endif } break; default : { #line 1454 "WxpqdicFrame.wxc" } break; } if (!(found)) { if (WXPQDIC_STATE_SENDED == iState) { iState = WXPQDIC_STATE_TIMEOUT; tLimit->SetLabel(sTexts[27]); tUsed->SetLabel(sTexts[27]); tAccount->SetLabel(sTexts[27]); tAllowed->SetLabel(sTexts[27]); tAllowed->SetForegroundColour(cBlack); lStatus->SetLabel(sTexts[29]); lStatus->SetForegroundColour(cRed); back = true; } } #line 1470 "WxpqdicFrame.wxc" return back; } bool WxpqdicFrame::SendRequest(bool force) { dk4_time_t currenttime = (dk4_time_t)0UL; size_t sz = 0; int res = 0; bool mustsend = false; bool back = false; #line 1484 "WxpqdicFrame.wxc" if ((dk4_time_t)0UL == tRequestSended) { mustsend = true; } else { if (force) { mustsend = true; } else { dk4time_get(¤ttime); if ((tRequestSended + (dk4_time_t)lUpdateInterval) <= currenttime) { mustsend = true; } } } if (mustsend) { #line 1497 "WxpqdicFrame.wxc" sz = szRequest; if ((dk4_um_t)0UL == currenttime) { dk4time_get(¤ttime); } res = dk4socket_sendto( sock, pRequest, &sz, 0, (struct sockaddr *)(&(aAddresses[0])), sizeof(dk4_sockaddr_storage_t), 0L, 0L, NULL ); tRequestSended = currenttime; switch (res) { case DK4_SOCKET_RESULT_SUCCESS : case DK4_SOCKET_RESULT_IN_PROGRESS : { #line 1511 "WxpqdicFrame.wxc" switch (iState) { case WXPQDIC_STATE_OK : { iState = WXPQDIC_STATE_SENDED; } break; } } break; default : { #line 1518 "WxpqdicFrame.wxc" if (WXPQDIC_STATE_SEND_FAILED != iState) { tLimit->SetLabel(sTexts[27]); tUsed->SetLabel(sTexts[27]); tAccount->SetLabel(sTexts[27]); tAllowed->SetLabel(sTexts[27]); lStatus->SetLabel(sTexts[28]); lStatus->SetForegroundColour(cRed); back = true; } iState = WXPQDIC_STATE_SEND_FAILED; } break; } } #if TRACE_DEBUG else { #line 1533 "WxpqdicFrame.wxc" } #endif #line 1536 "WxpqdicFrame.wxc" return back; } void WxpqdicFrame::OnRun(wxCommandEvent & WXUNUSED(event)) { bool mustUpdate = false; #line 1546 "WxpqdicFrame.wxc" { wxCriticalSectionLocker lockCsProtect(csProtect); if (bIsInitialized) { mustUpdate = SendRequest(true); } } if (mustUpdate) { Refresh(); Update(); } #line 1557 "WxpqdicFrame.wxc" } bool WxpqdicFrame::DataExchangeWithServer(void) { bool back = false; #line 1566 "WxpqdicFrame.wxc" if (RetrieveResponse()) { back = true; } if (SendRequest()) { back = true; } #line 1573 "WxpqdicFrame.wxc" return back; }