//Function: Init the Dlmg module //Parameters: // pDlmgCfg - Config parameter //return: // 0 - success // else - consult the errocode.h int fDlmg_Init(stDlmgCfg *pDlmgCfg) { int rt; char pSql[512]; char *pErrMsg=NULL; if(pDlmgCfg==NULL){ return ILLEGAL_INPUT; } memset(&DlmgStatus,0,sizeof(stDlmgCfg)); //Init database table if(pDlmgCfg->pDBHandle==NULL){ return ILLEGAL_INPUT; } DlmgStatus.pDBHandle=pDlmgCfg->pDBHandle; //创建表downpacks snprintf(pSql,512,"CREATE TABLE IF NOT EXISTS downpacks (\ PK_ID INTEGER NOT NULL, \ PK_TYPE INTEGER NOT NULL, \ PK_STOREPATH TEXT NOT NULL, \ PK_ICONPATH TEXT NOT NULL, \ PK_DESC TEXT NOT NULL, \ EXPIRE_DATE INTEGER, \ NEXTDSERNUM INTEGER, \ PRIMARY KEY (PK_ID));\ "); rt=sqlite3_exec(DlmgStatus.pDBHandle , pSql , 0 , 0 , &pErrMsg); if(rt!=SQLITE_OK){ DEBUGLOG2(3,"Error, CREATE TABLE downpacks failed %d: %s.\n",rt,pErrMsg); return DATABASE_FAILURE; } //创建表downrecords snprintf(pSql,512,"CREATE TABLE IF NOT EXISTS downrecords (\ DSERNUM INTEGER NOT NULL, \ PACKID INTEGER NOT NULL, \ DOWNTIME INTEGER, \ POSITION_EW_F TEXT, \ POSITION_EW_V DOUBLE, \ POSITION_NS_F TEXT, \ POSITION_NS_V DOUBLE, \ BROWSERINFO TEXT, \ PRIMARY KEY (DSERNUM,PACKID)); \ "); rt=sqlite3_exec(DlmgStatus.pDBHandle , pSql , 0 , 0 , &pErrMsg); if(rt!=SQLITE_OK){ DEBUGLOG2(3,"Error, CREATE TABLE downrecords failed %d: %s.\n",rt,pErrMsg); return DATABASE_FAILURE; } return SUCCESS; }
int intern_fgetc( FILE *stream ) { int zeichen; if (is_valid) { is_valid = 0; DEBUGLOG2(other,_T("old character: %x"),the_character); return the_character; } zeichen = fgetc(stream); DEBUGLOG2(other,_T("new character: %x, EOF %d"),zeichen,feof(stream)); return zeichen; }
void * ymalloc (mutabor_box_type * box, size_t size) { #ifdef ACS_VERSION void * help1 = Ax_malloc (size); #else void * help1 = malloc (size); #endif struct mini_heap * help2 = (mini_heap*) malloc (sizeof (struct mini_heap)); if (help1 == NULL || help2 == NULL) { DEBUGLOG2(other,_T("help1 == %p(%d) ; help2 == %p(%d)"), help1,(int)size,(void*)help2,(int)sizeof(struct mini_heap)); mutabor_error_message(box,error, _("Not enough memory.")); return NULL; } help2 -> pointer = help1; help2 -> next = box->runtime_heap; box->runtime_heap = help2; return help1; }
void MessageOut::writeCoordinates(const uint16_t x, const uint16_t y, unsigned char direction, const char *const str) { DEBUGLOG2(strprintf("writeCoordinates: %u,%u %u", CAST_U32(x), static_cast<unsigned>(y), CAST_U32(direction)), mPos, str); unsigned char *const data = reinterpret_cast<unsigned char*>(mData) + CAST_SIZE(mPos); mNetwork->mOutSize += 3; mPos += 3; uint16_t temp = x; temp <<= 6; data[0] = 0; data[1] = 1; data[2] = 2; data[0] = HIBYTE(temp); data[1] = CAST_U8(temp); temp = y; temp <<= 4; data[1] |= HIBYTE(temp); data[2] = LOBYTE(temp); direction = toServerDirection(direction); data[2] |= direction; PacketCounters::incOutBytes(3); }
void * xrealloc (mutabor_box_type * box, void * block, size_t newsize) { if ( ((size_t *)block) [ - 1 ] + (char*)block == & (box->file->heap.heap_to_use_syntax -> inhalt [box->file->heap.heap_to_use_syntax -> anzahl_belegt]) && (char*)block + newsize < &(box->file->heap.heap_to_use_syntax -> inhalt [ HEAP_PORTION_SYNTAX ])) { /* Dann war block der vorherige xmalloc und es passt noch rein */ box->file->heap.heap_to_use_syntax -> anzahl_belegt += newsize - ((size_t *)block) [ - 1 ] ; ((size_t *)block) [ - 1 ] = newsize; return block; } else { void * help = xmalloc (box, newsize); if (help) { memmove (help, block, newsize); return help; } else { DEBUGLOG2(other,_T("xmalloc (%d) failed"),(int)newsize); mutabor_error_message (box, error, _("Reallocation of memory failed.")); return NULL; } } }
void MessageIn::postInit() { // Read the message ID mId = readId(); IGNOREDEBUGLOG; DEBUGLOG2("Receive packet", 0, "MessageIn"); readInt16("packet id"); }
void MessageIn::postInit(const char *const str) { // Read the message ID mId = readId(); IGNOREDEBUGLOG; DEBUGLOG2("Receive packet", 0, "MessageIn"); readInt16(str); }
void MessageIn::postInit(const char *const str, const unsigned int version) { // Read the message ID mId = readId(); mVersion = version; IGNOREDEBUGLOG; DEBUGLOG2("Receive packet", 0, "MessageIn"); #ifdef ENABLEDEBUGLOG if (mVersion > 0) { const std::string verStr = toString(mVersion); DEBUGLOG2("Version", 0, verStr.c_str()); } #endif // ENABLEDEBUGLOG readInt16(str); }
/* Receives data on a socket with descriptor s and stores it in the buffer. When successful, the number of bytes of data received into the buffer is returned. The value 0 indicates that the connection is closed. The value -1 indicates an error. */ int XIOsocket::read(void* buffer, unsigned int size) { unsigned int read = 0; DEBUGLOG2(("XIOsocket(%p{%d})::read(%p, %d)\n", this, s_handle, buffer, size)); while (read < size) { #ifdef TCPV40HDRS // Work around for missing SO_RCVTIMEO in 16 bit IP stack. struct timeval timeout = {0}; timeout.tv_sec = xio_socket_timeout(); if (timeout.tv_sec) { fd_set waitlist; FD_ZERO(&waitlist); FD_SET (s_handle, &waitlist); switch (select(s_handle+1, &waitlist, NULL, NULL, &timeout)) { case 0: // Timeout seterror(SOCETIMEDOUT); return -1; case -1: // Error seterror(); return -1; } } #endif int done = recv(s_handle, (char*)buffer + read, size - read, 0); DEBUGLOG2(("XIOsocket::read: %d, %d\n", done, sock_errno())); if (done < 0) { seterror(); break; } else if (done == 0) { eof = true; break; } else { read += done; } } return read; }
signed char MessageIn::readInt8(const char *const str) { signed char value = CAST_S8(-1); if (mPos < mLength) value = CAST_S8(mData[mPos]); DEBUGLOG2("readInt8: " + toStringPrint(CAST_U32( CAST_U8(value))), mPos, str); mPos += 1; PacketCounters::incInBytes(1); return value; }
void BoxClass::AppendToBoxList (Box b) { #ifdef DEBUG DEBUGLOG2(routing,_T("Adding box %p"),b.get()); print_stacktrace(isDebugFlag(smartptr)); typename listtype::iterator i = FindInBoxList(b); if (i != boxList.end()) { UNREACHABLECT(listtype); } #endif boxList.push_back(b); }
void MessageOut::writeInt32(const int32_t value, const char *const str) { DEBUGLOG2("writeInt32: " + toStringPrint(CAST_U32(value)), mPos, str); expand(4); #if SDL_BYTEORDER == SDL_BIG_ENDIAN int32_t swap = SDL_Swap32(value); memcpy(mData + CAST_SIZE(mPos), &swap, sizeof(int32_t)); #else memcpy(mData + CAST_SIZE(mPos), &value, sizeof(int32_t)); #endif mPos += 4; PacketCounters::incOutBytes(4); }
void MessageOut::writeInt16(const int16_t value, const char *const str) { expand(2); #if SDL_BYTEORDER == SDL_BIG_ENDIAN int16_t swap = SDL_Swap16(value); memcpy(mData + static_cast<size_t>(mPos), &swap, sizeof(int16_t)); #else memcpy(mData + static_cast<size_t>(mPos), &value, sizeof(int16_t)); #endif DEBUGLOG2("writeInt16: " + toStringPrint(static_cast<unsigned int>( static_cast<uint16_t>(value))), mPos, str); mPos += 2; PacketCounters::incOutBytes(2); }
void * xcalloc (mutabor_box_type * box, size_t anzahl, size_t size) { void * help = xmalloc (box, anzahl * size); if (help) { memset (help, 0, anzahl * size); return help; } else { DEBUGLOG2(other,_T("xmalloc(%d * %d) failed"),(int)anzahl,(int)size); mutabor_error_message (box, error, _("Not enough memory.")); return NULL; } }
void PRINTSIZER (wxSizer * sizer, const wxString & offset) { if (!sizer) DEBUGLOG2 (other,_T("NULL Pointer.")); DEBUGLOGTYPE (other, *sizer, _T ("%sSizer: %p to Window %p"), offset.c_str (), (void*)sizer,(void*)sizer->GetContainingWindow ()); wxSizerItemList &childs = sizer -> GetChildren (); for (wxSizerItemList::iterator i = childs.begin (); i!=childs.end (); ++i) { wxSizerItem * item = *i; wxRect rect = item->GetRect (); if (item->IsSizer ()) { DEBUGLOGTYPE (other, *sizer, _T ("%s%s sizer from (%d,%d) to (%d,%d):"), offset.c_str (), (item -> IsShown ()? _T ("shown"):_T ("hidden")), rect.x,rect.y, rect.x+rect.width, rect.y+rect.height); PRINTSIZER (item->GetSizer (), offset + _T (" | ")); } else if (item -> IsWindow ()) { wxWindow * window = item->GetWindow (); DEBUGLOGTYPE (other, *window, _T ("%sWindow: %p with parent window %p (%s) from (%d,%d) to (%d,%d)"), offset.c_str (), (void*)window,(void*)window->GetParent (), (item -> IsShown ()? _T ("shown"):_T ("hidden")), rect.x,rect.y, rect.x+rect.width, rect.y+rect.height); if (window -> GetSizer()) PRINTSIZER(window -> GetSizer(), offset + _T(" [] ")); } else if (item -> IsSpacer ()) { wxSize size = item->GetSpacer (); DEBUGLOGTYPE (other, size, _T ("%sSpacer: %d x %d (%s) from (%d,%d) to (%d,%d)"), offset.c_str (), size.x,size.y, (item -> IsShown ()? _T ("shown"):_T ("hidden")), rect.x,rect.y, rect.x+rect.width, rect.y+rect.height); } } }
int32_t MessageIn::readInt32(const char *const str) { int32_t value = -1; if (mPos + 4 <= mLength) { #if SDL_BYTEORDER == SDL_BIG_ENDIAN int32_t swap; memcpy(&swap, mData + static_cast<size_t>(mPos), sizeof(int32_t)); value = SDL_Swap32(swap); #else memcpy(&value, mData + static_cast<size_t>(mPos), sizeof(int32_t)); #endif } DEBUGLOG2("readInt32: " + toStringPrint(static_cast<unsigned int>(value)), mPos, str); mPos += 4; PacketCounters::incInBytes(4); return value; }
void * xalloca (mutabor_box_type * box, size_t size) { #ifdef ACS_VERSION void * help = Ax_malloc (size); #else void * help = malloc (size); #endif if (help == NULL) { DEBUGLOG2(other,_T("malloc(%d) failed."),(int)size); mutabor_error_message (box, error, _("Not enough memory for mutabor in source file")); return NULL; } return help; }
int64_t MessageIn::readInt64(const char *const str) { int64_t value = -1; if (mPos + 8 <= mLength) { #if SDL_BYTEORDER == SDL_BIG_ENDIAN int64_t swap; memcpy(&swap, mData + CAST_SIZE(mPos), sizeof(int64_t)); value = SDL_Swap64(swap); #else // SDL_BYTEORDER == SDL_BIG_ENDIAN memcpy(&value, mData + CAST_SIZE(mPos), sizeof(int64_t)); #endif // SDL_BYTEORDER == SDL_BIG_ENDIAN } DEBUGLOG2("readInt64: " + toStringPrint(CAST_U32(value)), mPos, str); mPos += 8; PacketCounters::incInBytes(8); return value; }
/* Sends data on a connected socket. When successful, returns 0. The return value -1 indicates an error was detected on the sending side of the connection. */ int XIOsocket::write(const void* buffer, unsigned int size) { int done; DEBUGLOG2(("XIOsocket(%p{%d})::write(%p, %d)\n", this, s_handle, buffer, size)); while (size) { #ifdef TCPV40HDRS // Work around for missing SO_SNDTIMEO in 16 bit IP stack. struct timeval timeout = {0}; timeout.tv_sec = xio_socket_timeout(); if (timeout.tv_sec) { fd_set waitlist; FD_ZERO(&waitlist); FD_SET (s_handle, &waitlist); switch (select( s_handle+1, NULL, &waitlist, NULL, &timeout)) { case 0: // Timeout seterror(SOCETIMEDOUT); return -1; case -1: // Error seterror(); return -1; } } #endif done = send(s_handle, (char*)buffer, size, 0); if (done <= 0) { seterror(); return -1; } (char*&)buffer += done; size -= done; } return 0; }
uint16_t MessageIn::readUInt16(const char *const str) { uint16_t value = 0xffU; if (mPos + 2 <= mLength) { #if SDL_BYTEORDER == SDL_BIG_ENDIAN uint16_t swap; memcpy(&swap, mData + CAST_SIZE(mPos), sizeof(uint16_t)); value = SDL_Swap16(swap); #else // SDL_BYTEORDER == SDL_BIG_ENDIAN memcpy(&value, mData + CAST_SIZE(mPos), sizeof(uint16_t)); #endif // SDL_BYTEORDER == SDL_BIG_ENDIAN } DEBUGLOG2("readUInt16: " + toStringPrint(CAST_U32( CAST_U16(value))), mPos, str); mPos += 2; PacketCounters::incInBytes(2); return value; }
void PRINTWINDOW (wxWindow * window, const wxString & offset = _T ("")) { mutUnused(offset); if (!window) DEBUGLOG2 (other,_T("NULL window.")); }
MessageOut::~MessageOut() { DEBUGLOG2("writeEnd: ", mPos, "position after end of packet"); }
MutFileDataType FileNameDialog(wxWindow * parent, int Command, wxString Filename) { DEBUGLOG2(gui,_T("Command: %d"),Command); static const wxString logic_sources(_("Mutabor tuning file (*.mut)|*.mut|Old Mutabor tuning file (*.mus)|*.mus|All files (*.*)|*.*")); static const wxString route_sources(_("Mutabor routing file (*.murx)|*.murx|Old Mutabor routing file (*.mur)|*.mur|All files (*.*)|*.*")); wxString title, filetypes, dir(wxEmptyString), name(wxEmptyString) , ext(wxEmptyString); int flags; MutFileDataType retval; switch (Command) { case CM_FILEOPEN: title = _("Which Mutabor file shall be loaded?"); filetypes = logic_sources; flags = wxFD_CHANGE_DIR | wxFD_FILE_MUST_EXIST | wxFD_OPEN; break; case mutaborGUI::CM_EXECUTE: title = _("Which Mutabor file shall be executed?"); filetypes = logic_sources; flags = wxFD_CHANGE_DIR | wxFD_FILE_MUST_EXIST | wxFD_OPEN; break; case CM_FILESAVEAS: title = _("Enter the new Mutabor file name, please!"); filetypes = logic_sources; flags = wxFD_CHANGE_DIR | wxFD_OVERWRITE_PROMPT | wxFD_SAVE; break; case mutaborGUI::CM_ROUTELOAD: title = _("Which Mutabor route file shall be loaded?"); filetypes = route_sources; flags = wxFD_CHANGE_DIR | wxFD_FILE_MUST_EXIST | wxFD_OPEN; break; case mutaborGUI::CM_ROUTESAVE: case mutaborGUI::CM_ROUTESAVEAS: title = _("Enter the new Mutabor route file name, please!"); filetypes = route_sources; flags = wxFD_CHANGE_DIR | wxFD_OVERWRITE_PROMPT | wxFD_SAVE; break; default: wxLogError(_("Unexpected Command Id in FileNameDialog: %d"),Command); retval.type = MutFileDataType::Unknown; return retval; } if (!Filename.IsEmpty()) { wxFileName splitter(Filename); ext = splitter.GetExt(); name = splitter.GetFullName(); dir = splitter.GetPath(); } wxFileDialog * FileSelector = new wxFileDialog(parent, title, dir, name, filetypes, flags); int cmd = FileSelector->ShowModal(); if (cmd != wxID_OK) { retval.type = MutFileDataType::Canceled; return retval; } retval.name = FileSelector->GetPath(); switch (Command) { case CM_FILEOPEN: case mutaborGUI::CM_EXECUTE: case CM_FILESAVEAS: retval.type=MutFileDataType::LogicSource; break; case mutaborGUI::CM_ROUTELOAD: case mutaborGUI::CM_ROUTESAVE: case mutaborGUI::CM_ROUTESAVEAS: switch (FileSelector->GetFilterIndex()) { case 0: retval.type = MutFileDataType::XMLRoute1; break; case 1: retval.type = MutFileDataType::UTF8TextRoute; break; default: wxString ext = retval.name.GetExt().Upper(); if (ext == _T("MUR")) { retval.type = MutFileDataType::UTF8TextRoute; } else if (ext == _T("MURX")) { retval.type = MutFileDataType::XMLRoute1; } else retval.type = MutFileDataType::Unknown; } break; default: wxLogError(_("Unexpected Command Id in FileNameDialog: %d"),Command); retval.type = MutFileDataType::Unknown; return retval; } FileSelector->Destroy(); return retval; }
void * xmalloc (mutabor_box_type * box, size_t size) { if (size + OFFSET > HEAP_PORTION_SYNTAX) { DEBUGLOG2(other,_T("Error: %d + %d > %d"),(int)size,(int)OFFSET, HEAP_PORTION_SYNTAX); mutabor_error_message(box, error, _("A chunk of memory has been requested that was too large (%d > %d)"), (int)size, (int)HEAP_PORTION_SYNTAX-size); return NULL; } if (box->file->heap.syntax_heap == NULL) { #ifdef ACS_VERSION box->file->heap.syntax_heap = Ax_malloc (sizeof (struct heap_element)); memset(box->file->heap.syntax_heap,0,sizeof (struct heap_element)); #else box->file->heap.syntax_heap = (heap_element*) calloc (1,sizeof (struct heap_element)); #endif if (box->file->heap.syntax_heap == NULL) { DEBUGLOG2(other,_T("calloc(1,%d) failed"), (int)sizeof (struct heap_element)); mutabor_error_message(box, error, _("Could not allocate syntax heap chunk.")); return NULL; } box->file->heap.heap_to_use_syntax = box->file->heap.syntax_heap; box->file->heap.heap_to_use_syntax -> anzahl_belegt = 0; box->file->heap.heap_to_use_syntax -> next = NULL; } /**** Jetzt ist zumindest ein Block da ******/ if (box->file->heap.heap_to_use_syntax -> anzahl_belegt + size + OFFSET < HEAP_PORTION_SYNTAX) { void * help = & (box->file->heap.heap_to_use_syntax -> inhalt [ box->file->heap.heap_to_use_syntax -> anzahl_belegt + OFFSET ]) ; box->file->heap.heap_to_use_syntax -> anzahl_belegt += size + OFFSET; ((size_t *)help) [ - 1 ] = size; return help; } else { #ifdef ACS_VERSION box->file->heap.heap_to_use_syntax -> next = Ax_malloc (sizeof (struct heap_element)); box->file->heap.memset(heap_to_use_syntax -> next,0,sizeof (struct heap_element)); #else box->file->heap.heap_to_use_syntax -> next = (heap_element*) calloc (1,sizeof (struct heap_element)); #endif if (box->file->heap.heap_to_use_syntax -> next == NULL) { DEBUGLOG2(other,_T("heap_to_use_syntax -> nex == NULL")); mutabor_error_message(box, error, _("Could not allocate syntax heap chunk.")); return NULL; } box->file->heap.heap_to_use_syntax = box->file->heap.heap_to_use_syntax -> next; box->file->heap.heap_to_use_syntax -> next = NULL; box->file->heap.heap_to_use_syntax -> anzahl_belegt = size + OFFSET; { void * tmp = (void*)box->file->heap.heap_to_use_syntax -> inhalt; size_t * tmp2 = (size_t *) tmp; *tmp2 = size; /* Original code: * (size_t *)&(heap_to_use_syntax -> inhalt [ 0 ]) = size; */ } return & box->file->heap.heap_to_use_syntax -> inhalt [ OFFSET ] ; } }