summaryrefslogtreecommitdiff
path: root/plugins/helpers/db_helpers.cpp
blob: cf58b4f3b2c8d89a9b7a720323386b97b1a1d451 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
    Helper functions for Miranda-IM (www.miranda-im.org)
    Copyright 2006 P. Boon

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/
#include "db_helpers.h"

struct RemoveSettings{
	char *szPrefix;
	int count;
	char **szSettings;
};

static int DBRemoveEnumProc(const char *szSetting, LPARAM lParam) {

	struct RemoveSettings *rs;

	rs = (struct RemoveSettings *)lParam;
	if (!strncmp(szSetting, rs->szPrefix, strlen(rs->szPrefix))) {
		rs->szSettings = ( char** )realloc(rs->szSettings, (rs->count+1)*sizeof(char *));
		rs->szSettings[rs->count] = _strdup(szSetting);
		rs->count += 1;
	}
	
	return 0;
}

int Hlp_RemoveDatabaseSettings(HANDLE hContact, char *szModule, char *szPrefix) {

	DBCONTACTENUMSETTINGS dbces;
	struct RemoveSettings rs;
	int i, count;

	ZeroMemory(&rs, sizeof(struct RemoveSettings));
	rs.szPrefix = szPrefix;
	ZeroMemory(&dbces, sizeof(DBCONTACTENUMSETTINGS));
	dbces.pfnEnumProc = DBRemoveEnumProc;
	dbces.lParam = (LPARAM)&rs;
	dbces.szModule = szModule;
	if (CallService(MS_DB_CONTACT_ENUMSETTINGS, (WPARAM)(HANDLE)hContact, (LPARAM)&dbces) == -1) {
		
		return -1;
	}
	count = 0;
	if (rs.szSettings != NULL) {
		for (i=0;i<rs.count;i++) {
			if (rs.szSettings[i] != NULL) {
				if (!DBDeleteContactSetting(hContact, szModule, rs.szSettings[i])) {
					count += 1;
				}
				free(rs.szSettings[i]);
			}
		}
		free(rs.szSettings);
	}

	return count;
}