int ThreadData::sendPacket(const char* cmd, const char* fmt,...) { if (this == NULL) return 0; size_t strsize = 512; char* str = (char*)mir_alloc(strsize); int thisTrid = 0; if (fmt == NULL) mir_snprintf(str, strsize, "%s", cmd); else { thisTrid = InterlockedIncrement(&mTrid); if (fmt[0] == '\0') mir_snprintf(str, strsize, "%s %d", cmd, thisTrid); else { va_list vararg; va_start(vararg, fmt); int paramStart = mir_snprintf(str, strsize, "%s %d ", cmd, thisTrid); while (mir_vsnprintf(str+paramStart, strsize-paramStart-3, fmt, vararg) == -1) str = (char*)mir_realloc(str, strsize += 512); str[strsize-3] = 0; va_end(vararg); } } if (strchr(str, '\r') == NULL) strcat(str,"\r\n"); int result = send(str, strlen(str)); mir_free(str); return (result > 0) ? thisTrid : -1; }
static TCHAR *parseUrlDec(ARGUMENTSINFO *ai) { if (ai->argc != 2) return NULL; char *res = mir_t2a(ai->targv[1]); if (res == NULL) return NULL; unsigned int cur = 0; while (cur < mir_strlen(res)) { if ((*(res + cur) == '%') && (mir_strlen(res + cur) >= 3)) { char hex[8]; memset(hex, '\0', sizeof(hex)); strncpy(hex, res + cur + 1, 2); *(res + cur) = (char)strtol(hex, NULL, 16); memmove(res + cur + 1, res + cur + 3, mir_strlen(res + cur + 3) + 1); } cur++; } res = (char*)mir_realloc(res, mir_strlen(res) + 1); TCHAR *tres = mir_a2t(res); mir_free(res); return tres; }
LPSTR TranslateU( LPCSTR lpText ) { int i; for(i=0;i<ca2u;i++) { if( pa2u[i].a == lpText ) { return pa2u[i].u; } } ca2u++; pa2u = (pA2U) mir_realloc(pa2u,sizeof(A2U)*ca2u); pa2u[i].a = (LPSTR) lpText; if( bCoreUnicode ) { LPWSTR lpwText = mir_a2u(lpText); LPWSTR lpwTran = TranslateW(lpwText); mir_free(lpwText); pa2u[i].u = mir_strdup(exp->utf8encode(lpwTran)); } else { LPSTR lpTran = Translate(lpText); LPWSTR lpwTran = mir_a2u(lpTran); lpTran = exp->utf8encode(lpwTran); mir_free(lpwTran); pa2u[i].u = mir_strdup(lpTran); } return pa2u[i].u; }
static TCHAR *parseUrlEnc(ARGUMENTSINFO *ai) { if (ai->argc != 2) return NULL; char *res = mir_t2a(ai->targv[1]); if (res == NULL) return NULL; size_t cur = 0; while (cur < mir_strlen(res)) { if (((*(res + cur) >= '0') && (*(res + cur) <= '9')) || ((*(res + cur) >= 'a') && (*(res + cur) <= 'z')) || ((*(res + cur) >= 'A') && (*(res + cur) <= 'Z'))) { cur++; continue; } res = (char*)mir_realloc(res, mir_strlen(res) + 4); if (res == NULL) return NULL; char hex[8]; memmove(res + cur + 3, res + cur + 1, mir_strlen(res + cur + 1) + 1); mir_snprintf(hex, _countof(hex), "%%%x", *(res + cur)); strncpy(res + cur, hex, mir_strlen(hex)); cur += mir_strlen(hex); } TCHAR *tres = mir_a2t(res); mir_free(res); return tres; }
bool EventList::GetEventData(const EventIndex& ev, EventData& data) { if (!ev.isExternal) { DWORD newBlobSize = db_event_getBlobSize(ev.hEvent); if (newBlobSize > goldBlobSize) { gdbei.pBlob = (PBYTE)mir_realloc(gdbei.pBlob,newBlobSize); goldBlobSize = newBlobSize; } gdbei.cbBlob = goldBlobSize; if (db_event_get(ev.hEvent, &gdbei) == 0) { data.isMe = (gdbei.flags & DBEF_SENT) != 0; data.eventType = gdbei.eventType; data.timestamp = gdbei.timestamp; return true; } } else if (ev.exIdx >= 0 && ev.exIdx < (int)importedMessages.size()) { IImport::ExternalMessage& em = importedMessages[ev.exIdx]; data.isMe = (em.flags & DBEF_SENT) != 0; data.eventType = em.eventType; data.timestamp = em.timestamp; return true; } return false; }
// always gets called in main message loop static void CALLBACK BufferedProcTimer(HWND hwnd,UINT msg,UINT_PTR idTimer,DWORD currentTick) { struct BufferedCallData *buf; UINT uElapsed,uElapseNext=USER_TIMER_MAXIMUM; BUFFEREDPROC pfnBuffProc; LPARAM lParam; #ifdef _DEBUG char szDbgLine[256]; const char *pszProcName; #endif for(int i=0; i < nCallListCount; ++i) { /* find elapsed procs */ uElapsed=currentTick-callList[i].startTick; /* wraparound works */ if ((uElapsed+USER_TIMER_MINIMUM)>=callList[i].uElapse) { /* call elapsed proc */ pfnBuffProc=callList[i].pfnBuffProc; lParam=callList[i].lParam; #ifdef _DEBUG pszProcName=callList[i].pszProcName; #endif /* resize storage array */ if ((i+1)<nCallListCount) memmove(&callList[i],&callList[i+1],((nCallListCount-i-1)*sizeof(struct BufferedCallData))); --nCallListCount; --i; /* reiterate current */ if (nCallListCount) { buf=(struct BufferedCallData*)mir_realloc(callList,nCallListCount*sizeof(struct BufferedCallData)); if (buf != NULL) callList=buf; } else { mir_free(callList); callList=NULL; } #ifdef _DEBUG mir_snprintf(szDbgLine,SIZEOF(szDbgLine),"buffered call: %s(0x%X)\n",pszProcName,lParam); /* all ascii */ OutputDebugStringA(szDbgLine); #endif CallFunctionAsync((void (CALLBACK *)(void*))pfnBuffProc,(void*)lParam); /* compatible */ } /* find next timer delay */ else if ((callList[i].uElapse-uElapsed)<uElapseNext) uElapseNext=callList[i].uElapse-uElapsed; } /* set next timer */ if (nCallListCount) { #ifdef _DEBUG mir_snprintf(szDbgLine,SIZEOF(szDbgLine),"next buffered timeout: %ums\n",uElapseNext); /* all ascii */ OutputDebugStringA(szDbgLine); #endif idBufferedTimer=SetTimer(hwnd,idBufferedTimer,uElapseNext,BufferedProcTimer); /* will be reset */ } else { KillTimer(hwnd,idTimer); idBufferedTimer=0; #ifdef _DEBUG OutputDebugStringA("empty buffered queue\n"); #endif } }
INT_PTR CIrcProto::CallChatEvent(WPARAM wParam, LPARAM lParam) { GCEVENT * gce = (GCEVENT *)lParam; INT_PTR iVal = 0; // first see if the scripting module should modify or stop this event if ( m_bMbotInstalled && m_scriptingEnabled && gce && gce->time != 0 && (gce->pDest->pszID == NULL || lstrlen(gce->pDest->ptszID) != 0 && lstrcmpi(gce->pDest->ptszID , SERVERWINDOW))) { GCEVENT *gcevent= (GCEVENT*) lParam; GCEVENT *gcetemp = NULL; WPARAM wp = wParam; gcetemp = (GCEVENT *)mir_alloc(sizeof(GCEVENT)); gcetemp->pDest = (GCDEST *)mir_alloc(sizeof(GCDEST)); gcetemp->pDest->iType = gcevent->pDest->iType; gcetemp->dwFlags = gcevent->dwFlags; gcetemp->bIsMe = gcevent->bIsMe; gcetemp->cbSize = sizeof(GCEVENT); gcetemp->dwItemData = gcevent->dwItemData; gcetemp->time = gcevent->time; gcetemp->pDest->ptszID = mir_tstrdup( gcevent->pDest->ptszID ); gcetemp->pDest->pszModule = mir_strdup( gcevent->pDest->pszModule ); gcetemp->ptszText = mir_tstrdup( gcevent->ptszText ); gcetemp->ptszUID = mir_tstrdup( gcevent->ptszUID ); gcetemp->ptszNick = mir_tstrdup( gcevent->ptszNick ); gcetemp->ptszStatus = mir_tstrdup( gcevent->ptszStatus ); gcetemp->ptszUserInfo = mir_tstrdup( gcevent->ptszUserInfo ); if ( Scripting_TriggerMSPGuiIn( &wp, gcetemp ) && gcetemp ) { //MBOT CORRECTIONS //if ( gcetemp && gcetemp->pDest && gcetemp->pDest->ptszID ) { if ( gcetemp && gcetemp->pDest && gcetemp->pDest->ptszID && !my_strstri(gcetemp->pDest->ptszID, (IsConnected()) ? m_info.sNetwork.c_str() : TranslateT("Offline")) ) { CMString sTempId = MakeWndID( gcetemp->pDest->ptszID ); mir_realloc( gcetemp->pDest->ptszID, sizeof(TCHAR)*(sTempId.GetLength() + 1)); lstrcpyn(gcetemp->pDest->ptszID, sTempId.c_str(), sTempId.GetLength()+1); } iVal = CallServiceSync(MS_GC_EVENT, wp, (LPARAM) gcetemp); } if ( gcetemp ) { mir_free(( void* )gcetemp->pszNick); mir_free(( void* )gcetemp->pszUID); mir_free(( void* )gcetemp->pszStatus); mir_free(( void* )gcetemp->pszUserInfo); mir_free(( void* )gcetemp->pszText); mir_free(( void* )gcetemp->pDest->pszID); mir_free(( void* )gcetemp->pDest->pszModule); mir_free(( void* )gcetemp->pDest); mir_free(( void* )gcetemp); } return iVal; } return CallServiceSync( MS_GC_EVENT, wParam, ( LPARAM )gce ); }
unsigned MimeHeaders::allocSlot(void) { if (++mCount >= mAllocCount) { mAllocCount += 10; mVals = (MimeHeader*)mir_realloc(mVals, sizeof(MimeHeader) * mAllocCount); } return mCount - 1; }
void SetStatusBarResultInfo(HWND hwndDlg) { HWND hwndStatus = GetDlgItem(hwndDlg, IDC_STATUSBAR); HWND hwndResults = GetDlgItem(hwndDlg, IDC_RESULTS); LV_ITEM lvi; struct ListSearchResult *lsr; struct ProtoResultsSummary *subtotal = NULL; int subtotalCount = 0; int i, total; TCHAR str[256]; total = ListView_GetItemCount(hwndResults); for (lvi.iItem = total-1;lvi.iItem>=0;lvi.iItem--) { lvi.mask = LVIF_PARAM; ListView_GetItem(hwndResults, &lvi); lsr = (struct ListSearchResult*)lvi.lParam; if (lsr == NULL) continue; for (i=0;i<subtotalCount;i++) { if (subtotal[i].szProto == lsr->szProto) { subtotal[i].count++; break; } } if (i == subtotalCount) { subtotal = (struct ProtoResultsSummary*)mir_realloc(subtotal, sizeof(struct ProtoResultsSummary)*(subtotalCount+1)); subtotal[subtotalCount].szProto = lsr->szProto; subtotal[subtotalCount++].count = 1; } } if (total != 0) { TCHAR substr[64]; PROTOACCOUNT *pa = Proto_GetAccount(subtotal[0].szProto); if (pa == NULL) return; if (subtotalCount == 1) { if (total == 1) mir_sntprintf(str, SIZEOF(str), TranslateT("1 %s user found"), pa->tszAccountName); else mir_sntprintf(str, SIZEOF(str), TranslateT("%d %s users found"), total, pa->tszAccountName); } else { mir_sntprintf(str, SIZEOF(str), TranslateT("%d users found ("), total); for (i=0; i < subtotalCount; i++) { if (i) { if ((pa = Proto_GetAccount(subtotal[i].szProto)) == NULL) return; lstrcat(str, _T(", ")); } mir_sntprintf(substr, SIZEOF(substr), _T("%d %s"), subtotal[i].count, pa->tszAccountName); lstrcat(str, substr); } lstrcat(str, _T(")")); } mir_free(subtotal); } else lstrcpy(str, TranslateT("No users found")); SendMessage(hwndStatus, SB_SETTEXT, 2, (LPARAM)str); }
void CJabberProto::ListRemoveResource( JABBER_LIST list, const TCHAR* jid ) { EnterCriticalSection( &m_csLists ); int i = ListExist( list, jid ); JABBER_LIST_ITEM* LI = m_lstRoster[i-1]; if ( !i || LI == NULL ) { LeaveCriticalSection( &m_csLists ); return; } const TCHAR* p = _tcschr( jid, '@' ); const TCHAR* q = _tcschr(( p == NULL ) ? jid : p, '/' ); if ( q ) { const TCHAR* resource = q+1; if ( resource[0] ) { JABBER_RESOURCE_STATUS* r = LI->resource; int j; for ( j=0; j < LI->resourceCount; j++, r++ ) { if ( !_tcsicmp( r->resourceName, resource )) break; } if ( j < LI->resourceCount ) { // Found last seen resource ID to be removed if ( LI->lastSeenResource == j ) LI->lastSeenResource = -1; else if ( LI->lastSeenResource > j ) LI->lastSeenResource--; // update manually selected resource ID if (LI->resourceMode == RSMODE_MANUAL) { if ( LI->manualResource == j ) { LI->resourceMode = RSMODE_LASTSEEN; LI->manualResource = -1; } else if ( LI->manualResource > j ) LI->manualResource--; } // Update MirVer due to possible resource changes UpdateMirVer(LI); JabberListFreeResourceInternal( r ); if ( LI->resourceCount-- == 1 ) { mir_free( r ); LI->resource = NULL; } else { memmove( r, r+1, ( LI->resourceCount-j )*sizeof( JABBER_RESOURCE_STATUS )); LI->resource = ( JABBER_RESOURCE_STATUS* )mir_realloc( LI->resource, LI->resourceCount*sizeof( JABBER_RESOURCE_STATUS )); } } } } LeaveCriticalSection( &m_csLists ); MenuUpdateSrmmIcon(LI); }
//--------------------------------------------------------------------------- int CSend::OnSend(void *obj, WPARAM, LPARAM lParam) { CSend* self = (CSend*)obj; ACKDATA *ack = (ACKDATA*)lParam; if (ack->hProcess != self->m_hSend) return 0; /* if(dat->waitingForAcceptance) { SetTimer(hwndDlg,1,1000,NULL); dat->waitingForAcceptance=0; } */ switch (ack->result) { case ACKRESULT_INITIALISING: //SetFtStatus(hwndDlg, LPGENT("Initialising..."), FTS_TEXT); break; case ACKRESULT_CONNECTING: //SetFtStatus(hwndDlg, LPGENT("Connecting..."), FTS_TEXT); break; case ACKRESULT_CONNECTPROXY: //SetFtStatus(hwndDlg, LPGENT("Connecting to proxy..."), FTS_TEXT); break; case ACKRESULT_LISTENING: //SetFtStatus(hwndDlg, LPGENT("Waiting for connection..."), FTS_TEXT); break; case ACKRESULT_CONNECTED: //SetFtStatus(hwndDlg, LPGENT("Connected"), FTS_TEXT); break; case ACKRESULT_SENTREQUEST: //SetFtStatus(hwndDlg, LPGENT("Decision sent"), FTS_TEXT); break; case ACKRESULT_NEXTFILE: //SetFtStatus(hwndDlg, LPGENT("Moving to next file..."), FTS_TEXT); case ACKRESULT_FILERESUME: // case ACKRESULT_DATA: //transfer is on progress break; case ACKRESULT_DENIED: self->Unhook(); self->Exit(ack->result); break; case ACKRESULT_FAILED: self->Unhook(); self->Exit(ack->result); //type=ACKTYPE_MESSAGE, result=success/failure, (char*)lParam=error message or NULL. //type=ACKTYPE_URL, result=success/failure, (char*)lParam=error message or NULL. //type=ACKTYPE_FILE, result=ACKRESULT_FAILED then lParam=(LPARAM)(const char*)szReason break; case ACKRESULT_SUCCESS: self->Unhook(); switch (ack->type) { case ACKTYPE_CHAT: break; case ACKTYPE_MESSAGE: self->DB_EventAdd((WORD)EVENTTYPE_MESSAGE); break; case ACKTYPE_URL: self->DB_EventAdd((WORD)EVENTTYPE_URL); break; case ACKTYPE_FILE: self->m_szEventMsg = (char*)mir_realloc(self->m_szEventMsg, sizeof(DWORD) + self->m_cbEventMsg); memmove(self->m_szEventMsg + sizeof(DWORD), self->m_szEventMsg, self->m_cbEventMsg); self->m_cbEventMsg += sizeof(DWORD); self->DB_EventAdd((WORD)EVENTTYPE_FILE); break; } self->Exit(ack->result); break; } return 0; }
static int ProtoAck(WPARAM, LPARAM lParam) { ACKDATA *ack = (ACKDATA*)lParam; if (ack->type != ACKTYPE_FILE) return 0; switch (ack->result) { case ACKRESULT_DATA: { for (int i = 0; i < nTransfersCount; ++i) if (transfers[i] == ack->hProcess) break; /* already in list */ /* insert into list */ HANDLE *buf = (HANDLE*)mir_realloc(transfers, (nTransfersCount + 1)*sizeof(HANDLE)); if (buf != NULL) { transfers = buf; transfers[nTransfersCount] = ack->hProcess; ++nTransfersCount; } break; } case ACKRESULT_SUCCESS: case ACKRESULT_FAILED: case ACKRESULT_DENIED: for (int i = 0; i < nTransfersCount; ++i) { if (transfers[i] == ack->hProcess) { /* remove from list */ if (i < (nTransfersCount - 1)) memmove(&transfers[i], &transfers[i + 1], (nTransfersCount - i - 1)*sizeof(HANDLE)); --nTransfersCount; HANDLE *buf = (HANDLE*)mir_realloc(transfers, nTransfersCount*sizeof(HANDLE)); if (buf != NULL) transfers = buf; else if (!nTransfersCount) transfers = NULL; /* stop watcher */ if (!nTransfersCount && (currentWatcherType&SDWTF_FILETRANSFER)) ShutdownAndStopWatcher(); break; } } break; } return 0; }
// MonitorInfoEnumProc - CALLBACK for MonitorInfoEnum BOOL CALLBACK MonitorInfoEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) { MONITORS* monitors = (MONITORS*)dwData; ++monitors->count; monitors->info = (MONITORINFOEX*)mir_realloc(monitors->info, sizeof(MONITORINFOEX)*monitors->count); monitors->info[monitors->count-1].cbSize = sizeof(MONITORINFOEX); if(!GetMonitorInfo(hMonitor, (LPMONITORINFO)(monitors->info + monitors->count-1))) { return FALSE; // stop enumeration if error } return TRUE; }
TReceivedItem* TRecvContactsData::AddReceivedItem() { int iItem = cbReceived; cbReceived++; maReceived = (TReceivedItem**)mir_realloc(maReceived, cbReceived*sizeof(TReceivedItem*)); maReceived[iItem] = new TReceivedItem(); return maReceived[iItem]; }
static DWORD CALLBACK StreamOutCallback(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG * pcb) { MessageSendQueueItem *msi = (MessageSendQueueItem *)dwCookie; msi->sendBuffer = (char*)mir_realloc(msi->sendBuffer, msi->sendBufferSize + cb + 2); memcpy(msi->sendBuffer + msi->sendBufferSize, pbBuff, cb); msi->sendBufferSize += cb; *((TCHAR*)(msi->sendBuffer + msi->sendBufferSize)) = '\0'; *pcb = cb; return 0; }
static bool ReallocInfoBuffer(ThreadData *info, size_t mDataSize) { char *mData = (char*)mir_realloc(info->mData, mDataSize+1); if (mData == NULL) return false; info->mData = mData; info->mDataSize = mDataSize; ZeroMemory(&mData[info->mBytesInData], info->mDataSize-info->mBytesInData+1); return true; }
static TCHAR* GetAwayMessage(int statusMode, char *szProto) { DBVARIANT dbv; if (szProto && !(CallProtoService(szProto, PS_GETCAPS, PFLAGNUM_3, 0) & Proto_Status2Flag(statusMode))) return NULL; if (DBGetContactSettingByte(NULL, "SRAway", StatusModeToDbSetting(statusMode, "Ignore"), 0)) return NULL; if (DBGetContactSettingByte(NULL, "SRAway", StatusModeToDbSetting(statusMode, "UsePrev"),0)) { if (DBGetContactSettingTString(NULL, "SRAway", StatusModeToDbSetting(statusMode, "Msg"), &dbv)) dbv.ptszVal = mir_tstrdup(GetDefaultMessage(statusMode)); } else { int i; TCHAR substituteStr[128]; if (DBGetContactSettingTString(NULL, "SRAway", StatusModeToDbSetting(statusMode,"Default"), &dbv)) dbv.ptszVal = mir_tstrdup(GetDefaultMessage(statusMode)); for (i=0; dbv.ptszVal[i]; i++) { if (dbv.ptszVal[i] != '%') continue; if (!_tcsnicmp(dbv.ptszVal + i, _T("%time%"), 6)) { MIRANDA_IDLE_INFO mii = {0}; mii.cbSize = sizeof(mii); CallService(MS_IDLE_GETIDLEINFO, 0, (LPARAM)&mii); if (mii.idleType == 1) { int mm; SYSTEMTIME t; GetLocalTime(&t); mm = t.wMinute + t.wHour * 60 - mii.idleTime; if (mm < 0) mm += 60 * 24; t.wMinute = mm % 60; t.wHour = mm / 60; GetTimeFormat(LOCALE_USER_DEFAULT, TIME_NOSECONDS, &t, NULL, substituteStr, SIZEOF(substituteStr)); } else GetTimeFormat(LOCALE_USER_DEFAULT, TIME_NOSECONDS, NULL, NULL, substituteStr, SIZEOF(substituteStr)); } else if (!_tcsnicmp(dbv.ptszVal + i, _T("%date%"), 6)) GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, NULL, NULL, substituteStr, SIZEOF(substituteStr)); else continue; if (lstrlen(substituteStr) > 6) dbv.ptszVal = (TCHAR*)mir_realloc(dbv.ptszVal, (lstrlen(dbv.ptszVal) + 1 + lstrlen(substituteStr) - 6) * sizeof(TCHAR)); MoveMemory(dbv.ptszVal + i + lstrlen(substituteStr), dbv.ptszVal + i + 6, (lstrlen(dbv.ptszVal) - i - 5) * sizeof(TCHAR)); CopyMemory(dbv.ptszVal+i, substituteStr, lstrlen(substituteStr) * sizeof(TCHAR)); } } return dbv.ptszVal; }
void JabberListRemoveByIndex(int index) { EnterCriticalSection(&csLists); if (index>=0 && index<count) { JabberListFreeItemInternal(&(lists[index])); count--; memmove(lists+index, lists+index+1, sizeof(JABBER_LIST_ITEM)*(count-index)); lists = (JABBER_LIST_ITEM *) mir_realloc(lists, sizeof(JABBER_LIST_ITEM)*count); } LeaveCriticalSection(&csLists); }
static int RemoveFromList(int pos,void **lpList,int *ListElemCount,int ElemSize) { //memcpy(&((*lpMenuItems)[pos]),&((*lpMenuItems)[pos+1]),sizeof(CListIntMenuItem)*(*MenuItemCount-pos-1)); void *p1,*p2; p1=(void *)( (int)(*lpList)+pos*ElemSize); p2=(void *)( (int)(*lpList)+(pos+1)*ElemSize); memcpy(p1,p2,ElemSize*(*ListElemCount-pos-1)); (*ListElemCount)--; (*lpList)=mir_realloc((*lpList),ElemSize*(*ListElemCount)); return 0; }
int AddModernMaskToList(ModernMask * mm, ModernMaskList * mmTemplateList) { if (!mmTemplateList || !mm) return -1; //if (!mmTemplateList->MaskList) mmTemplateList->MaskList=mir_alloc(1); mmTemplateList->MaskList=mir_realloc(mmTemplateList->MaskList,sizeof(ModernMask)*(mmTemplateList->AllocatedMask+1)); //if (mm->MaskID==0) // mm->MaskID=mmTemplateList->AllocatedMask; memcpy(&(mmTemplateList->MaskList[mmTemplateList->AllocatedMask]),mm,sizeof(ModernMask)); mmTemplateList->AllocatedMask++; return mmTemplateList->AllocatedMask-1; }
int CJabberProto::ListAddResource( JABBER_LIST list, const TCHAR* jid, int status, const TCHAR* statusMessage, char priority, const TCHAR* nick ) { EnterCriticalSection( &m_csLists ); int i = ListExist( list, jid ); if ( !i ) { LeaveCriticalSection( &m_csLists ); return 0; } JABBER_LIST_ITEM* LI = m_lstRoster[i-1]; int bIsNewResource = false, j; const TCHAR* p = _tcschr( jid, '@' ); const TCHAR* q = _tcschr(( p == NULL ) ? jid : p, '/' ); if ( q ) { const TCHAR* resource = q+1; if ( resource[0] ) { JABBER_RESOURCE_STATUS* r = LI->resource; for ( j=0; j < LI->resourceCount; j++, r++ ) { if ( !_tcscmp( r->resourceName, resource )) { // Already exist, update status and statusMessage r->status = status; replaceStr( r->statusMessage, statusMessage ); r->priority = priority; break; } } if ( j >= LI->resourceCount ) { // Not already exist, add new resource LI->resource = ( JABBER_RESOURCE_STATUS * ) mir_realloc( LI->resource, ( LI->resourceCount+1 )*sizeof( JABBER_RESOURCE_STATUS )); bIsNewResource = true; r = LI->resource + LI->resourceCount++; memset( r, 0, sizeof( JABBER_RESOURCE_STATUS )); r->status = status; r->affiliation = AFFILIATION_NONE; r->role = ROLE_NONE; r->resourceName = mir_tstrdup( resource ); r->nick = mir_tstrdup( nick ); if ( statusMessage ) r->statusMessage = mir_tstrdup( statusMessage ); r->priority = priority; } } } // No resource, update the main statusMessage else { LI->itemResource.status = status; replaceStr( LI->itemResource.statusMessage, statusMessage ); } LeaveCriticalSection( &m_csLists ); MenuUpdateSrmmIcon(LI); return bIsNewResource; }
static void AppendToByteBuffer(struct ResizableByteBuffer *buffer,const void *append,DWORD cbAppendSize) { if (buffer->cbAlloced<=buffer->cbLength+cbAppendSize) { BYTE* buf=(BYTE*)mir_realloc(buffer->buf,buffer->cbAlloced+ALLOC_STEP+cbAppendSize); if (buf == NULL) return; buffer->buf=buf; buffer->cbAlloced+=ALLOC_STEP+cbAppendSize; OutputDebugStringA("reallocating memory...\n"); /* all ascii */ } memcpy(&buffer->buf[buffer->cbLength],append,cbAppendSize); buffer->cbLength+=cbAppendSize; }
static int SettingsEnumProc(const char* szSetting, LPARAM lParam) { if (szSetting) { enumDBSettingsParam* p = (enumDBSettingsParam*)lParam; p->count++; p->pszSettingName = (char**)mir_realloc(p->pszSettingName, p->count * sizeof(char*)); p->pszSettingName[p->count - 1] = mir_strdup(szSetting); } return 0; }
/** * name: CLineBuffer::_resizeBuf * desc: ensure, the right size for the buffer * param: cbReq - number of bytes required for the next operation * * return: TRUE if reallocation successful or memoryblock is large enough, FALSE otherwise **/ BYTE CLineBuffer::_resizeBuf(const size_t cbReq) { if (cbReq > _cbVal - _cbUsed) { if (!(_pVal = (PBYTE)mir_realloc(_pVal, BLOCKSIZE + _cbVal + 1))) { _cbVal = 0; _cbUsed = 0; return FALSE; } _cbVal += BLOCKSIZE; } return TRUE; }
void CContactCache::saveHistory(WPARAM wParam, LPARAM) { size_t iLength = 0, iStreamLength = 0; int oldTop = 0; char* szFromStream = NULL; if (m_hwnd == 0 || m_dat == 0) return; if (wParam) { oldTop = m_iHistoryTop; m_iHistoryTop = (int)wParam; } szFromStream = ::Message_GetFromStream(GetDlgItem(m_hwnd, IDC_MESSAGE), SF_RTFNOOBJS | SFF_PLAINRTF | SF_NCRFORNONASCII); if (szFromStream != NULL) { iLength = iStreamLength = (mir_strlen(szFromStream) + 1); if (iLength > 0 && m_history != NULL) { // XXX: iLength > 1 ? if ((m_iHistoryTop == m_iHistorySize) && oldTop == 0) { // shift the stack down... TInputHistory ihTemp = m_history[0]; m_iHistoryTop--; ::memmove((void*)&m_history[0], (void*)&m_history[1], (m_iHistorySize - 1) * sizeof(TInputHistory)); m_history[m_iHistoryTop] = ihTemp; } if (iLength > m_history[m_iHistoryTop].lLen) { if (m_history[m_iHistoryTop].szText == NULL) { if (iLength < HISTORY_INITIAL_ALLOCSIZE) iLength = HISTORY_INITIAL_ALLOCSIZE; m_history[m_iHistoryTop].szText = (TCHAR*)mir_alloc(iLength); m_history[m_iHistoryTop].lLen = iLength; } else { if (iLength > m_history[m_iHistoryTop].lLen) { m_history[m_iHistoryTop].szText = (TCHAR*)mir_realloc(m_history[m_iHistoryTop].szText, iLength); m_history[m_iHistoryTop].lLen = iLength; } } } ::memcpy(m_history[m_iHistoryTop].szText, szFromStream, iStreamLength); if (!oldTop) { if (m_iHistoryTop < m_iHistorySize) { m_iHistoryTop++; m_iHistoryCurrent = m_iHistoryTop; } } } mir_free(szFromStream); } if (oldTop) m_iHistoryTop = oldTop; }
static void HTTPFormAppendData(NETLIBHTTPREQUEST* nlhr, size_t* dataMax, char** dataPos, const char* data, size_t len) { nlhr->dataLength = (*dataPos - nlhr->pData); if (nlhr->dataLength + len >= *dataMax) { *dataPos = nlhr->pData; *dataMax += 0x1000 + 0x1000 * (len >> 12); nlhr->pData = (char*)mir_realloc(nlhr->pData, *dataMax); if (!nlhr->pData) mir_free(*dataPos); *dataPos = nlhr->pData; if (!*dataPos) return; *dataPos += nlhr->dataLength; }
char* Log_CreateRtfHeader(MODULEINFO *mi) { int i; // guesstimate amount of memory for the RTF header size_t bufferEnd = 0, bufferAlloced = 4096; char *buffer = (char *)mir_realloc(mi->pszHeader, bufferAlloced); buffer[0] = '\0'; // get the number of pixels per logical inch HDC hdc = GetDC(NULL); ci.logPixelSY = GetDeviceCaps(hdc, LOGPIXELSY); ci.logPixelSX = GetDeviceCaps(hdc, LOGPIXELSX); ReleaseDC(NULL, hdc); // ### RTF HEADER // font table Log_Append(buffer, bufferEnd, bufferAlloced, "{\\rtf1\\ansi\\deff0{\\fonttbl"); for (i = 0; i < OPTIONS_FONTCOUNT; i++) Log_Append(buffer, bufferEnd, bufferAlloced, "{\\f%u\\fnil\\fcharset%u%S;}", i, ci.aFonts[i].lf.lfCharSet, ci.aFonts[i].lf.lfFaceName); // colour table Log_Append(buffer, bufferEnd, bufferAlloced, "}{\\colortbl ;"); for (i = 0; i < OPTIONS_FONTCOUNT; i++) Log_Append(buffer, bufferEnd, bufferAlloced, "\\red%u\\green%u\\blue%u;", GetRValue(ci.aFonts[i].color), GetGValue(ci.aFonts[i].color), GetBValue(ci.aFonts[i].color)); for (i = 0; i < mi->nColorCount; i++) Log_Append(buffer, bufferEnd, bufferAlloced, "\\red%u\\green%u\\blue%u;", GetRValue(mi->crColors[i]), GetGValue(mi->crColors[i]), GetBValue(mi->crColors[i])); // new paragraph Log_Append(buffer, bufferEnd, bufferAlloced, "}\\pard"); // set tabs and indents int iIndent = 0; if (g_Settings->dwIconFlags) { iIndent += (14 * 1440) / ci.logPixelSX; Log_Append(buffer, bufferEnd, bufferAlloced, "\\tx%u", iIndent); } if (g_Settings->bShowTime) { int iSize = (g_Settings->LogTextIndent * 1440) / ci.logPixelSX; Log_Append(buffer, bufferEnd, bufferAlloced, "\\tx%u", iIndent + iSize); if (g_Settings->bLogIndentEnabled) iIndent += iSize; } Log_Append(buffer, bufferEnd, bufferAlloced, "\\fi-%u\\li%u", iIndent, iIndent); return buffer; }
static TCHAR* ListView_GetItemTextEx(HWND hLV, int iItem, int iSubItem) { LVITEM lvi = {0}; lvi.mask = LVIF_TEXT; lvi.iSubItem = iSubItem; lvi.cchTextMax = 64; lvi.pszText = (TCHAR*)mir_alloc(lvi.cchTextMax * sizeof(TCHAR)); // loop until the returned size is smaller than buffer size while (SendMessage(hLV, LVM_GETITEMTEXT, iItem, (LPARAM)&lvi) == lvi.cchTextMax - 1) { lvi.cchTextMax += 64; lvi.pszText = (TCHAR*)mir_realloc(lvi.pszText, lvi.cchTextMax * sizeof(TCHAR)); } return lvi.pszText; }
static TCHAR *parseAddAlias(ARGUMENTSINFO *ai) { int res; char *szHelp, *szArgsA; if (ai->argc != 3) return NULL; TCHAR *cur = ai->targv[1]; while (isValidTokenChar(*cur)) cur++; ptrT alias(mir_tstrndup(ai->targv[1], cur - ai->targv[1])); int argc; TCHAR **argv; getArguments(cur, &argv, &argc); deRegisterToken(alias); addToAliasRegister(alias, argc, argv, ai->targv[2]); TCHAR *szArgs = NULL; for (int i = 0; i < argc; i++) { if (i == 0) szArgs = (TCHAR*)mir_calloc((_tcslen(argv[i]) + 2)*sizeof(TCHAR)); else szArgs = (TCHAR*)mir_realloc(szArgs, (_tcslen(szArgs) + _tcslen(argv[i]) + 2)*sizeof(TCHAR)); _tcscat(szArgs, argv[i]); if (i != argc - 1) _tcscat(szArgs, _T(",")); } if (szArgs != NULL && argc > 0) { szArgsA = mir_t2a(szArgs); size_t size = 32 + strlen(szArgsA); szHelp = (char *)mir_alloc(size); memset(szHelp, '\0', 32 + strlen(szArgsA)); mir_snprintf(szHelp, size, LPGEN("Alias")"\t(%s)\t"LPGEN("user defined"), szArgsA); res = registerIntToken(alias, parseTranslateAlias, TRF_FUNCTION | TRF_UNPARSEDARGS, szHelp); mir_free(szArgsA); } else { szHelp = (char*)mir_alloc(32); memset(szHelp, '\0', 32); mir_snprintf(szHelp, 32, LPGEN("Alias")"\t\t"LPGEN("user defined")); res = registerIntToken(alias, parseTranslateAlias, TRF_FIELD | TRF_UNPARSEDARGS, szHelp); } mir_free(szArgs); mir_free(szHelp); return (res == 0) ? mir_tstrdup(_T("")) : NULL; }
void TlenXmlAddAttr(XmlNode *n, char *name, char *value) { int i; if (n == NULL || name == NULL || value == NULL) return; i = n->numAttr; (n->numAttr)++; n->attr = (XmlAttr **) mir_realloc(n->attr, sizeof(XmlAttr *) * n->numAttr); n->attr[i] = (XmlAttr *) mir_alloc(sizeof(XmlAttr)); n->attr[i]->name = mir_strdup(name); n->attr[i]->value = mir_strdup(value); }