diff options
author | George Hazan <george.hazan@gmail.com> | 2013-04-09 21:40:22 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2013-04-09 21:40:22 +0000 |
commit | 3dc0d9b0b7c30ea2f77d74c4ce5b6ccd67bd525c (patch) | |
tree | efee912ee654baafeb98efcd117921db6b7489bc /protocols/Gadu-Gadu | |
parent | bcb27264ba737778e5d3edad36088bacf74f0236 (diff) |
- the kernel filters out contacts by proto names much faster than a plugin;
- database cycles simplified
git-svn-id: http://svn.miranda-ng.org/main/trunk@4404 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/Gadu-Gadu')
-rw-r--r-- | protocols/Gadu-Gadu/src/core.cpp | 49 | ||||
-rw-r--r-- | protocols/Gadu-Gadu/src/import.cpp | 139 |
2 files changed, 88 insertions, 100 deletions
diff --git a/protocols/Gadu-Gadu/src/core.cpp b/protocols/Gadu-Gadu/src/core.cpp index 393157275d..e54f313070 100644 --- a/protocols/Gadu-Gadu/src/core.cpp +++ b/protocols/Gadu-Gadu/src/core.cpp @@ -1447,16 +1447,13 @@ void GGPROTO::setalloffline() netlog("setalloffline(): started. Setting buddies offline");
db_set_w(NULL, m_szModuleName, GG_KEY_STATUS, ID_STATUS_OFFLINE);
- for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
- char *szProto = GetContactProto(hContact);
- if (szProto != NULL && !strcmp(szProto, m_szModuleName)) {
- db_set_w(hContact, m_szModuleName, GG_KEY_STATUS, ID_STATUS_OFFLINE);
- // Clear IP and port settings
- db_unset(hContact, m_szModuleName, GG_KEY_CLIENTIP);
- db_unset(hContact, m_szModuleName, GG_KEY_CLIENTPORT);
- // Delete status descr
- db_unset(hContact, "CList", GG_KEY_STATUSDESCR);
- }
+ for (HANDLE hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
+ db_set_w(hContact, m_szModuleName, GG_KEY_STATUS, ID_STATUS_OFFLINE);
+ // Clear IP and port settings
+ db_unset(hContact, m_szModuleName, GG_KEY_CLIENTIP);
+ db_unset(hContact, m_szModuleName, GG_KEY_CLIENTPORT);
+ // Delete status descr
+ db_unset(hContact, "CList", GG_KEY_STATUSDESCR);
}
#ifdef DEBUGMODE
netlog("setalloffline(): End.");
@@ -1517,11 +1514,8 @@ void GGPROTO::notifyall() netlog("notifyall(): Subscribing notification to all users");
// Readup count
- for (hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
- szProto = GetContactProto(hContact);
- if (szProto != NULL && !strcmp(szProto, m_szModuleName))
- count ++;
- }
+ for (hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName))
+ count ++;
// Readup list
/* FIXME: If we have nothing on the list but we omit gg_notify_ex we have problem with receiving any contacts */
@@ -1536,9 +1530,8 @@ void GGPROTO::notifyall() uins = (uin_t*)calloc(sizeof(uin_t), count);
types = (char*)calloc(sizeof(char), count);
- for (hContact = db_find_first(); hContact && cc < count; hContact = db_find_next(hContact)) {
- szProto = GetContactProto(hContact);
- if (szProto != NULL && !strcmp(szProto, m_szModuleName) && (uins[cc] = db_get_dw(hContact, m_szModuleName, GG_KEY_UIN, 0))) {
+ for (hContact = db_find_first(m_szModuleName); hContact && cc < count; hContact = db_find_next(hContact, m_szModuleName)) {
+ if (uins[cc] = db_get_dw(hContact, m_szModuleName, GG_KEY_UIN, 0)) {
if ((db_get_w(hContact, m_szModuleName, GG_KEY_APPARENT, (WORD) ID_STATUS_ONLINE) == ID_STATUS_OFFLINE) ||
db_get_b(hContact, "CList", "NotOnList", 0))
types[cc] = GG_USER_OFFLINE;
@@ -1572,21 +1565,17 @@ HANDLE GGPROTO::getcontact(uin_t uin, int create, int inlist, TCHAR *szNick) netlog("getcontact(): uin=%d create=%d inlist=%d", uin, create, inlist);
#endif
// Look for contact in DB
- for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
- char *szProto = GetContactProto(hContact);
- if (szProto != NULL && !strcmp(szProto, m_szModuleName)) {
- if ((uin_t)db_get_dw(hContact, m_szModuleName, GG_KEY_UIN, 0) == uin
- && db_get_b(hContact, m_szModuleName, "ChatRoom", 0) == 0)
- {
- if (inlist) {
- db_unset(hContact, "CList", "NotOnList");
- db_unset(hContact, "CList", "Hidden");
- }
- return hContact;
+ for (HANDLE hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
+ if ((uin_t)db_get_dw(hContact, m_szModuleName, GG_KEY_UIN, 0) == uin && !db_get_b(hContact, m_szModuleName, "ChatRoom", 0)) {
+ if (inlist) {
+ db_unset(hContact, "CList", "NotOnList");
+ db_unset(hContact, "CList", "Hidden");
}
+ return hContact;
}
}
- if (!create) return NULL;
+ if (!create)
+ return NULL;
HANDLE hContact = (HANDLE) CallService(MS_DB_CONTACT_ADD, 0, 0);
if (!hContact) {
diff --git a/protocols/Gadu-Gadu/src/import.cpp b/protocols/Gadu-Gadu/src/import.cpp index 0492ecb32b..1e899588db 100644 --- a/protocols/Gadu-Gadu/src/import.cpp +++ b/protocols/Gadu-Gadu/src/import.cpp @@ -101,85 +101,84 @@ char *gg_makecontacts(GGPROTO *gg, int cr) char *contacts;
// Readup contacts
- for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
- char *szProto = GetContactProto(hContact);
- if (szProto != NULL && !strcmp(szProto, gg->m_szModuleName) && !db_get_b(hContact, gg->m_szModuleName, "ChatRoom", 0)) {
- DBVARIANT dbv;
+ for (HANDLE hContact = db_find_first(gg->m_szModuleName); hContact; hContact = db_find_next(hContact, gg->m_szModuleName)) {
+ if (db_get_b(hContact, gg->m_szModuleName, "ChatRoom", 0))
+ continue;
- // Readup FirstName
- if (!db_get_s(hContact, gg->m_szModuleName, GG_KEY_PD_FIRSTNAME, &dbv, DBVT_WCHAR))
- {
- char* pszValA = mir_t2a(dbv.ptszVal);
- string_append(s, dbv.pszVal);
- mir_free(pszValA);
- db_free(&dbv);
- }
- string_append_c(s, ';');
- // Readup LastName
- if (!db_get_s(hContact, gg->m_szModuleName, GG_KEY_PD_LASTNAME, &dbv, DBVT_WCHAR))
+ // Readup FirstName
+ DBVARIANT dbv;
+ if (!db_get_s(hContact, gg->m_szModuleName, GG_KEY_PD_FIRSTNAME, &dbv, DBVT_WCHAR))
+ {
+ char* pszValA = mir_t2a(dbv.ptszVal);
+ string_append(s, dbv.pszVal);
+ mir_free(pszValA);
+ db_free(&dbv);
+ }
+ string_append_c(s, ';');
+ // Readup LastName
+ if (!db_get_s(hContact, gg->m_szModuleName, GG_KEY_PD_LASTNAME, &dbv, DBVT_WCHAR))
+ {
+ char* pszValA = mir_t2a(dbv.ptszVal);
+ string_append(s, dbv.pszVal);
+ mir_free(pszValA);
+ db_free(&dbv);
+ }
+ string_append_c(s, ';');
+
+ // Readup Nick
+ if (!db_get_s(hContact, "CList", "MyHandle", &dbv, DBVT_TCHAR) || !db_get_s(hContact, gg->m_szModuleName, GG_KEY_NICK, &dbv, DBVT_TCHAR))
+ {
+ char* dbvA = mir_t2a(dbv.ptszVal);
+ DBVARIANT dbv2;
+ if (!db_get_s(hContact, gg->m_szModuleName, GG_KEY_PD_NICKNAME, &dbv2, DBVT_WCHAR))
{
- char* pszValA = mir_t2a(dbv.ptszVal);
- string_append(s, dbv.pszVal);
+ char* pszValA = mir_t2a(dbv2.ptszVal);
+ string_append(s, pszValA);
mir_free(pszValA);
- db_free(&dbv);
+ db_free(&dbv2);
}
- string_append_c(s, ';');
+ else string_append(s, dbvA);
- // Readup Nick
- if (!db_get_s(hContact, "CList", "MyHandle", &dbv, DBVT_TCHAR) || !db_get_s(hContact, gg->m_szModuleName, GG_KEY_NICK, &dbv, DBVT_TCHAR))
- {
- char* dbvA = mir_t2a(dbv.ptszVal);
- DBVARIANT dbv2;
- if (!db_get_s(hContact, gg->m_szModuleName, GG_KEY_PD_NICKNAME, &dbv2, DBVT_WCHAR))
- {
- char* pszValA = mir_t2a(dbv2.ptszVal);
- string_append(s, pszValA);
- mir_free(pszValA);
- db_free(&dbv2);
- }
- else string_append(s, dbvA);
-
- string_append_c(s, ';');
- string_append(s, dbvA);
- mir_free(dbvA);
- db_free(&dbv);
- }
- else
- string_append_c(s, ';');
string_append_c(s, ';');
+ string_append(s, dbvA);
+ mir_free(dbvA);
+ db_free(&dbv);
+ }
+ else
+ string_append_c(s, ';');
+ string_append_c(s, ';');
- // Readup Phone (fixed: uses stored editable phones)
- if (!db_get_s(hContact, "UserInfo", "MyPhone0", &dbv, DBVT_ASCIIZ))
- {
- // Remove SMS postfix
- char *sms = strstr(dbv.pszVal, " SMS");
- if (sms) *sms = 0;
+ // Readup Phone (fixed: uses stored editable phones)
+ if (!db_get_s(hContact, "UserInfo", "MyPhone0", &dbv, DBVT_ASCIIZ))
+ {
+ // Remove SMS postfix
+ char *sms = strstr(dbv.pszVal, " SMS");
+ if (sms) *sms = 0;
- string_append(s, dbv.pszVal);
- db_free(&dbv);
- }
- string_append_c(s, ';');
- // Readup Group
- if (!db_get_s(hContact, "CList", "Group", &dbv, DBVT_ASCIIZ))
- {
- string_append(s, dbv.pszVal);
- db_free(&dbv);
- }
- string_append_c(s, ';');
- // Readup Uin
- string_append(s, ditoa(db_get_dw(hContact, gg->m_szModuleName, GG_KEY_UIN, 0)));
- string_append_c(s, ';');
- // Readup Mail (fixed: uses stored editable mails)
- if (!db_get_s(hContact, "UserInfo", "Mye-mail0", &dbv, DBVT_ASCIIZ))
- {
- string_append(s, dbv.pszVal);
- db_free(&dbv);
- }
- if (cr)
- string_append(s, ";0;;0;\r\n");
- else
- string_append(s, ";0;;0;\n");
+ string_append(s, dbv.pszVal);
+ db_free(&dbv);
+ }
+ string_append_c(s, ';');
+ // Readup Group
+ if (!db_get_s(hContact, "CList", "Group", &dbv, DBVT_ASCIIZ))
+ {
+ string_append(s, dbv.pszVal);
+ db_free(&dbv);
+ }
+ string_append_c(s, ';');
+ // Readup Uin
+ string_append(s, ditoa(db_get_dw(hContact, gg->m_szModuleName, GG_KEY_UIN, 0)));
+ string_append_c(s, ';');
+ // Readup Mail (fixed: uses stored editable mails)
+ if (!db_get_s(hContact, "UserInfo", "Mye-mail0", &dbv, DBVT_ASCIIZ))
+ {
+ string_append(s, dbv.pszVal);
+ db_free(&dbv);
}
+ if (cr)
+ string_append(s, ";0;;0;\r\n");
+ else
+ string_append(s, ";0;;0;\n");
}
contacts = string_free(s, 0);
|