STDMETHODIMP_(MEVENT) CDb3Mmap::FindLastEvent(MCONTACT contactID) { DBCachedContact *cc; DWORD ofsContact = GetContactOffset(contactID, &cc); mir_cslock lck(m_csDbAccess); DBContact *dbc = (DBContact*)DBRead(ofsContact, nullptr); if (dbc->signature != DBCONTACT_SIGNATURE) return 0; if (!cc || !cc->IsSub()) return MEVENT(dbc->ofsLastEvent); if ((cc = m_cache->GetCachedContact(cc->parentID)) == nullptr) return 0; dbc = (DBContact*)DBRead(cc->dwOfsContact, nullptr); if (dbc->signature != DBCONTACT_SIGNATURE) return 0; for (DWORD dwOffset = dbc->ofsLastEvent; dwOffset != 0;) { DBEvent *dbe = AdaptEvent(dwOffset, contactID); if (dbe->signature != DBEVENT_SIGNATURE) return 0; if (dbe->contactID == contactID) return MEVENT(dwOffset); dwOffset = dbe->ofsPrev; } return 0; }
STDMETHODIMP_(HANDLE) CDb3Mmap::FindLastEvent(MCONTACT contactID) { DBCachedContact *cc; DWORD ofsContact = GetContactOffset(contactID, &cc); mir_cslock lck(m_csDbAccess); DBContact *dbc = (DBContact*)DBRead(ofsContact, sizeof(DBContact), NULL); if (dbc->signature != DBCONTACT_SIGNATURE) return NULL; if (!cc || !cc->IsSub()) return HANDLE(dbc->ofsLastEvent); if ((cc = m_cache->GetCachedContact(cc->parentID)) == NULL) return NULL; dbc = (DBContact*)DBRead(cc->dwDriverData, sizeof(DBContact), NULL); if (dbc->signature != DBCONTACT_SIGNATURE) return NULL; for (DWORD dwOffset = dbc->ofsLastEvent; dwOffset != 0;) { DBEvent *dbe = (DBEvent*)DBRead(dwOffset, sizeof(DBEvent), NULL); if (dbe->signature != DBEVENT_SIGNATURE) return NULL; if (dbe->contactID == contactID) return HANDLE(dwOffset); dwOffset = dbe->ofsPrev; } return NULL; }
int InitModuleNames(void) { struct DBModuleName *dbmn; DWORD ofsThis; int nameLen; char *mod; hModHeap=HeapCreate(0,0,0); lMods.sortFunc=ModCompare; lMods.increment=50; lOfs.sortFunc=OfsCompare; lOfs.increment=50; ofsThis=dbHeader.ofsFirstModuleName; dbmn=(struct DBModuleName*)DBRead(ofsThis,sizeof(struct DBModuleName),NULL); while(ofsThis) { if(dbmn->signature!=DBMODULENAME_SIGNATURE) DatabaseCorruption(NULL); nameLen=dbmn->cbName; mod = (char*)HeapAlloc(hModHeap,0,nameLen+1); CopyMemory(mod,DBRead(ofsThis+offsetof(struct DBModuleName,name),nameLen,NULL),nameLen); mod[nameLen] = 0; AddToList(mod, nameLen, ofsThis); ofsThis=dbmn->ofsNext; dbmn=(struct DBModuleName*)DBRead(ofsThis,sizeof(struct DBModuleName),NULL); } CreateServiceFunction(MS_DB_MODULES_ENUM,EnumModuleNames); return 0; }
DBEvent* CDb3Mmap::AdaptEvent(DWORD ofs, DWORD dwContactID) { if (m_dbHeader.version >= DB_095_1_VERSION) return (DBEvent*)DBRead(ofs, nullptr); DBEvent_094 *pOldEvent = (DBEvent_094*)DBRead(ofs, nullptr); m_tmpEvent.signature = pOldEvent->signature; m_tmpEvent.contactID = dwContactID; memcpy(&m_tmpEvent.ofsPrev, &pOldEvent->ofsPrev, sizeof(DBEvent_094) - sizeof(DWORD)); return &m_tmpEvent; }
STDMETHODIMP_(BOOL) CDb3Mmap::MarkEventRead(MCONTACT contactID, HANDLE hDbEvent) { DBCachedContact *cc; if (contactID) { if ((cc = m_cache->GetCachedContact(contactID)) == NULL) return -1; if (cc->IsSub()) if ((cc = m_cache->GetCachedContact(cc->parentID)) == NULL) return -1; } else cc = NULL; mir_cslockfull lck(m_csDbAccess); DWORD ofsContact = (cc) ? cc->dwDriverData : m_dbHeader.ofsUser; DBContact dbc = *(DBContact*)DBRead(ofsContact, sizeof(DBContact), NULL); DBEvent *dbe = (DBEvent*)DBRead((DWORD)hDbEvent, sizeof(DBEvent), NULL); if (dbe->signature != DBEVENT_SIGNATURE || dbc.signature != DBCONTACT_SIGNATURE) return -1; if (dbe->markedRead()) return dbe->flags; // log1("mark read @ %08x", hContact); dbe->flags |= DBEF_READ; DBWrite((DWORD)hDbEvent, dbe, sizeof(DBEvent)); BOOL ret = dbe->flags; if (dbc.ofsFirstUnread == (DWORD)hDbEvent) { for (;;) { if (dbe->ofsNext == 0) { dbc.ofsFirstUnread = 0; dbc.tsFirstUnread = 0; break; } DWORD ofsThis = dbe->ofsNext; dbe = (DBEvent*)DBRead(ofsThis, sizeof(DBEvent), NULL); if (!dbe->markedRead()) { dbc.ofsFirstUnread = ofsThis; dbc.tsFirstUnread = dbe->timestamp; break; } } } DBWrite(ofsContact, &dbc, sizeof(DBContact)); DBFlush(0); lck.unlock(); NotifyEventHooks(hEventMarkedRead, contactID, (LPARAM)hDbEvent); return ret; }
static INT_PTR GetEvent(WPARAM wParam,LPARAM lParam) { struct DBEvent *dbe; DBEVENTINFO *dbei=(DBEVENTINFO*)lParam; int bytesToCopy,i; if(dbei==NULL||dbei->cbSize!=sizeof(DBEVENTINFO)) return 1; if(dbei->cbBlob > 0 && dbei->pBlob == NULL) { dbei->cbBlob = 0; return 1; } EnterCriticalSection(&csDbAccess); dbe=(struct DBEvent*)DBRead(wParam,sizeof(struct DBEvent),NULL); if(dbe->signature!=DBEVENT_SIGNATURE) { LeaveCriticalSection(&csDbAccess); return 1; } dbei->szModule=GetModuleNameByOfs(dbe->ofsModuleName); dbei->timestamp=dbe->timestamp; dbei->flags=dbe->flags; dbei->eventType=dbe->eventType; if(dbei->cbBlob<dbe->cbBlob) bytesToCopy=dbei->cbBlob; else bytesToCopy=dbe->cbBlob; dbei->cbBlob=dbe->cbBlob; for(i=0;;i+=MAXCACHEDREADSIZE) { if(bytesToCopy-i<=MAXCACHEDREADSIZE) { CopyMemory(dbei->pBlob+i,DBRead(wParam+offsetof(struct DBEvent,blob)+i,bytesToCopy-i,NULL),bytesToCopy-i); break; } CopyMemory(dbei->pBlob+i,DBRead(wParam+offsetof(struct DBEvent,blob)+i,MAXCACHEDREADSIZE,NULL),MAXCACHEDREADSIZE); }
//this function caches results static DWORD GetSettingsGroupOfsByModuleNameOfs(struct DBContact *dbc,DWORD ofsContact,DWORD ofsModuleName) { struct DBContactSettings *dbcs; DWORD ofsThis; int i; for(i=0;i<SETTINGSGROUPOFSCOUNT;i++) { if(settingsGroupOfsCache[i].ofsContact==ofsContact && settingsGroupOfsCache[i].ofsModuleName==ofsModuleName) return settingsGroupOfsCache[i].ofsSettingsGroup; } ofsThis=dbc->ofsFirstSettings; while(ofsThis) { dbcs=(struct DBContactSettings*)DBRead(ofsThis,sizeof(struct DBContactSettings),NULL); if(dbcs->signature!=DBCONTACTSETTINGS_SIGNATURE) DatabaseCorruption(); if(dbcs->ofsModuleName==ofsModuleName) { settingsGroupOfsCache[nextSGOCacheEntry].ofsContact=ofsContact; settingsGroupOfsCache[nextSGOCacheEntry].ofsModuleName=ofsModuleName; settingsGroupOfsCache[nextSGOCacheEntry].ofsSettingsGroup=ofsThis; if(++nextSGOCacheEntry==SETTINGSGROUPOFSCOUNT) nextSGOCacheEntry=0; return ofsThis; } ofsThis=dbcs->ofsNext; } return 0; }
void CDb3Mmap::ConvertEvents() { DBContact dbc = *(DBContact*)DBRead(m_dbHeader.ofsUser, sizeof(DBContact), NULL); ConvertContactEvents(&dbc); DBWrite(m_dbHeader.ofsUser, &dbc, sizeof(dbc)); for (DWORD dwOffset = m_dbHeader.ofsFirstContact; dwOffset != 0;) { DBContact dbc = *(DBContact*)DBRead(dwOffset, sizeof(DBContact), NULL); ConvertContactEvents(&dbc); DBWrite(dwOffset, &dbc, sizeof(dbc)); if (m_contactsMap.find((ConvertedContact*)&dbc.dwContactID) == NULL) m_contactsMap.insert(new ConvertedContact(dwOffset, dbc.dwContactID)); dwOffset = dbc.ofsNext; } FlushViewOfFile(m_pDbCache, 0); }
STDMETHODIMP_(BOOL) CDb3Mmap::GetEvent(MEVENT hDbEvent, DBEVENTINFO *dbei) { if (dbei == nullptr) return 1; if (dbei->cbBlob > 0 && dbei->pBlob == nullptr) { dbei->cbBlob = 0; return 1; } mir_cslock lck(m_csDbAccess); DBEvent *dbe = AdaptEvent((DWORD)hDbEvent, 0); if (dbe->signature != DBEVENT_SIGNATURE) return 1; dbei->szModule = GetModuleNameByOfs(dbe->ofsModuleName); dbei->timestamp = dbe->timestamp; dbei->flags = dbe->flags; dbei->eventType = dbe->wEventType; int bytesToCopy = (dbei->cbBlob < dbe->cbBlob) ? dbei->cbBlob : dbe->cbBlob; dbei->cbBlob = dbe->cbBlob; if (bytesToCopy && dbei->pBlob) { BYTE *pSrc; if (m_dbHeader.version >= DB_095_1_VERSION) pSrc = DBRead(DWORD(hDbEvent) + offsetof(DBEvent, blob), nullptr); else pSrc = DBRead(DWORD(hDbEvent) + offsetof(DBEvent_094, blob), nullptr); if (dbe->flags & DBEF_ENCRYPTED) { dbei->flags &= ~DBEF_ENCRYPTED; size_t len; BYTE* pBlob = (BYTE*)m_crypto->decodeBuffer(pSrc, dbe->cbBlob, &len); if (pBlob == nullptr) return 1; memcpy(dbei->pBlob, pBlob, bytesToCopy); if (bytesToCopy > (int)len) memset(dbei->pBlob + len, 0, bytesToCopy - len); mir_free(pBlob); } else memcpy(dbei->pBlob, pSrc, bytesToCopy); } return 0; }
STDMETHODIMP_(HANDLE) CDb3Mmap::FindPrevEvent(MCONTACT contactID, HANDLE hDbEvent) { DBCachedContact *cc = (contactID) ? m_cache->GetCachedContact(contactID) : NULL; mir_cslock lck(m_csDbAccess); DBEvent *dbe = (DBEvent*)DBRead((DWORD)hDbEvent, sizeof(DBEvent), NULL); if (dbe->signature != DBEVENT_SIGNATURE) return NULL; if (!cc || !cc->IsSub()) return HANDLE(dbe->ofsPrev); for (DWORD dwOffset = dbe->ofsPrev; dwOffset != 0;) { dbe = (DBEvent*)DBRead(dwOffset, sizeof(DBEvent), NULL); if (dbe->signature != DBEVENT_SIGNATURE) return NULL; if (dbe->contactID == contactID) return HANDLE(dwOffset); dwOffset = dbe->ofsPrev; } return NULL; }
static INT_PTR GetBlobSize(WPARAM wParam,LPARAM lParam) { INT_PTR ret; struct DBEvent *dbe; EnterCriticalSection(&csDbAccess); dbe=(struct DBEvent*)DBRead(wParam,sizeof(struct DBEvent),NULL); if(dbe->signature!=DBEVENT_SIGNATURE) ret=-1; else ret=dbe->cbBlob; LeaveCriticalSection(&csDbAccess); return ret; }
int CDb3Mmap::InitModuleNames(void) { DWORD ofsThis = m_dbHeader.ofsModuleNames; DBModuleName *dbmn = (struct DBModuleName*)DBRead(ofsThis,sizeof(struct DBModuleName),NULL); while (ofsThis) { if (dbmn->signature != DBMODULENAME_SIGNATURE) DatabaseCorruption(NULL); int nameLen = dbmn->cbName; char *mod = (char*)HeapAlloc(m_hModHeap,0,nameLen+1); CopyMemory(mod,DBRead(ofsThis + offsetof(struct DBModuleName,name),nameLen,NULL),nameLen); mod[nameLen] = 0; AddToList(mod, nameLen, ofsThis); ofsThis = dbmn->ofsNext; dbmn = (struct DBModuleName*)DBRead(ofsThis,sizeof(struct DBModuleName),NULL); } return 0; }
STDMETHODIMP_(BOOL) CDb3Mmap::EnumContactSettings(MCONTACT contactID, DBCONTACTENUMSETTINGS* dbces) { if (!dbces->szModule) return -1; mir_cslock lck(m_csDbAccess); DWORD ofsContact = GetContactOffset(contactID); if (ofsContact == 0) return -1; DBContact *dbc = (DBContact*)DBRead(ofsContact, NULL); if (dbc->signature != DBCONTACT_SIGNATURE) return -1; DWORD ofsModuleName = GetModuleNameOfs(dbces->szModule); dbces->ofsSettings = GetSettingsGroupOfsByModuleNameOfs(dbc, ofsModuleName); if (!dbces->ofsSettings) return -1; DWORD ofsBlobPtr = dbces->ofsSettings + offsetof(DBContactSettings, blob); int bytesRemaining; PBYTE pBlob = (PBYTE)DBRead(ofsBlobPtr, &bytesRemaining); if (pBlob[0] == 0) return -1; int result = 0; while (pBlob[0]) { NeedBytes(1); NeedBytes(1 + pBlob[0]); char szSetting[256]; memcpy(szSetting, pBlob + 1, pBlob[0]); szSetting[pBlob[0]] = 0; result = (dbces->pfnEnumProc)(szSetting, dbces->lParam); MoveAlong(1 + pBlob[0]); NeedBytes(3); MoveAlong(1 + GetSettingValueLength(pBlob)); NeedBytes(1); } return result; }
static INT_PTR GetEventCount(WPARAM wParam,LPARAM lParam) { INT_PTR ret; struct DBContact *dbc; EnterCriticalSection(&csDbAccess); if(wParam==0) wParam=dbHeader.ofsUser; dbc=(struct DBContact*)DBRead(wParam,sizeof(struct DBContact),NULL); if(dbc->signature!=DBCONTACT_SIGNATURE) ret=-1; else ret=dbc->eventCount; LeaveCriticalSection(&csDbAccess); return ret; }
void CDb3Mmap::ConvertContactEvents(DBContact *dbc) { BYTE *pBlob = (PBYTE)mir_alloc(65536); DWORD ofsPrev = 0; __try { for (DWORD ofsEvent = dbc->ofsFirstEvent; ofsEvent != 0;) { DBEvent_094 pOld = *(DBEvent_094*)DBRead(ofsEvent, sizeof(DBEvent_094), NULL); if (pOld.signature != DBEVENT_SIGNATURE) break; if (pOld.cbBlob >= 65536) { ofsEvent = pOld.ofsNext; continue; } memcpy(pBlob, m_pDbCache + ofsEvent + offsetof(DBEvent_094, blob), pOld.cbBlob); DWORD ofsNew = ReallocSpace(ofsEvent, offsetof(DBEvent_094, blob) + pOld.cbBlob, offsetof(DBEvent, blob) + pOld.cbBlob); DBEvent *pNew = (DBEvent*)&m_pDbCache[ofsNew]; pNew->signature = pOld.signature; pNew->contactID = dbc->dwContactID; memcpy(&pNew->ofsPrev, &pOld.ofsPrev, offsetof(DBEvent_094, blob) - sizeof(DWORD)); memcpy(&pNew->blob, pBlob, pNew->cbBlob); if (pNew->flags & 1) { pNew->flags &= ~1; pNew->ofsPrev = 0; } if (ofsPrev == 0) // first event dbc->ofsFirstEvent = ofsNew, pNew->ofsPrev = 0; else { DBEvent *pPrev = (DBEvent*)&m_pDbCache[ofsPrev]; pPrev->ofsNext = ofsNew, pNew->ofsPrev = ofsPrev; } if (dbc->ofsFirstUnread == ofsEvent) dbc->ofsFirstUnread = ofsNew; if (dbc->ofsLastEvent == ofsEvent) dbc->ofsLastEvent = ofsNew; ofsPrev = ofsNew; ofsEvent = pNew->ofsNext; } } __except (EXCEPTION_EXECUTE_HANDLER) {} mir_free(pBlob); }
logical CTX_DBBase :: ExecuteAction (DB_Event intevent ) { logical term = NO; BEGINSEQ if ( !this ) LEAVESEQ switch ( intevent ) { case DBO_Opened : term = DBOpened(); break; case DBO_Initialize : term = DBInitialize(); break; case DBO_Created : if ( !(term = DBCreated()) ) intern_states.data_state = DAT_Filled; break; case DBO_NotCreated : term = DBNotCreated(); break; case DBO_Read : if ( !(term = DBRead()) ) intern_states.data_state = DAT_Filled; break; case DBO_Reset : term = DBReset(); break; case DBO_Stored : term = DBStored(); break; case DBO_Inserted : if ( !(term = DBInserted()) ) intern_states.data_state = DAT_Filled; break; case DBO_NotInserted: term = DBNotInserted(); break; case DBO_Removed : term = DBRemoved(); break; case DBO_NotRemoved : term = DBNotRemoved(); break; case DBO_Deleted : term = DBDeleted(); break; case DBO_NotDeleted : term = DBNotDeleted(); break; case DBO_Refresh : term = DBRefresh(); break; case DBO_NotOpened : term = DBNotOpened(); break; case DBO_Close : term = DBClose(); break; case DBP_Read : term = DBBeforeRead(); break; case DBP_Create : term = DBCreate(); break; case DBP_Modify : term = DBModify(); break; case DBP_Store : term = DBStore(); break; case DBP_Insert : term = DBInsert(); break; case DBP_Open : term = DBOpen(); break; case DBP_Remove : term = DBRemove(); break; case DBP_Delete : term = DBDelete(); break; case DBP_Select : term = DBSelect(); break; case DB_undefined : LEAVESEQ default : ERROR } RECOVER term = YES; ENDSEQ return(term); }
STDMETHODIMP_(BOOL) CDb3Mmap::GetEvent(HANDLE hDbEvent, DBEVENTINFO *dbei) { if (dbei == NULL || dbei->cbSize != sizeof(DBEVENTINFO)) return 1; if (dbei->cbBlob > 0 && dbei->pBlob == NULL) { dbei->cbBlob = 0; return 1; } mir_cslock lck(m_csDbAccess); DBEvent *dbe = (DBEvent*)DBRead((DWORD)hDbEvent, sizeof(DBEvent), NULL); if (dbe->signature != DBEVENT_SIGNATURE) return 1; dbei->szModule = GetModuleNameByOfs(dbe->ofsModuleName); dbei->timestamp = dbe->timestamp; dbei->flags = dbe->flags; dbei->eventType = dbe->wEventType; int bytesToCopy = (dbei->cbBlob < dbe->cbBlob) ? dbei->cbBlob : dbe->cbBlob; dbei->cbBlob = dbe->cbBlob; if (bytesToCopy && dbei->pBlob) { BYTE *pSrc = DBRead(DWORD(hDbEvent) + offsetof(DBEvent, blob), bytesToCopy, NULL); if (dbe->flags & DBEF_ENCRYPTED) { dbei->flags &= ~DBEF_ENCRYPTED; size_t len; BYTE* pBlob = (BYTE*)m_crypto->decodeBuffer(pSrc, dbe->cbBlob, &len); if (pBlob == NULL) return 1; memcpy(dbei->pBlob, pBlob, bytesToCopy); if (bytesToCopy > (int)len) memset(dbei->pBlob + len, 0, bytesToCopy - len); mir_free(pBlob); } else MoveMemory(dbei->pBlob, pSrc, bytesToCopy); } return 0; }
int CDb3Mmap::WipeContactHistory(DBContact *dbc) { // drop subContact's history if any for (DWORD dwOffset = dbc->ofsFirstEvent; dwOffset != 0;) { DBEvent *pev = (DBEvent*)DBRead(dwOffset, sizeof(DBEvent), NULL); if (pev->signature != DBEVENT_SIGNATURE) // broken chain, don't touch it return 2; DWORD dwNext = pev->ofsNext; DeleteSpace(dwOffset, offsetof(DBEvent, blob) + pev->cbBlob); dwOffset = dwNext; } dbc->eventCount = 0; dbc->ofsFirstEvent = dbc->ofsLastEvent = dbc->ofsFirstUnread = dbc->tsFirstUnread = 0; return 0; }
STDMETHODIMP_(BOOL) CDb3Mmap::IsDbContact(MCONTACT contactID) { DBCachedContact *cc = m_cache->GetCachedContact(contactID); if (cc == NULL) return FALSE; mir_cslock lck(m_csDbAccess); DBContact *dbc = (DBContact*)DBRead(cc->dwDriverData, NULL); if (dbc->signature == DBCONTACT_SIGNATURE) { m_cache->AddContactToCache(contactID); return TRUE; } return FALSE; }
static DWORD GetSettingsGroupOfsByModuleNameOfs(struct DBContact *dbc,DWORD ofsModuleName) { struct DBContactSettings *dbcs; DWORD ofsThis; ofsThis=dbc->ofsFirstSettings; while(ofsThis) { dbcs=(struct DBContactSettings*)DBRead(ofsThis,sizeof(struct DBContactSettings),NULL); if(dbcs->signature!=DBCONTACTSETTINGS_SIGNATURE) DatabaseCorruption(NULL); if(dbcs->ofsModuleName==ofsModuleName) return ofsThis; ofsThis=dbcs->ofsNext; } return 0; }
void CSchemaItem::SerializeDatabaseItem( ATTRIBUTEIDTODATAMAP &valuesMap, IArchive &ar ) { if( valuesMap.find( m_hszLabel.GetUniqueID() ) == valuesMap.end() || valuesMap[m_hszLabel.GetUniqueID()] == NULL ) { valuesMap[m_hszLabel.GetUniqueID()] = new DATABASEDATA( m_DefaultValue ); } DATABASEDATA *value = valuesMap[m_hszLabel.GetUniqueID()]; TCHAR *tag = (TCHAR*)m_hszLabel.GetString(); if( ar.IsReading() ) { DBRead( value, &ar, tag ); } else { DBWrite( value, &ar, tag ); } }
static INT_PTR IsDbContact(WPARAM wParam,LPARAM lParam) { struct DBContact *dbc; DWORD ofsContact=(DWORD)wParam; int ret; EnterCriticalSection(&csDbAccess); { int index; DBCachedContactValueList VLtemp; VLtemp.hContact = (HANDLE)wParam; if ( li.List_GetIndex(&lContacts,&VLtemp,&index)) ret = TRUE; else { dbc=(struct DBContact*)DBRead(ofsContact,sizeof(struct DBContact),NULL); ret=dbc->signature==DBCONTACT_SIGNATURE; if (ret) AddToCachedContactList((HANDLE)wParam, index); } } LeaveCriticalSection(&csDbAccess); return ret; }
void CSchemaItem::Serialize( IArchive &ar ) { if( ar.IsReading() ) { StdString name; // Dummy variable to read the name. It should already be stored as CObjectTemplate StdString type; StdString attributeClass; ar.Read( m_fVersion, _T("Version") ); ar.Read( name, _T("Name") ); ar.Read( type, _T("Type") ); ar.Read( attributeClass, _T("Class") ); m_hszLabel.Init( name ); m_hszType.Init( type ); m_hszClass.Init( attributeClass ); DBRead( &m_DefaultValue, &ar, _T("Default") ); // IMPORTANT: DBRead is dependent on m_hszType. Make sure m_hszType has been initialized before calling DBRead. // NOTE: We are assuming the order in which schema items are instantiated will be // the order in which to read data items. if( m_Schema != NULL ) { m_Schema->RegisterSchemaItem( this ); } } else { ar.StartClass(_T("CSchemaItem")); ar.Write( m_fVersion, _T("Version") ); ar.Write( m_hszLabel.GetString(), _T("Name") ); ar.Write( m_hszType.GetString(), _T("Type") ); ar.Write( m_hszClass.GetString(), _T("Class") ); DBWrite( &m_DefaultValue, &ar, _T("Default") ); ar.EndClass(); } }
static INT_PTR FindNextContact(WPARAM wParam,LPARAM lParam) { int index; struct DBContact *dbc; DBCachedContactValueList VLtemp, *VL = NULL; VLtemp.hContact = (HANDLE)wParam; EnterCriticalSection(&csDbAccess); while(VLtemp.hContact) { if ( li.List_GetIndex(&lContacts,&VLtemp,&index)) { VL = ( DBCachedContactValueList* )lContacts.items[index]; if (VL->hNext != NULL) { if (!lParam || CheckProto(VL->hNext,(const char*)lParam)) { LeaveCriticalSection(&csDbAccess); return (INT_PTR)VL->hNext; } else { VLtemp.hContact = VL->hNext; continue; } } } dbc=(struct DBContact*)DBRead((DWORD)VLtemp.hContact,sizeof(struct DBContact),NULL); if (dbc->signature!=DBCONTACT_SIGNATURE) break; else { if ( VL == NULL ) VL = AddToCachedContactList(VLtemp.hContact,index); VL->hNext = (HANDLE)dbc->ofsNext; if (VL->hNext != NULL && (!lParam || CheckProto(VL->hNext,(const char*)lParam))) { LeaveCriticalSection(&csDbAccess); return (INT_PTR)VL->hNext; } VLtemp.hContact = VL->hNext; } } LeaveCriticalSection(&csDbAccess); return 0; }
static INT_PTR WriteContactSetting(WPARAM wParam, LPARAM lParam) { DBCONTACTWRITESETTING *dbcws=(DBCONTACTWRITESETTING*)lParam; DBCONTACTWRITESETTING tmp; struct DBContact dbc; DWORD ofsModuleName; struct DBContactSettings dbcs; PBYTE pBlob; int settingNameLen=0; int moduleNameLen=0; int settingDataLen=0; int bytesRequired,bytesRemaining; DWORD ofsContact,ofsSettingsGroup,ofsBlobPtr; if (dbcws == NULL || dbcws->szSetting==NULL || dbcws->szModule==NULL ) return 1; // the db format can't tolerate more than 255 bytes of space (incl. null) for settings+module name settingNameLen=(int)strlen(dbcws->szSetting); moduleNameLen=(int)strlen(dbcws->szModule); if ( settingNameLen > 0xFE ) { #ifdef _DEBUG OutputDebugStringA("WriteContactSetting() got a > 255 setting name length. \n"); #endif return 1; } if ( moduleNameLen > 0xFE ) { #ifdef _DEBUG OutputDebugStringA("WriteContactSetting() got a > 255 module name length. \n"); #endif return 1; } tmp = *dbcws; if (tmp.value.type == DBVT_WCHAR) { if (tmp.value.pszVal != NULL) { char* val = mir_utf8encodeW(tmp.value.pwszVal); if ( val == NULL ) return 1; tmp.value.pszVal = ( char* )_malloca( strlen( val )+1 ); strcpy( tmp.value.pszVal, val ); mir_free(val); tmp.value.type = DBVT_UTF8; } else return 1; } if(tmp.value.type!=DBVT_BYTE && tmp.value.type!=DBVT_WORD && tmp.value.type!=DBVT_DWORD && tmp.value.type!=DBVT_ASCIIZ && tmp.value.type!=DBVT_UTF8 && tmp.value.type!=DBVT_BLOB) return 1; if ((!tmp.szModule) || (!tmp.szSetting) || ((tmp.value.type == DBVT_ASCIIZ || tmp.value.type == DBVT_UTF8 )&& tmp.value.pszVal == NULL) || (tmp.value.type == DBVT_BLOB && tmp.value.pbVal == NULL) ) return 1; // the db can not tolerate strings/blobs longer than 0xFFFF since the format writes 2 lengths switch( tmp.value.type ) { case DBVT_ASCIIZ: case DBVT_BLOB: case DBVT_UTF8: { size_t len = ( tmp.value.type != DBVT_BLOB ) ? (int)strlen(tmp.value.pszVal) : tmp.value.cpbVal; if ( len >= 0xFFFF ) { #ifdef _DEBUG OutputDebugStringA("WriteContactSetting() writing huge string/blob, rejecting ( >= 0xFFFF ) \n"); #endif return 1; } } } EnterCriticalSection(&csDbAccess); { char* szCachedSettingName = GetCachedSetting(tmp.szModule, tmp.szSetting, moduleNameLen, settingNameLen); if ( tmp.value.type != DBVT_BLOB ) { DBVARIANT* pCachedValue = GetCachedValuePtr((HANDLE)wParam, szCachedSettingName, 1); if ( pCachedValue != NULL ) { BOOL bIsIdentical = FALSE; if ( pCachedValue->type == tmp.value.type ) { switch(tmp.value.type) { case DBVT_BYTE: bIsIdentical = pCachedValue->bVal == tmp.value.bVal; break; case DBVT_WORD: bIsIdentical = pCachedValue->wVal == tmp.value.wVal; break; case DBVT_DWORD: bIsIdentical = pCachedValue->dVal == tmp.value.dVal; break; case DBVT_UTF8: case DBVT_ASCIIZ: bIsIdentical = strcmp( pCachedValue->pszVal, tmp.value.pszVal ) == 0; break; } if ( bIsIdentical ) { LeaveCriticalSection(&csDbAccess); return 0; } } SetCachedVariant(&tmp.value, pCachedValue); } if ( szCachedSettingName[-1] != 0 ) { LeaveCriticalSection(&csDbAccess); NotifyEventHooks(hSettingChangeEvent,wParam,(LPARAM)&tmp); return 0; } } else GetCachedValuePtr((HANDLE)wParam, szCachedSettingName, -1); } ofsModuleName=GetModuleNameOfs(tmp.szModule); if(wParam==0) ofsContact=dbHeader.ofsUser; else ofsContact=wParam; dbc=*(struct DBContact*)DBRead(ofsContact,sizeof(struct DBContact),NULL); if(dbc.signature!=DBCONTACT_SIGNATURE) { LeaveCriticalSection(&csDbAccess); return 1; } log0("write setting"); //make sure the module group exists ofsSettingsGroup=GetSettingsGroupOfsByModuleNameOfs(&dbc,ofsModuleName); if(ofsSettingsGroup==0) { //module group didn't exist - make it if(tmp.value.type&DBVTF_VARIABLELENGTH) { if(tmp.value.type==DBVT_ASCIIZ || tmp.value.type==DBVT_UTF8) bytesRequired = (int)strlen(tmp.value.pszVal)+2; else if(tmp.value.type==DBVT_BLOB) bytesRequired=tmp.value.cpbVal+2; } else bytesRequired=tmp.value.type; bytesRequired+=2+settingNameLen; bytesRequired+=(DB_SETTINGS_RESIZE_GRANULARITY-(bytesRequired%DB_SETTINGS_RESIZE_GRANULARITY))%DB_SETTINGS_RESIZE_GRANULARITY; ofsSettingsGroup=CreateNewSpace(bytesRequired+offsetof(struct DBContactSettings,blob)); dbcs.signature=DBCONTACTSETTINGS_SIGNATURE; dbcs.ofsNext=dbc.ofsFirstSettings; dbcs.ofsModuleName=ofsModuleName; dbcs.cbBlob=bytesRequired; dbcs.blob[0]=0; dbc.ofsFirstSettings=ofsSettingsGroup; DBWrite(ofsContact,&dbc,sizeof(struct DBContact)); DBWrite(ofsSettingsGroup,&dbcs,sizeof(struct DBContactSettings)); ofsBlobPtr=ofsSettingsGroup+offsetof(struct DBContactSettings,blob); pBlob=(PBYTE)DBRead(ofsBlobPtr,1,&bytesRemaining); } else {
static INT_PTR AddEvent(WPARAM wParam,LPARAM lParam) { DBEVENTINFO *dbei=(DBEVENTINFO*)lParam; struct DBContact dbc; struct DBEvent dbe,*dbeTest; DWORD ofsNew,ofsModuleName,ofsContact,ofsThis; if(dbei==NULL||dbei->cbSize!=sizeof(DBEVENTINFO)) return 0; if(dbei->timestamp==0) return 0; if (NotifyEventHooks(hEventFilterAddedEvent,wParam,lParam)) { return 0; } EnterCriticalSection(&csDbAccess); if(wParam==0) ofsContact=dbHeader.ofsUser; else ofsContact=wParam; dbc=*(struct DBContact*)DBRead(ofsContact,sizeof(struct DBContact),NULL); if(dbc.signature!=DBCONTACT_SIGNATURE) { LeaveCriticalSection(&csDbAccess); return 0; } ofsNew=CreateNewSpace(offsetof(struct DBEvent,blob)+dbei->cbBlob); ofsModuleName=GetModuleNameOfs(dbei->szModule); dbe.signature=DBEVENT_SIGNATURE; dbe.ofsModuleName=ofsModuleName; dbe.timestamp=dbei->timestamp; dbe.flags=dbei->flags; dbe.eventType=dbei->eventType; dbe.cbBlob=dbei->cbBlob; //find where to put it - sort by timestamp if(dbc.eventCount==0) { dbe.ofsPrev=wParam; dbe.ofsNext=0; dbe.flags|=DBEF_FIRST; dbc.ofsFirstEvent=dbc.ofsLastEvent=ofsNew; } else { dbeTest=(struct DBEvent*)DBRead(dbc.ofsFirstEvent,sizeof(struct DBEvent),NULL); // Should new event be placed before first event in chain? if (dbei->timestamp < dbeTest->timestamp) { dbe.ofsPrev=wParam; dbe.ofsNext=dbc.ofsFirstEvent; dbe.flags|=DBEF_FIRST; dbc.ofsFirstEvent=ofsNew; dbeTest=(struct DBEvent*)DBRead(dbe.ofsNext,sizeof(struct DBEvent),NULL); dbeTest->flags&=~DBEF_FIRST; dbeTest->ofsPrev=ofsNew; DBWrite(dbe.ofsNext,dbeTest,sizeof(struct DBEvent)); } else { // Loop through the chain, starting at the end ofsThis = dbc.ofsLastEvent; dbeTest = (struct DBEvent*)DBRead(ofsThis, sizeof(struct DBEvent), NULL); for(;;) { // If the new event's timesstamp is equal to or greater than the // current dbevent, it will be inserted after. If not, continue // with the previous dbevent in chain. if (dbe.timestamp >= dbeTest->timestamp) { dbe.ofsPrev = ofsThis; dbe.ofsNext = dbeTest->ofsNext; dbeTest->ofsNext = ofsNew; DBWrite(ofsThis, dbeTest, sizeof(struct DBEvent)); if (dbe.ofsNext == 0) dbc.ofsLastEvent = ofsNew; else { dbeTest = (struct DBEvent*)DBRead(dbe.ofsNext, sizeof(struct DBEvent), NULL); dbeTest->ofsPrev = ofsNew; DBWrite(dbe.ofsNext, dbeTest, sizeof(struct DBEvent)); } break; } ofsThis = dbeTest->ofsPrev; dbeTest = (struct DBEvent*)DBRead(ofsThis, sizeof(struct DBEvent), NULL); } } } dbc.eventCount++; if(!(dbe.flags&(DBEF_READ|DBEF_SENT))) { if(dbe.timestamp<dbc.timestampFirstUnread || dbc.timestampFirstUnread==0) { dbc.timestampFirstUnread=dbe.timestamp; dbc.ofsFirstUnreadEvent=ofsNew; } } DBWrite(ofsContact,&dbc,sizeof(struct DBContact)); DBWrite(ofsNew,&dbe,offsetof(struct DBEvent,blob)); DBWrite(ofsNew+offsetof(struct DBEvent,blob),dbei->pBlob,dbei->cbBlob); DBFlush(0); LeaveCriticalSection(&csDbAccess); log1("add event @ %08x",ofsNew); NotifyEventHooks(hEventAddedEvent,wParam,(LPARAM)ofsNew); return (INT_PTR)ofsNew; }
static __inline int GetContactSettingWorker(HANDLE hContact,DBCONTACTGETSETTING *dbcgs,int isStatic) { struct DBContact *dbc; DWORD ofsModuleName,ofsContact,ofsSettingsGroup,ofsBlobPtr; int settingNameLen,moduleNameLen; int bytesRemaining; PBYTE pBlob; char* szCachedSettingName; if ((!dbcgs->szSetting) || (!dbcgs->szModule)) return 1; // the db format can't tolerate more than 255 bytes of space (incl. null) for settings+module name settingNameLen = (int)strlen(dbcgs->szSetting); moduleNameLen = (int)strlen(dbcgs->szModule); if ( settingNameLen > 0xFE ) { #ifdef _DEBUG OutputDebugStringA("GetContactSettingWorker() got a > 255 setting name length. \n"); #endif return 1; } if ( moduleNameLen > 0xFE ) { #ifdef _DEBUG OutputDebugStringA("GetContactSettingWorker() got a > 255 module name length. \n"); #endif return 1; } EnterCriticalSection(&csDbAccess); log3("get [%08p] %s/%s",hContact,dbcgs->szModule,dbcgs->szSetting); szCachedSettingName = GetCachedSetting(dbcgs->szModule,dbcgs->szSetting,moduleNameLen,settingNameLen); { DBVARIANT* pCachedValue = GetCachedValuePtr( hContact, szCachedSettingName, 0 ); if ( pCachedValue != NULL ) { if ( pCachedValue->type == DBVT_ASCIIZ || pCachedValue->type == DBVT_UTF8 ) { int cbOrigLen = dbcgs->pValue->cchVal; char* cbOrigPtr = dbcgs->pValue->pszVal; memcpy( dbcgs->pValue, pCachedValue, sizeof( DBVARIANT )); if ( isStatic ) { int cbLen = 0; if ( pCachedValue->pszVal != NULL ) cbLen = (int)strlen( pCachedValue->pszVal ); cbOrigLen--; dbcgs->pValue->pszVal = cbOrigPtr; if(cbLen<cbOrigLen) cbOrigLen=cbLen; CopyMemory(dbcgs->pValue->pszVal,pCachedValue->pszVal,cbOrigLen); dbcgs->pValue->pszVal[cbOrigLen]=0; dbcgs->pValue->cchVal=cbLen; } else { dbcgs->pValue->pszVal = (char*)mir_alloc(strlen(pCachedValue->pszVal)+1); strcpy(dbcgs->pValue->pszVal,pCachedValue->pszVal); } } else memcpy( dbcgs->pValue, pCachedValue, sizeof( DBVARIANT )); switch( dbcgs->pValue->type ) { case DBVT_BYTE: log1( "get cached byte: %d", dbcgs->pValue->bVal ); break; case DBVT_WORD: log1( "get cached word: %d", dbcgs->pValue->wVal ); break; case DBVT_DWORD: log1( "get cached dword: %d", dbcgs->pValue->dVal ); break; case DBVT_UTF8: case DBVT_ASCIIZ: log1( "get cached string: '%s'", dbcgs->pValue->pszVal); break; default: log1( "get cached crap: %d", dbcgs->pValue->type ); break; } LeaveCriticalSection(&csDbAccess); return ( pCachedValue->type == DBVT_DELETED ) ? 1 : 0; } } ofsModuleName=GetModuleNameOfs(dbcgs->szModule); if(hContact==NULL) ofsContact=dbHeader.ofsUser; else ofsContact=(DWORD)hContact; dbc=(struct DBContact*)DBRead(ofsContact,sizeof(struct DBContact),NULL); if(dbc->signature!=DBCONTACT_SIGNATURE) { LeaveCriticalSection(&csDbAccess); return 1; } ofsSettingsGroup=GetSettingsGroupOfsByModuleNameOfs(dbc,ofsModuleName); if(ofsSettingsGroup) { ofsBlobPtr=ofsSettingsGroup+offsetof(struct DBContactSettings,blob); pBlob = DBRead(ofsBlobPtr,sizeof(struct DBContactSettings),&bytesRemaining); while(pBlob[0]) { NeedBytes(1+settingNameLen); if(pBlob[0]==settingNameLen && !memcmp(pBlob+1,dbcgs->szSetting,settingNameLen)) { MoveAlong(1+settingNameLen); NeedBytes(5); if(isStatic && pBlob[0]&DBVTF_VARIABLELENGTH && VLT(dbcgs->pValue->type) != VLT(pBlob[0])) { LeaveCriticalSection(&csDbAccess); return 1; } dbcgs->pValue->type=pBlob[0]; switch(pBlob[0]) { case DBVT_DELETED: { /* this setting is deleted */ dbcgs->pValue->type=DBVT_DELETED; LeaveCriticalSection(&csDbAccess); return 2; } case DBVT_BYTE: dbcgs->pValue->bVal=pBlob[1]; break; case DBVT_WORD: DecodeCopyMemory(&(dbcgs->pValue->wVal), (PWORD)(pBlob+1), 2); break; case DBVT_DWORD: DecodeCopyMemory(&(dbcgs->pValue->dVal), (PDWORD)(pBlob+1), 4); break; case DBVT_UTF8: case DBVT_ASCIIZ: NeedBytes(3+*(PWORD)(pBlob+1)); if(isStatic) { dbcgs->pValue->cchVal--; if(*(PWORD)(pBlob+1)<dbcgs->pValue->cchVal) dbcgs->pValue->cchVal=*(PWORD)(pBlob+1); DecodeCopyMemory(dbcgs->pValue->pszVal,pBlob+3,dbcgs->pValue->cchVal); dbcgs->pValue->pszVal[dbcgs->pValue->cchVal]=0; dbcgs->pValue->cchVal=*(PWORD)(pBlob+1); } else { dbcgs->pValue->pszVal=(char*)mir_alloc(1+*(PWORD)(pBlob+1)); DecodeCopyMemory(dbcgs->pValue->pszVal,pBlob+3,*(PWORD)(pBlob+1)); dbcgs->pValue->pszVal[*(PWORD)(pBlob+1)]=0; } break; case DBVT_BLOB: NeedBytes(3+*(PWORD)(pBlob+1)); if(isStatic) { if(*(PWORD)(pBlob+1)<dbcgs->pValue->cpbVal) dbcgs->pValue->cpbVal=*(PWORD)(pBlob+1); DecodeCopyMemory(dbcgs->pValue->pbVal,pBlob+3,dbcgs->pValue->cpbVal); } else { dbcgs->pValue->pbVal=(char*)mir_alloc(*(PWORD)(pBlob+1)); DecodeCopyMemory(dbcgs->pValue->pbVal,pBlob+3,*(PWORD)(pBlob+1)); } dbcgs->pValue->cpbVal=*(PWORD)(pBlob+1); break; } /**** add to cache **********************/ if ( dbcgs->pValue->type != DBVT_BLOB ) { DBVARIANT* pCachedValue = GetCachedValuePtr( hContact, szCachedSettingName, 1 ); if ( pCachedValue != NULL ) SetCachedVariant(dbcgs->pValue,pCachedValue); } LeaveCriticalSection(&csDbAccess); logg(); return 0; } NeedBytes(1); MoveAlong(pBlob[0]+1); NeedBytes(3); MoveAlong(1+GetSettingValueLength(pBlob)); NeedBytes(1); } } /**** nullbie: query info from preset **********************/ if (!hContact && DBPreset_QuerySetting(dbcgs->szModule, dbcgs->szSetting, dbcgs->pValue, isStatic)) { /**** add to cache **********************/ if ( dbcgs->pValue->type != DBVT_BLOB ) { DBVARIANT* pCachedValue = GetCachedValuePtr( hContact, szCachedSettingName, 1 ); if ( pCachedValue != NULL ) SetCachedVariant(dbcgs->pValue,pCachedValue); } return 0; } /**** add missing setting to cache **********************/ if ( dbcgs->pValue->type != DBVT_BLOB ) { DBVARIANT* pCachedValue = GetCachedValuePtr( hContact, szCachedSettingName, 1 ); if ( pCachedValue != NULL ) pCachedValue->type = DBVT_DELETED; } LeaveCriticalSection(&csDbAccess); logg(); return 1; }
bytesRequired+=2+settingNameLen; bytesRequired+=(DB_SETTINGS_RESIZE_GRANULARITY-(bytesRequired%DB_SETTINGS_RESIZE_GRANULARITY))%DB_SETTINGS_RESIZE_GRANULARITY; ofsSettingsGroup=CreateNewSpace(bytesRequired+offsetof(struct DBContactSettings,blob)); dbcs.signature=DBCONTACTSETTINGS_SIGNATURE; dbcs.ofsNext=dbc.ofsFirstSettings; dbcs.ofsModuleName=ofsModuleName; dbcs.cbBlob=bytesRequired; dbcs.blob[0]=0; dbc.ofsFirstSettings=ofsSettingsGroup; DBWrite(ofsContact,&dbc,sizeof(struct DBContact)); DBWrite(ofsSettingsGroup,&dbcs,sizeof(struct DBContactSettings)); ofsBlobPtr=ofsSettingsGroup+offsetof(struct DBContactSettings,blob); pBlob=(PBYTE)DBRead(ofsBlobPtr,1,&bytesRemaining); } else { dbcs=*(struct DBContactSettings*)DBRead(ofsSettingsGroup,sizeof(struct DBContactSettings),&bytesRemaining); //find if the setting exists ofsBlobPtr=ofsSettingsGroup+offsetof(struct DBContactSettings,blob); pBlob=(PBYTE)DBRead(ofsBlobPtr,1,&bytesRemaining); while(pBlob[0]) { NeedBytes(settingNameLen+1); if(pBlob[0]==settingNameLen && !memcmp(pBlob+1,tmp.szSetting,settingNameLen)) break; NeedBytes(1); MoveAlong(pBlob[0]+1); NeedBytes(3); MoveAlong(1+GetSettingValueLength(pBlob)); NeedBytes(1); } if(pBlob[0]) { //setting already existed, and up to end of name is in cache MoveAlong(1+settingNameLen);
void conv(register FILE *fp, int baseline) { register FILE *gfp = NULL; /* input file pointer */ register int done = 0; /* flag to remember if finished */ register ELT *e; /* current element pointer */ ELT *PICTURE; /* whole picture data base pointer */ double temp; /* temporary calculating area */ /* POINT ptr; */ /* coordinates of a point to pass to `mov' */ /* routine */ int flyback; /* flag `want to end up at the top of the */ /* picture?' */ int compat; /* test character after .GE or .GF */ initpic(); /* set defaults, ranges, etc. */ strcpy(GScommand, inputline); /* save `.GS' line for later */ do { done = !doinput(fp); /* test for EOF */ flyback = (*c3 == 'F'); /* and .GE or .GF */ compat = (compatibility_flag || *c4 == '\n' || *c4 == ' ' || *c4 == '\0'); done |= (*c1 == '.' && *c2 == 'G' && (*c3 == 'E' || flyback) && compat); if (done) { if (setdefault) savestate(); if (!gremlinfile[0]) { if (!setdefault) error("at line %1: no picture filename.\n", baseline); return; } char *path; gfp = macro_path.open_file(gremlinfile, &path); if (!gfp) return; PICTURE = DBRead(gfp); /* read picture file */ fclose(gfp); a_delete path; if (DBNullelt(PICTURE)) return; /* If a request is made to make the */ /* picture fit into a specific area, */ /* set the scale to do that. */ if (stipple == (char *) NULL) /* if user forgot stipple */ if (has_polygon(PICTURE)) /* and picture has a polygon */ stipple = (char *)DEFSTIPPLE; /* then set the default */ if ((temp = bottompoint - toppoint) < 0.1) temp = 0.1; temp = (height != 0.0) ? height / (temp * SCREENtoINCH) : BIG; if ((troffscale = rightpoint - leftpoint) < 0.1) troffscale = 0.1; troffscale = (width != 0.0) ? width / (troffscale * SCREENtoINCH) : BIG; if (temp == BIG && troffscale == BIG) troffscale = xscale; else { if (temp < troffscale) troffscale = temp; } /* here, troffscale is the */ /* picture's scaling factor */ if (pointscale) { register int i; /* do pointscaling here, when */ /* scale is known, before output */ for (i = 0; i < SIZES; i++) tsize[i] = (int) (troffscale * (double) tsize[i] + 0.5); } /* change to device units */ troffscale *= SCREENtoINCH * res; /* from screen units */ ytop = (int) (toppoint * troffscale); /* calculate integer */ ybottom = (int) (bottompoint * troffscale); /* versions of the */ xleft = (int) (leftpoint * troffscale); /* picture limits */ xright = (int) (rightpoint * troffscale); /* save stuff in number registers, */ /* register g1 = picture width and */ /* register g2 = picture height, */ /* set vertical spacing, no fill, */ /* and break (to make sure picture */ /* starts on left), and put out the */ /* user's `.GS' line. */ printf(".br\n" ".nr g1 %du\n" ".nr g2 %du\n" "%s" ".nr g3 \\n(.f\n" ".nr g4 \\n(.s\n" "\\0\n" ".sp -1\n", xright - xleft, ybottom - ytop, GScommand); if (stipple) /* stipple requested for this picture */ printf(".st %s\n", stipple); lastx = xleft; /* note where we are (upper left */ lastyline = lasty = ytop; /* corner of the picture) */ /* Just dump everything in the order it appears. * * If -s command-line option, traverse picture twice: First time, * print only the interiors of filled polygons (as borderless * polygons). Second time, print the outline as series of line * segments. This way, postprocessors that overwrite rather than * merge picture elements (such as Postscript) can still have text and * graphics on a shaded background. */ /* if (sflag) */ if (!sflag) { /* changing the default for filled polygons */ e = PICTURE; polyfill = FILL; while (!DBNullelt(e)) { printf(".mk\n"); if (e->type == POLYGON) HGPrintElt(e, baseline); printf(".rt\n"); lastx = xleft; lastyline = lasty = ytop; e = DBNextElt(e); } } e = PICTURE; /* polyfill = !sflag ? BOTH : OUTLINE; */ polyfill = sflag ? BOTH : OUTLINE; /* changing the default */ while (!DBNullelt(e)) { printf(".mk\n"); HGPrintElt(e, baseline); printf(".rt\n"); lastx = xleft; lastyline = lasty = ytop; e = DBNextElt(e); } /* decide where to end picture */ /* I changed everything here. I always use the combination .mk and */ /* .rt so once finished I just space down the heigth of the picture */ /* that is \n(g2u */ if (flyback) { /* end picture at upper left */ /* ptr.x = leftpoint; ptr.y = toppoint; */ } else { /* end picture at lower left */ /* ptr.x = leftpoint; ptr.y = bottompoint; */ printf(".sp \\n(g2u\n"); } /* tmove(&ptr); */ /* restore default line parameters */ /* restore everything to the way it was before the .GS, then put */ /* out the `.GE' line from user */ /* printf("\\D't %du'\\D's %du'\n", DEFTHICK, DEFSTYLE); */ /* groff doesn't understand the \Ds command */ printf("\\D't %du'\n", DEFTHICK); if (flyback) /* make sure we end up at top of */ printf(".sp -1\n"); /* picture if `flying back' */ if (stipple) /* restore stipple to previous */ printf(".st\n"); printf(".br\n" ".ft \\n(g3\n" ".ps \\n(g4\n" "%s", inputline); } else interpret(inputline); /* take commands from the input file */ } while (!done); }
static __inline int GetContactSettingWorker(HANDLE hContact,DBCONTACTGETSETTING *dbcgs,int isStatic) { struct DBContact dbc; struct DBContactSettings dbcs; DWORD ofsModuleName,ofsContact,ofsSettingsGroup,ofsBlobPtr; int settingNameLen; int bytesRemaining; PBYTE pBlob; char* szCachedSettingName; if ((!dbcgs->szSetting) || (!dbcgs->szModule)) return 1; settingNameLen=(int)strlen(dbcgs->szSetting); EnterCriticalSection(&csDbAccess); log3("get [%08p] %s/%s",hContact,dbcgs->szModule,dbcgs->szSetting); szCachedSettingName = GetCachedSetting(dbcgs->szModule,dbcgs->szSetting,settingNameLen); { DBVARIANT* pCachedValue = GetCachedValuePtr( hContact, szCachedSettingName, 0 ); if ( pCachedValue != NULL ) { if ( pCachedValue->type == DBVT_ASCIIZ || pCachedValue->type == DBVT_UTF8 ) { int cbOrigLen = dbcgs->pValue->cchVal; char* cbOrigPtr = dbcgs->pValue->pszVal; memcpy( dbcgs->pValue, pCachedValue, sizeof( DBVARIANT )); if ( isStatic ) { int cbLen = 0; if ( pCachedValue->pszVal != NULL ) cbLen = (int)strlen( pCachedValue->pszVal ); cbOrigLen--; dbcgs->pValue->pszVal = cbOrigPtr; if(cbLen<cbOrigLen) cbOrigLen=cbLen; CopyMemory(dbcgs->pValue->pszVal,pCachedValue->pszVal,cbOrigLen); dbcgs->pValue->pszVal[cbOrigLen]=0; dbcgs->pValue->cchVal=cbLen; } else { dbcgs->pValue->pszVal = (char*)mir_alloc(strlen(pCachedValue->pszVal)+1); strcpy(dbcgs->pValue->pszVal,pCachedValue->pszVal); } } else memcpy( dbcgs->pValue, pCachedValue, sizeof( DBVARIANT )); switch( dbcgs->pValue->type ) { case DBVT_BYTE: log1( "get cached byte: %d", dbcgs->pValue->bVal ); break; case DBVT_WORD: log1( "get cached word: %d", dbcgs->pValue->wVal ); break; case DBVT_DWORD: log1( "get cached dword: %d", dbcgs->pValue->dVal ); break; case DBVT_UTF8: case DBVT_ASCIIZ: log1( "get cached string: '%s'", dbcgs->pValue->pszVal); break; default: log1( "get cached crap: %d", dbcgs->pValue->type ); break; } LeaveCriticalSection(&csDbAccess); return ( pCachedValue->type == DBVT_DELETED ) ? 1 : 0; } } ofsModuleName=GetModuleNameOfs(dbcgs->szModule); if(hContact==NULL) ofsContact=dbHeader.ofsUser; else ofsContact=(DWORD)hContact; dbc=*(struct DBContact*)DBRead(ofsContact,sizeof(struct DBContact),NULL); if(dbc.signature!=DBCONTACT_SIGNATURE) { LeaveCriticalSection(&csDbAccess); return 1; } ofsSettingsGroup=GetSettingsGroupOfsByModuleNameOfs(&dbc,ofsContact,ofsModuleName); if(ofsSettingsGroup) { dbcs=*(struct DBContactSettings*)DBRead(ofsSettingsGroup,sizeof(struct DBContactSettings),&bytesRemaining); ofsBlobPtr=ofsSettingsGroup+offsetof(struct DBContactSettings,blob); pBlob=(PBYTE)DBRead(ofsBlobPtr,1,&bytesRemaining); while(pBlob[0]) { NeedBytes(1+settingNameLen); if(pBlob[0]==settingNameLen && !memcmp(pBlob+1,dbcgs->szSetting,settingNameLen)) { MoveAlong(1+settingNameLen); NeedBytes(5); if(isStatic && pBlob[0]&DBVTF_VARIABLELENGTH && VLT(dbcgs->pValue->type) != VLT(pBlob[0])) { LeaveCriticalSection(&csDbAccess); return 1; } dbcgs->pValue->type=pBlob[0]; switch(pBlob[0]) { case DBVT_DELETED: { /* this setting is deleted */ dbcgs->pValue->type=DBVT_DELETED; LeaveCriticalSection(&csDbAccess); return 2; } case DBVT_BYTE: dbcgs->pValue->bVal=pBlob[1]; break; case DBVT_WORD: dbcgs->pValue->wVal=*(PWORD)(pBlob+1); break; case DBVT_DWORD: dbcgs->pValue->dVal=*(PDWORD)(pBlob+1); break; case DBVT_UTF8: case DBVT_ASCIIZ: NeedBytes(3+*(PWORD)(pBlob+1)); if(isStatic) { dbcgs->pValue->cchVal--; if(*(PWORD)(pBlob+1)<dbcgs->pValue->cchVal) dbcgs->pValue->cchVal=*(PWORD)(pBlob+1); CopyMemory(dbcgs->pValue->pszVal,pBlob+3,dbcgs->pValue->cchVal); dbcgs->pValue->pszVal[dbcgs->pValue->cchVal]=0; dbcgs->pValue->cchVal=*(PWORD)(pBlob+1); } else { dbcgs->pValue->pszVal=(char*)mir_alloc(1+*(PWORD)(pBlob+1)); CopyMemory(dbcgs->pValue->pszVal,pBlob+3,*(PWORD)(pBlob+1)); dbcgs->pValue->pszVal[*(PWORD)(pBlob+1)]=0; } break; case DBVT_BLOB: NeedBytes(3+*(PWORD)(pBlob+1)); if(isStatic) { if(*(PWORD)(pBlob+1)<dbcgs->pValue->cpbVal) dbcgs->pValue->cpbVal=*(PWORD)(pBlob+1); CopyMemory(dbcgs->pValue->pbVal,pBlob+3,dbcgs->pValue->cpbVal); } else { dbcgs->pValue->pbVal=(char*)mir_alloc(*(PWORD)(pBlob+1)); CopyMemory(dbcgs->pValue->pbVal,pBlob+3,*(PWORD)(pBlob+1)); } dbcgs->pValue->cpbVal=*(PWORD)(pBlob+1); break; } /**** add to cache **********************/ if ( dbcgs->pValue->type != DBVT_BLOB ) { DBVARIANT* pCachedValue = GetCachedValuePtr( hContact, szCachedSettingName, 1 ); if ( pCachedValue != NULL ) SetCachedVariant(dbcgs->pValue,pCachedValue); } LeaveCriticalSection(&csDbAccess); logg(); return 0; } NeedBytes(1); MoveAlong(pBlob[0]+1); NeedBytes(3); MoveAlong(1+GetSettingValueLength(pBlob)); NeedBytes(1); } } /**** add missing setting to cache **********************/ if ( dbcgs->pValue->type != DBVT_BLOB ) { DBVARIANT* pCachedValue = GetCachedValuePtr( hContact, szCachedSettingName, 1 ); if ( pCachedValue != NULL ) pCachedValue->type = DBVT_DELETED; } LeaveCriticalSection(&csDbAccess); logg(); return 1; }