root / src / addrindex.c @ 2993
History | View | Annotate | Download (52.3 kB)
| 1 | 1 | hiro | /*
|
|---|---|---|---|
| 2 | 1 | hiro | * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client |
| 3 | 1 | hiro | * Copyright (C) 2001 Match Grun |
| 4 | 1 | hiro | * |
| 5 | 1 | hiro | * This program is free software; you can redistribute it and/or modify |
| 6 | 1 | hiro | * it under the terms of the GNU General Public License as published by |
| 7 | 1 | hiro | * the Free Software Foundation; either version 2 of the License, or |
| 8 | 1 | hiro | * (at your option) any later version. |
| 9 | 1 | hiro | * |
| 10 | 1 | hiro | * This program is distributed in the hope that it will be useful, |
| 11 | 1 | hiro | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | 1 | hiro | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | 1 | hiro | * GNU General Public License for more details. |
| 14 | 1 | hiro | * |
| 15 | 1 | hiro | * You should have received a copy of the GNU General Public License |
| 16 | 1 | hiro | * along with this program; if not, write to the Free Software |
| 17 | 1 | hiro | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 18 | 1 | hiro | */ |
| 19 | 1 | hiro | |
| 20 | 1 | hiro | /*
|
| 21 | 1 | hiro | * General functions for accessing address index file. |
| 22 | 1 | hiro | */ |
| 23 | 1 | hiro | |
| 24 | 1 | hiro | #ifdef HAVE_CONFIG_H
|
| 25 | 1 | hiro | # include "config.h" |
| 26 | 1 | hiro | #endif
|
| 27 | 1 | hiro | |
| 28 | 1 | hiro | #include "defs.h" |
| 29 | 1 | hiro | |
| 30 | 1 | hiro | #include <glib.h> |
| 31 | 92 | hiro | #include <glib/gi18n.h> |
| 32 | 1 | hiro | #include <stdlib.h> |
| 33 | 1 | hiro | |
| 34 | 1 | hiro | #include "mgutils.h" |
| 35 | 1 | hiro | #include "addritem.h" |
| 36 | 1 | hiro | #include "addrcache.h" |
| 37 | 1 | hiro | #include "addrbook.h" |
| 38 | 1 | hiro | #include "addrindex.h" |
| 39 | 1 | hiro | #include "xml.h" |
| 40 | 478 | hiro | #include "utils.h" |
| 41 | 1 | hiro | |
| 42 | 1 | hiro | #ifndef DEV_STANDALONE
|
| 43 | 1 | hiro | #include "prefs.h" |
| 44 | 1 | hiro | #include "codeconv.h" |
| 45 | 1 | hiro | #endif
|
| 46 | 1 | hiro | |
| 47 | 1 | hiro | #include "vcard.h" |
| 48 | 1 | hiro | |
| 49 | 1 | hiro | #ifdef USE_JPILOT
|
| 50 | 1 | hiro | #include "jpilot.h" |
| 51 | 1 | hiro | #endif
|
| 52 | 1 | hiro | |
| 53 | 1 | hiro | #ifdef USE_LDAP
|
| 54 | 1 | hiro | #include "syldap.h" |
| 55 | 1 | hiro | #endif
|
| 56 | 1 | hiro | |
| 57 | 1 | hiro | #define TAG_ADDRESS_INDEX "addressbook" |
| 58 | 1 | hiro | |
| 59 | 1 | hiro | #define TAG_IF_ADDRESS_BOOK "book_list" |
| 60 | 1 | hiro | #define TAG_IF_VCARD "vcard_list" |
| 61 | 1 | hiro | #define TAG_IF_JPILOT "jpilot_list" |
| 62 | 1 | hiro | #define TAG_IF_LDAP "ldap_list" |
| 63 | 1 | hiro | |
| 64 | 1 | hiro | #define TAG_DS_ADDRESS_BOOK "book" |
| 65 | 1 | hiro | #define TAG_DS_VCARD "vcard" |
| 66 | 1 | hiro | #define TAG_DS_JPILOT "jpilot" |
| 67 | 1 | hiro | #define TAG_DS_LDAP "server" |
| 68 | 1 | hiro | |
| 69 | 1 | hiro | /* XML Attribute names */
|
| 70 | 1 | hiro | #define ATTAG_BOOK_NAME "name" |
| 71 | 1 | hiro | #define ATTAG_BOOK_FILE "file" |
| 72 | 1 | hiro | |
| 73 | 1 | hiro | #define ATTAG_VCARD_NAME "name" |
| 74 | 1 | hiro | #define ATTAG_VCARD_FILE "file" |
| 75 | 1 | hiro | |
| 76 | 1 | hiro | #define ATTAG_JPILOT_NAME "name" |
| 77 | 1 | hiro | #define ATTAG_JPILOT_FILE "file" |
| 78 | 1 | hiro | #define ATTAG_JPILOT_CUSTOM_1 "custom-1" |
| 79 | 1 | hiro | #define ATTAG_JPILOT_CUSTOM_2 "custom-2" |
| 80 | 1 | hiro | #define ATTAG_JPILOT_CUSTOM_3 "custom-3" |
| 81 | 1 | hiro | #define ATTAG_JPILOT_CUSTOM_4 "custom-4" |
| 82 | 1 | hiro | #define ATTAG_JPILOT_CUSTOM "custom-" |
| 83 | 1 | hiro | |
| 84 | 1 | hiro | #define ATTAG_LDAP_NAME "name" |
| 85 | 1 | hiro | #define ATTAG_LDAP_HOST "host" |
| 86 | 1 | hiro | #define ATTAG_LDAP_PORT "port" |
| 87 | 1 | hiro | #define ATTAG_LDAP_BASE_DN "base-dn" |
| 88 | 1 | hiro | #define ATTAG_LDAP_BIND_DN "bind-dn" |
| 89 | 1 | hiro | #define ATTAG_LDAP_BIND_PASS "bind-pass" |
| 90 | 1 | hiro | #define ATTAG_LDAP_CRITERIA "criteria" |
| 91 | 1 | hiro | #define ATTAG_LDAP_MAX_ENTRY "max-entry" |
| 92 | 1 | hiro | #define ATTAG_LDAP_TIMEOUT "timeout" |
| 93 | 1 | hiro | |
| 94 | 1 | hiro | #if 0
|
| 95 | 1 | hiro | N_("Common address")
|
| 96 | 1 | hiro | N_("Personal address")
|
| 97 | 1 | hiro | #endif |
| 98 | 1 | hiro | |
| 99 | 1 | hiro | #define DISP_NEW_COMMON _("Common address") |
| 100 | 1 | hiro | #define DISP_NEW_PERSONAL _("Personal address") |
| 101 | 1 | hiro | |
| 102 | 1 | hiro | /* Old address book */
|
| 103 | 1 | hiro | #define TAG_IF_OLD_COMMON "common_address" |
| 104 | 1 | hiro | #define TAG_IF_OLD_PERSONAL "personal_address" |
| 105 | 1 | hiro | |
| 106 | 1 | hiro | #define DISP_OLD_COMMON _("Common address") |
| 107 | 1 | hiro | #define DISP_OLD_PERSONAL _("Personal address") |
| 108 | 1 | hiro | |
| 109 | 1 | hiro | typedef struct _AddressIfAttr AddressIfAttrib; |
| 110 | 1 | hiro | struct _AddressIfAttr {
|
| 111 | 1 | hiro | gchar *name; |
| 112 | 1 | hiro | gchar *value; |
| 113 | 1 | hiro | }; |
| 114 | 1 | hiro | |
| 115 | 1 | hiro | /*
|
| 116 | 1 | hiro | * Build interface with default values. |
| 117 | 1 | hiro | */ |
| 118 | 1 | hiro | static AddressInterface *addrindex_create_interface( gint type, gchar *name, gchar *tagIf, gchar *tagDS ) {
|
| 119 | 1 | hiro | AddressInterface *iface = g_new0( AddressInterface, 1 );
|
| 120 | 1 | hiro | ADDRITEM_TYPE(iface) = ITEMTYPE_INTERFACE; |
| 121 | 1 | hiro | ADDRITEM_ID(iface) = NULL;
|
| 122 | 1 | hiro | ADDRITEM_NAME(iface) = g_strdup( name ); |
| 123 | 1 | hiro | ADDRITEM_PARENT(iface) = NULL;
|
| 124 | 1 | hiro | ADDRITEM_SUBTYPE(iface) = type; |
| 125 | 1 | hiro | iface->type = type; |
| 126 | 1 | hiro | iface->name = g_strdup( name ); |
| 127 | 1 | hiro | iface->listTag = g_strdup( tagIf ); |
| 128 | 1 | hiro | iface->itemTag = g_strdup( tagDS ); |
| 129 | 1 | hiro | iface->legacyFlag = FALSE; |
| 130 | 1 | hiro | iface->haveLibrary = TRUE; |
| 131 | 1 | hiro | iface->useInterface = TRUE; |
| 132 | 1 | hiro | iface->readOnly = TRUE; |
| 133 | 1 | hiro | iface->getAccessFlag = NULL;
|
| 134 | 1 | hiro | iface->getModifyFlag = NULL;
|
| 135 | 1 | hiro | iface->getReadFlag = NULL;
|
| 136 | 1 | hiro | iface->getStatusCode = NULL;
|
| 137 | 1 | hiro | iface->getReadData = NULL;
|
| 138 | 1 | hiro | iface->getRootFolder = NULL;
|
| 139 | 1 | hiro | iface->getListFolder = NULL;
|
| 140 | 1 | hiro | iface->getListPerson = NULL;
|
| 141 | 1 | hiro | iface->getAllPersons = NULL;
|
| 142 | 1 | hiro | iface->getAllGroups = NULL;
|
| 143 | 1 | hiro | iface->getName = NULL;
|
| 144 | 1 | hiro | iface->listSource = NULL;
|
| 145 | 1 | hiro | return iface;
|
| 146 | 1 | hiro | } |
| 147 | 1 | hiro | |
| 148 | 1 | hiro | /*
|
| 149 | 1 | hiro | * Build table of interfaces. |
| 150 | 1 | hiro | */ |
| 151 | 1 | hiro | static void addrindex_build_if_list( AddressIndex *addrIndex ) { |
| 152 | 1 | hiro | AddressInterface *iface; |
| 153 | 1 | hiro | |
| 154 | 1 | hiro | iface = addrindex_create_interface( ADDR_IF_BOOK, "Address Book", TAG_IF_ADDRESS_BOOK, TAG_DS_ADDRESS_BOOK );
|
| 155 | 1 | hiro | iface->readOnly = FALSE; |
| 156 | 1 | hiro | iface->getModifyFlag = ( void * ) addrbook_get_modified;
|
| 157 | 1 | hiro | iface->getAccessFlag = ( void * ) addrbook_get_accessed;
|
| 158 | 1 | hiro | iface->getReadFlag = ( void * ) addrbook_get_read_flag;
|
| 159 | 1 | hiro | iface->getStatusCode = ( void * ) addrbook_get_status;
|
| 160 | 1 | hiro | iface->getReadData = ( void * ) addrbook_read_data;
|
| 161 | 1 | hiro | iface->getRootFolder = ( void * ) addrbook_get_root_folder;
|
| 162 | 1 | hiro | iface->getListFolder = ( void * ) addrbook_get_list_folder;
|
| 163 | 1 | hiro | iface->getListPerson = ( void * ) addrbook_get_list_person;
|
| 164 | 1 | hiro | iface->getAllPersons = ( void * ) addrbook_get_all_persons;
|
| 165 | 1 | hiro | iface->getName = ( void * ) addrbook_get_name;
|
| 166 | 1 | hiro | iface->setAccessFlag = ( void * ) addrbook_set_accessed;
|
| 167 | 1 | hiro | addrIndex->interfaceList = g_list_append( addrIndex->interfaceList, iface ); |
| 168 | 1 | hiro | ADDRITEM_PARENT(iface) = ADDRITEM_OBJECT(addrIndex); |
| 169 | 1 | hiro | |
| 170 | 1 | hiro | iface = addrindex_create_interface( ADDR_IF_VCARD, "vCard", TAG_IF_VCARD, TAG_DS_VCARD );
|
| 171 | 1 | hiro | iface->getModifyFlag = ( void * ) vcard_get_modified;
|
| 172 | 1 | hiro | iface->getAccessFlag = ( void * ) vcard_get_accessed;
|
| 173 | 1 | hiro | iface->getReadFlag = ( void * ) vcard_get_read_flag;
|
| 174 | 1 | hiro | iface->getStatusCode = ( void * ) vcard_get_status;
|
| 175 | 1 | hiro | iface->getReadData = ( void * ) vcard_read_data;
|
| 176 | 1 | hiro | iface->getRootFolder = ( void * ) vcard_get_root_folder;
|
| 177 | 1 | hiro | iface->getListFolder = ( void * ) vcard_get_list_folder;
|
| 178 | 1 | hiro | iface->getListPerson = ( void * ) vcard_get_list_person;
|
| 179 | 1 | hiro | iface->getAllPersons = ( void * ) vcard_get_all_persons;
|
| 180 | 1 | hiro | iface->getName = ( void * ) vcard_get_name;
|
| 181 | 1 | hiro | iface->setAccessFlag = ( void * ) vcard_set_accessed;
|
| 182 | 1 | hiro | addrIndex->interfaceList = g_list_append( addrIndex->interfaceList, iface ); |
| 183 | 1 | hiro | ADDRITEM_PARENT(iface) = ADDRITEM_OBJECT(addrIndex); |
| 184 | 1 | hiro | |
| 185 | 1 | hiro | iface = addrindex_create_interface( ADDR_IF_JPILOT, "JPilot", TAG_IF_JPILOT, TAG_DS_JPILOT );
|
| 186 | 1 | hiro | #ifdef USE_JPILOT
|
| 187 | 1 | hiro | /* iface->haveLibrary = jpilot_test_pilot_lib(); */
|
| 188 | 1 | hiro | iface->haveLibrary = TRUE; |
| 189 | 1 | hiro | iface->useInterface = iface->haveLibrary; |
| 190 | 1 | hiro | iface->getModifyFlag = ( void * ) jpilot_get_modified;
|
| 191 | 1 | hiro | iface->getAccessFlag = ( void * ) jpilot_get_accessed;
|
| 192 | 1 | hiro | iface->getReadFlag = ( void * ) jpilot_get_read_flag;
|
| 193 | 1 | hiro | iface->getStatusCode = ( void * ) jpilot_get_status;
|
| 194 | 1 | hiro | iface->getReadData = ( void * ) jpilot_read_data;
|
| 195 | 1 | hiro | iface->getRootFolder = ( void * ) jpilot_get_root_folder;
|
| 196 | 1 | hiro | iface->getListFolder = ( void * ) jpilot_get_list_folder;
|
| 197 | 1 | hiro | iface->getListPerson = ( void * ) jpilot_get_list_person;
|
| 198 | 1 | hiro | iface->getAllPersons = ( void * ) jpilot_get_all_persons;
|
| 199 | 1 | hiro | iface->getName = ( void * ) jpilot_get_name;
|
| 200 | 1 | hiro | iface->setAccessFlag = ( void * ) jpilot_set_accessed;
|
| 201 | 1 | hiro | #else
|
| 202 | 1 | hiro | iface->useInterface = FALSE; |
| 203 | 1 | hiro | iface->haveLibrary = FALSE; |
| 204 | 1 | hiro | #endif
|
| 205 | 1 | hiro | addrIndex->interfaceList = g_list_append( addrIndex->interfaceList, iface ); |
| 206 | 1 | hiro | ADDRITEM_PARENT(iface) = ADDRITEM_OBJECT(addrIndex); |
| 207 | 1 | hiro | |
| 208 | 1 | hiro | iface = addrindex_create_interface( ADDR_IF_LDAP, "LDAP", TAG_IF_LDAP, TAG_DS_LDAP );
|
| 209 | 1 | hiro | #ifdef USE_LDAP
|
| 210 | 1 | hiro | /* iface->haveLibrary = syldap_test_ldap_lib(); */
|
| 211 | 1 | hiro | iface->haveLibrary = TRUE; |
| 212 | 1 | hiro | iface->useInterface = iface->haveLibrary; |
| 213 | 1 | hiro | iface->getAccessFlag = ( void * ) syldap_get_accessed;
|
| 214 | 1 | hiro | /* iface->getModifyFlag = ( void * ) syldap_get_modified; */
|
| 215 | 1 | hiro | /* iface->getReadFlag = ( void * ) syldap_get_read_flag; */
|
| 216 | 1 | hiro | iface->getStatusCode = ( void * ) syldap_get_status;
|
| 217 | 1 | hiro | iface->getReadData = ( void * ) syldap_read_data;
|
| 218 | 1 | hiro | iface->getRootFolder = ( void * ) syldap_get_root_folder;
|
| 219 | 1 | hiro | iface->getListFolder = ( void * ) syldap_get_list_folder;
|
| 220 | 1 | hiro | iface->getListPerson = ( void * ) syldap_get_list_person;
|
| 221 | 1 | hiro | iface->getName = ( void * ) syldap_get_name;
|
| 222 | 1 | hiro | iface->setAccessFlag = ( void * ) syldap_set_accessed;
|
| 223 | 1 | hiro | #else
|
| 224 | 1 | hiro | iface->useInterface = FALSE; |
| 225 | 1 | hiro | iface->haveLibrary = FALSE; |
| 226 | 1 | hiro | #endif
|
| 227 | 1 | hiro | addrIndex->interfaceList = g_list_append( addrIndex->interfaceList, iface ); |
| 228 | 1 | hiro | ADDRITEM_PARENT(iface) = ADDRITEM_OBJECT(addrIndex); |
| 229 | 1 | hiro | |
| 230 | 1 | hiro | /* Two old legacy data sources */
|
| 231 | 1 | hiro | iface = addrindex_create_interface( ADDR_IF_COMMON, "Old Address - common", TAG_IF_OLD_COMMON, NULL ); |
| 232 | 1 | hiro | iface->legacyFlag = TRUE; |
| 233 | 1 | hiro | addrIndex->interfaceList = g_list_append( addrIndex->interfaceList, iface ); |
| 234 | 1 | hiro | ADDRITEM_PARENT(iface) = ADDRITEM_OBJECT(addrIndex); |
| 235 | 1 | hiro | |
| 236 | 1 | hiro | iface = addrindex_create_interface( ADDR_IF_COMMON, "Old Address - personal", TAG_IF_OLD_PERSONAL, NULL ); |
| 237 | 1 | hiro | iface->legacyFlag = TRUE; |
| 238 | 1 | hiro | addrIndex->interfaceList = g_list_append( addrIndex->interfaceList, iface ); |
| 239 | 1 | hiro | ADDRITEM_PARENT(iface) = ADDRITEM_OBJECT(addrIndex); |
| 240 | 1 | hiro | |
| 241 | 1 | hiro | } |
| 242 | 1 | hiro | |
| 243 | 1 | hiro | /*
|
| 244 | 1 | hiro | * Free name-value pairs. |
| 245 | 1 | hiro | */ |
| 246 | 1 | hiro | static void addrindex_free_attributes( GList *list ) { |
| 247 | 1 | hiro | GList *node = list; |
| 248 | 1 | hiro | while( node ) {
|
| 249 | 1 | hiro | AddressIfAttrib *nv = node->data; |
| 250 | 1 | hiro | g_free( nv->name ); nv->name = NULL;
|
| 251 | 1 | hiro | g_free( nv->value ); nv->value = NULL;
|
| 252 | 1 | hiro | g_free( nv ); |
| 253 | 1 | hiro | node->data = NULL;
|
| 254 | 1 | hiro | node = g_list_next( node ); |
| 255 | 1 | hiro | } |
| 256 | 1 | hiro | g_list_free( list ); |
| 257 | 1 | hiro | } |
| 258 | 1 | hiro | |
| 259 | 1 | hiro | /*
|
| 260 | 1 | hiro | * Free up data source. |
| 261 | 1 | hiro | */ |
| 262 | 1 | hiro | void addrindex_free_datasource( AddressIndex *addrIndex, AddressDataSource *ds ) {
|
| 263 | 1 | hiro | AddressInterface *iface = NULL;
|
| 264 | 1 | hiro | g_return_if_fail( addrIndex != NULL );
|
| 265 | 1 | hiro | g_return_if_fail( ds != NULL );
|
| 266 | 1 | hiro | |
| 267 | 2844 | hiro | if( ds->iface == NULL ) { |
| 268 | 1 | hiro | iface = addrindex_get_interface( addrIndex, ds->type ); |
| 269 | 1 | hiro | } |
| 270 | 1 | hiro | if( iface == NULL ) return; |
| 271 | 1 | hiro | |
| 272 | 1 | hiro | if( iface->useInterface ) {
|
| 273 | 1 | hiro | if( iface->type == ADDR_IF_BOOK ) {
|
| 274 | 1 | hiro | AddressBookFile *abf = ds->rawDataSource; |
| 275 | 1 | hiro | if( abf ) {
|
| 276 | 1 | hiro | addrbook_free_book( abf ); |
| 277 | 1 | hiro | } |
| 278 | 1 | hiro | } |
| 279 | 1 | hiro | else if( iface->type == ADDR_IF_VCARD ) { |
| 280 | 1 | hiro | VCardFile *vcf = ds->rawDataSource; |
| 281 | 1 | hiro | if( vcf ) {
|
| 282 | 1 | hiro | vcard_free( vcf ); |
| 283 | 1 | hiro | } |
| 284 | 1 | hiro | } |
| 285 | 1 | hiro | #ifdef USE_JPILOT
|
| 286 | 1 | hiro | else if( iface->type == ADDR_IF_JPILOT ) { |
| 287 | 1 | hiro | JPilotFile *jpf = ds->rawDataSource; |
| 288 | 1 | hiro | if( jpf ) {
|
| 289 | 1 | hiro | jpilot_free( jpf ); |
| 290 | 1 | hiro | } |
| 291 | 1 | hiro | } |
| 292 | 1 | hiro | #endif
|
| 293 | 1 | hiro | #ifdef USE_LDAP
|
| 294 | 1 | hiro | else if( iface->type == ADDR_IF_LDAP ) { |
| 295 | 1 | hiro | SyldapServer *server = ds->rawDataSource; |
| 296 | 1 | hiro | if( server ) {
|
| 297 | 1 | hiro | syldap_free( server ); |
| 298 | 1 | hiro | } |
| 299 | 1 | hiro | } |
| 300 | 1 | hiro | #endif
|
| 301 | 1 | hiro | } |
| 302 | 1 | hiro | else {
|
| 303 | 1 | hiro | GList *list = ds->rawDataSource; |
| 304 | 1 | hiro | addrindex_free_attributes( list ); |
| 305 | 1 | hiro | } |
| 306 | 1 | hiro | |
| 307 | 1 | hiro | g_free( ADDRITEM_ID(addrIndex) ); |
| 308 | 1 | hiro | g_free( ADDRITEM_NAME(addrIndex) ); |
| 309 | 1 | hiro | |
| 310 | 1 | hiro | ADDRITEM_TYPE(addrIndex) = ITEMTYPE_NONE; |
| 311 | 1 | hiro | ADDRITEM_ID(addrIndex) = NULL;
|
| 312 | 1 | hiro | ADDRITEM_NAME(addrIndex) = NULL;
|
| 313 | 1 | hiro | ADDRITEM_PARENT(addrIndex) = NULL;
|
| 314 | 1 | hiro | ADDRITEM_SUBTYPE(addrIndex) = 0;
|
| 315 | 1 | hiro | ds->type = ADDR_IF_NONE; |
| 316 | 1 | hiro | ds->rawDataSource = NULL;
|
| 317 | 2844 | hiro | ds->iface = NULL;
|
| 318 | 1 | hiro | |
| 319 | 1 | hiro | ds->type = ADDR_IF_NONE; |
| 320 | 1 | hiro | ds->rawDataSource = NULL;
|
| 321 | 2844 | hiro | ds->iface = NULL;
|
| 322 | 1 | hiro | g_free( ds ); |
| 323 | 1 | hiro | } |
| 324 | 1 | hiro | |
| 325 | 1 | hiro | static void addrindex_free_all_datasources( AddressInterface *iface ) { |
| 326 | 1 | hiro | GList *node = iface->listSource; |
| 327 | 1 | hiro | while( node ) {
|
| 328 | 1 | hiro | AddressDataSource *ds = node->data; |
| 329 | 1 | hiro | if( iface->useInterface ) {
|
| 330 | 1 | hiro | if( iface->type == ADDR_IF_BOOK ) {
|
| 331 | 1 | hiro | AddressBookFile *abf = ds->rawDataSource; |
| 332 | 1 | hiro | if( abf ) {
|
| 333 | 1 | hiro | addrbook_free_book( abf ); |
| 334 | 1 | hiro | } |
| 335 | 1 | hiro | } |
| 336 | 1 | hiro | else if( iface->type == ADDR_IF_VCARD ) { |
| 337 | 1 | hiro | VCardFile *vcf = ds->rawDataSource; |
| 338 | 1 | hiro | if( vcf ) {
|
| 339 | 1 | hiro | vcard_free( vcf ); |
| 340 | 1 | hiro | } |
| 341 | 1 | hiro | } |
| 342 | 1 | hiro | #ifdef USE_JPILOT
|
| 343 | 1 | hiro | else if( iface->type == ADDR_IF_JPILOT ) { |
| 344 | 1 | hiro | JPilotFile *jpf = ds->rawDataSource; |
| 345 | 1 | hiro | if( jpf ) {
|
| 346 | 1 | hiro | jpilot_free( jpf ); |
| 347 | 1 | hiro | } |
| 348 | 1 | hiro | } |
| 349 | 1 | hiro | #endif
|
| 350 | 1 | hiro | #ifdef USE_LDAP
|
| 351 | 1 | hiro | else if( iface->type == ADDR_IF_LDAP ) { |
| 352 | 1 | hiro | SyldapServer *server = ds->rawDataSource; |
| 353 | 1 | hiro | if( server ) {
|
| 354 | 1 | hiro | syldap_free( server ); |
| 355 | 1 | hiro | } |
| 356 | 1 | hiro | } |
| 357 | 1 | hiro | #endif
|
| 358 | 1 | hiro | } |
| 359 | 1 | hiro | else {
|
| 360 | 1 | hiro | GList *list = ds->rawDataSource; |
| 361 | 1 | hiro | addrindex_free_attributes( list ); |
| 362 | 1 | hiro | } |
| 363 | 1 | hiro | |
| 364 | 1 | hiro | ds->type = ADDR_IF_NONE; |
| 365 | 1 | hiro | ds->rawDataSource = NULL;
|
| 366 | 2844 | hiro | ds->iface = NULL;
|
| 367 | 1 | hiro | g_free( ds ); |
| 368 | 1 | hiro | node->data = NULL;
|
| 369 | 1 | hiro | node = g_list_next( node ); |
| 370 | 1 | hiro | } |
| 371 | 1 | hiro | } |
| 372 | 1 | hiro | |
| 373 | 1 | hiro | static void addrindex_free_interface( AddressInterface *iface ) { |
| 374 | 1 | hiro | addrindex_free_all_datasources( iface ); |
| 375 | 1 | hiro | |
| 376 | 1 | hiro | g_free( ADDRITEM_ID(iface) ); |
| 377 | 1 | hiro | g_free( ADDRITEM_NAME(iface) ); |
| 378 | 1 | hiro | g_free( iface->name ); |
| 379 | 1 | hiro | g_free( iface->listTag ); |
| 380 | 1 | hiro | g_free( iface->itemTag ); |
| 381 | 1 | hiro | |
| 382 | 1 | hiro | ADDRITEM_TYPE(iface) = ITEMTYPE_NONE; |
| 383 | 1 | hiro | ADDRITEM_ID(iface) = NULL;
|
| 384 | 1 | hiro | ADDRITEM_NAME(iface) = NULL;
|
| 385 | 1 | hiro | ADDRITEM_PARENT(iface) = NULL;
|
| 386 | 1 | hiro | ADDRITEM_SUBTYPE(iface) = 0;
|
| 387 | 1 | hiro | iface->type = ADDR_IF_NONE; |
| 388 | 1 | hiro | iface->name = NULL;
|
| 389 | 1 | hiro | iface->listTag = NULL;
|
| 390 | 1 | hiro | iface->itemTag = NULL;
|
| 391 | 1 | hiro | iface->legacyFlag = FALSE; |
| 392 | 1 | hiro | iface->useInterface = FALSE; |
| 393 | 1 | hiro | iface->haveLibrary = FALSE; |
| 394 | 1 | hiro | |
| 395 | 1 | hiro | g_list_free( iface->listSource ); |
| 396 | 1 | hiro | iface->listSource = NULL;
|
| 397 | 1 | hiro | } |
| 398 | 1 | hiro | |
| 399 | 1 | hiro | /*
|
| 400 | 1 | hiro | * Create new object. |
| 401 | 1 | hiro | */ |
| 402 | 1 | hiro | AddressIndex *addrindex_create_index() {
|
| 403 | 1 | hiro | AddressIndex *addrIndex = g_new0( AddressIndex, 1 );
|
| 404 | 1 | hiro | |
| 405 | 1 | hiro | ADDRITEM_TYPE(addrIndex) = ITEMTYPE_INDEX; |
| 406 | 1 | hiro | ADDRITEM_ID(addrIndex) = NULL;
|
| 407 | 1 | hiro | ADDRITEM_NAME(addrIndex) = g_strdup( "Address Index" );
|
| 408 | 1 | hiro | ADDRITEM_PARENT(addrIndex) = NULL;
|
| 409 | 1 | hiro | ADDRITEM_SUBTYPE(addrIndex) = 0;
|
| 410 | 1 | hiro | addrIndex->filePath = NULL;
|
| 411 | 1 | hiro | addrIndex->fileName = NULL;
|
| 412 | 1 | hiro | addrIndex->retVal = MGU_SUCCESS; |
| 413 | 1 | hiro | addrIndex->needsConversion = FALSE; |
| 414 | 1 | hiro | addrIndex->wasConverted = FALSE; |
| 415 | 1 | hiro | addrIndex->conversionError = FALSE; |
| 416 | 1 | hiro | addrIndex->interfaceList = NULL;
|
| 417 | 1 | hiro | addrIndex->lastType = ADDR_IF_NONE; |
| 418 | 1 | hiro | addrIndex->dirtyFlag = FALSE; |
| 419 | 1 | hiro | addrindex_build_if_list( addrIndex ); |
| 420 | 1 | hiro | return addrIndex;
|
| 421 | 1 | hiro | } |
| 422 | 1 | hiro | |
| 423 | 1 | hiro | /*
|
| 424 | 1 | hiro | * Specify file to be used. |
| 425 | 1 | hiro | */ |
| 426 | 1 | hiro | void addrindex_set_file_path( AddressIndex *addrIndex, const gchar *value ) { |
| 427 | 1 | hiro | g_return_if_fail( addrIndex != NULL );
|
| 428 | 1 | hiro | addrIndex->filePath = mgu_replace_string( addrIndex->filePath, value ); |
| 429 | 1 | hiro | } |
| 430 | 1 | hiro | void addrindex_set_file_name( AddressIndex *addrIndex, const gchar *value ) { |
| 431 | 1 | hiro | g_return_if_fail( addrIndex != NULL );
|
| 432 | 1 | hiro | addrIndex->fileName = mgu_replace_string( addrIndex->fileName, value ); |
| 433 | 1 | hiro | } |
| 434 | 1 | hiro | void addrindex_set_dirty( AddressIndex *addrIndex, const gboolean value ) { |
| 435 | 1 | hiro | g_return_if_fail( addrIndex != NULL );
|
| 436 | 1 | hiro | addrIndex->dirtyFlag = value; |
| 437 | 1 | hiro | } |
| 438 | 1 | hiro | |
| 439 | 1 | hiro | /*
|
| 440 | 1 | hiro | * Return list of interfaces. |
| 441 | 1 | hiro | */ |
| 442 | 1 | hiro | GList *addrindex_get_interface_list( AddressIndex *addrIndex ) {
|
| 443 | 1 | hiro | g_return_val_if_fail( addrIndex != NULL, NULL ); |
| 444 | 1 | hiro | return addrIndex->interfaceList;
|
| 445 | 1 | hiro | } |
| 446 | 1 | hiro | |
| 447 | 1 | hiro | /*
|
| 448 | 1 | hiro | * Free up object. |
| 449 | 1 | hiro | */ |
| 450 | 1 | hiro | void addrindex_free_index( AddressIndex *addrIndex ) {
|
| 451 | 1 | hiro | GList *node; |
| 452 | 1 | hiro | |
| 453 | 1 | hiro | g_return_if_fail( addrIndex != NULL );
|
| 454 | 1 | hiro | |
| 455 | 1 | hiro | g_free( ADDRITEM_ID(addrIndex) ); |
| 456 | 1 | hiro | g_free( ADDRITEM_NAME(addrIndex) ); |
| 457 | 1 | hiro | g_free( addrIndex->filePath ); |
| 458 | 1 | hiro | g_free( addrIndex->fileName ); |
| 459 | 1 | hiro | ADDRITEM_TYPE(addrIndex) = ITEMTYPE_NONE; |
| 460 | 1 | hiro | ADDRITEM_ID(addrIndex) = NULL;
|
| 461 | 1 | hiro | ADDRITEM_NAME(addrIndex) = NULL;
|
| 462 | 1 | hiro | ADDRITEM_PARENT(addrIndex) = NULL;
|
| 463 | 1 | hiro | ADDRITEM_SUBTYPE(addrIndex) = 0;
|
| 464 | 1 | hiro | addrIndex->filePath = NULL;
|
| 465 | 1 | hiro | addrIndex->fileName = NULL;
|
| 466 | 1 | hiro | addrIndex->retVal = MGU_SUCCESS; |
| 467 | 1 | hiro | addrIndex->needsConversion = FALSE; |
| 468 | 1 | hiro | addrIndex->wasConverted = FALSE; |
| 469 | 1 | hiro | addrIndex->conversionError = FALSE; |
| 470 | 1 | hiro | addrIndex->lastType = ADDR_IF_NONE; |
| 471 | 1 | hiro | addrIndex->dirtyFlag = FALSE; |
| 472 | 1 | hiro | node = addrIndex->interfaceList; |
| 473 | 1 | hiro | while( node ) {
|
| 474 | 1 | hiro | AddressInterface *iface = node->data; |
| 475 | 1 | hiro | addrindex_free_interface( iface ); |
| 476 | 1 | hiro | node = g_list_next( node ); |
| 477 | 1 | hiro | } |
| 478 | 1 | hiro | g_list_free( addrIndex->interfaceList ); |
| 479 | 1 | hiro | addrIndex->interfaceList = NULL;
|
| 480 | 1 | hiro | g_free( addrIndex ); |
| 481 | 1 | hiro | } |
| 482 | 1 | hiro | |
| 483 | 1 | hiro | /*
|
| 484 | 1 | hiro | * Print address index. |
| 485 | 1 | hiro | */ |
| 486 | 1 | hiro | void addrindex_print_index( AddressIndex *addrIndex, FILE *stream ) {
|
| 487 | 1 | hiro | g_return_if_fail( addrIndex != NULL );
|
| 488 | 1 | hiro | fprintf( stream, "AddressIndex:\n" );
|
| 489 | 1 | hiro | fprintf( stream, "\tfile path: '%s'\n", addrIndex->filePath );
|
| 490 | 1 | hiro | fprintf( stream, "\tfile name: '%s'\n", addrIndex->fileName );
|
| 491 | 1 | hiro | fprintf( stream, "\t status: %d : '%s'\n", addrIndex->retVal, mgu_error2string( addrIndex->retVal ) );
|
| 492 | 1 | hiro | fprintf( stream, "\tconverted: '%s'\n", addrIndex->wasConverted ? "yes" : "no" ); |
| 493 | 1 | hiro | fprintf( stream, "\tcvt error: '%s'\n", addrIndex->conversionError ? "yes" : "no" ); |
| 494 | 1 | hiro | fprintf( stream, "\t---\n" );
|
| 495 | 1 | hiro | } |
| 496 | 1 | hiro | |
| 497 | 1 | hiro | /*
|
| 498 | 1 | hiro | * Retrieve specified interface from index. |
| 499 | 1 | hiro | */ |
| 500 | 1 | hiro | AddressInterface *addrindex_get_interface( AddressIndex *addrIndex, AddressIfType ifType ) {
|
| 501 | 1 | hiro | AddressInterface *retVal = NULL;
|
| 502 | 1 | hiro | GList *node; |
| 503 | 1 | hiro | |
| 504 | 1 | hiro | g_return_val_if_fail( addrIndex != NULL, NULL ); |
| 505 | 1 | hiro | |
| 506 | 1 | hiro | node = addrIndex->interfaceList; |
| 507 | 1 | hiro | while( node ) {
|
| 508 | 1 | hiro | AddressInterface *iface = node->data; |
| 509 | 1 | hiro | node = g_list_next( node ); |
| 510 | 1 | hiro | if( iface->type == ifType ) {
|
| 511 | 1 | hiro | retVal = iface; |
| 512 | 1 | hiro | break;
|
| 513 | 1 | hiro | } |
| 514 | 1 | hiro | } |
| 515 | 1 | hiro | return retVal;
|
| 516 | 1 | hiro | } |
| 517 | 1 | hiro | |
| 518 | 1 | hiro | AddressDataSource *addrindex_create_datasource() {
|
| 519 | 1 | hiro | AddressDataSource *ds = NULL;
|
| 520 | 1 | hiro | ds = g_new0( AddressDataSource, 1 );
|
| 521 | 1 | hiro | ADDRITEM_TYPE(ds) = ITEMTYPE_DATASOURCE; |
| 522 | 1 | hiro | ADDRITEM_ID(ds) = NULL;
|
| 523 | 1 | hiro | ADDRITEM_NAME(ds) = NULL;
|
| 524 | 1 | hiro | ADDRITEM_PARENT(ds) = NULL;
|
| 525 | 1 | hiro | ADDRITEM_SUBTYPE(ds) = 0;
|
| 526 | 1 | hiro | ds->type = ADDR_IF_NONE; |
| 527 | 1 | hiro | ds->rawDataSource = NULL;
|
| 528 | 2844 | hiro | ds->iface = NULL;
|
| 529 | 1 | hiro | return ds;
|
| 530 | 1 | hiro | } |
| 531 | 1 | hiro | |
| 532 | 1 | hiro | /*
|
| 533 | 1 | hiro | * Add data source to index. |
| 534 | 1 | hiro | * Enter: addrIndex Address index object. |
| 535 | 1 | hiro | * ifType Interface type to add. |
| 536 | 1 | hiro | * dataSource Actual data source to add. |
| 537 | 1 | hiro | * Return: TRUE if data source was added. |
| 538 | 1 | hiro | * Note: The raw data object (for example, AddressBookFile or VCardFile object) should be |
| 539 | 1 | hiro | * supplied as the dataSource argument. |
| 540 | 1 | hiro | */ |
| 541 | 1 | hiro | AddressDataSource *addrindex_index_add_datasource( AddressIndex *addrIndex, AddressIfType ifType, gpointer dataSource ) {
|
| 542 | 1 | hiro | AddressInterface *iface; |
| 543 | 1 | hiro | AddressDataSource *ds = NULL;
|
| 544 | 1 | hiro | |
| 545 | 1 | hiro | g_return_val_if_fail( addrIndex != NULL, NULL ); |
| 546 | 1 | hiro | g_return_val_if_fail( dataSource != NULL, NULL ); |
| 547 | 1 | hiro | |
| 548 | 1 | hiro | iface = addrindex_get_interface( addrIndex, ifType ); |
| 549 | 1 | hiro | if( iface ) {
|
| 550 | 1 | hiro | ds = addrindex_create_datasource(); |
| 551 | 1 | hiro | ADDRITEM_PARENT(ds) = ADDRITEM_OBJECT(iface); |
| 552 | 1 | hiro | ds->type = ifType; |
| 553 | 1 | hiro | ds->rawDataSource = dataSource; |
| 554 | 2844 | hiro | ds->iface = iface; |
| 555 | 1 | hiro | iface->listSource = g_list_append( iface->listSource, ds ); |
| 556 | 1 | hiro | addrIndex->dirtyFlag = TRUE; |
| 557 | 1 | hiro | } |
| 558 | 1 | hiro | return ds;
|
| 559 | 1 | hiro | } |
| 560 | 1 | hiro | |
| 561 | 1 | hiro | /*
|
| 562 | 1 | hiro | * Remove data source from index. |
| 563 | 1 | hiro | * Enter: addrIndex Address index object. |
| 564 | 1 | hiro | * dataSource Data source to remove. |
| 565 | 1 | hiro | * Return: Data source if removed, or NULL if data source was not found in |
| 566 | 1 | hiro | * index. Note the this object must still be freed. |
| 567 | 1 | hiro | */ |
| 568 | 1 | hiro | AddressDataSource *addrindex_index_remove_datasource( AddressIndex *addrIndex, AddressDataSource *dataSource ) {
|
| 569 | 1 | hiro | AddressDataSource *retVal = FALSE; |
| 570 | 1 | hiro | AddressInterface *iface; |
| 571 | 1 | hiro | |
| 572 | 1 | hiro | g_return_val_if_fail( addrIndex != NULL, NULL ); |
| 573 | 1 | hiro | g_return_val_if_fail( dataSource != NULL, NULL ); |
| 574 | 1 | hiro | |
| 575 | 1 | hiro | iface = addrindex_get_interface( addrIndex, dataSource->type ); |
| 576 | 1 | hiro | if( iface ) {
|
| 577 | 1 | hiro | iface->listSource = g_list_remove( iface->listSource, dataSource ); |
| 578 | 1 | hiro | addrIndex->dirtyFlag = TRUE; |
| 579 | 2844 | hiro | dataSource->iface = NULL;
|
| 580 | 1 | hiro | retVal = dataSource; |
| 581 | 1 | hiro | } |
| 582 | 1 | hiro | return retVal;
|
| 583 | 1 | hiro | } |
| 584 | 1 | hiro | |
| 585 | 1 | hiro | static AddressInterface *addrindex_tag_get_interface( AddressIndex *addrIndex, gchar *tag, AddressIfType ifType ) {
|
| 586 | 1 | hiro | AddressInterface *retVal = NULL;
|
| 587 | 1 | hiro | GList *node = addrIndex->interfaceList; |
| 588 | 1 | hiro | |
| 589 | 1 | hiro | while( node ) {
|
| 590 | 1 | hiro | AddressInterface *iface = node->data; |
| 591 | 1 | hiro | node = g_list_next( node ); |
| 592 | 1 | hiro | if( tag ) {
|
| 593 | 1 | hiro | if( strcmp( iface->listTag, tag ) == 0 ) { |
| 594 | 1 | hiro | retVal = iface; |
| 595 | 1 | hiro | break;
|
| 596 | 1 | hiro | } |
| 597 | 1 | hiro | } |
| 598 | 1 | hiro | else {
|
| 599 | 1 | hiro | if( iface->type == ifType ) {
|
| 600 | 1 | hiro | retVal = iface; |
| 601 | 1 | hiro | break;
|
| 602 | 1 | hiro | } |
| 603 | 1 | hiro | } |
| 604 | 1 | hiro | } |
| 605 | 1 | hiro | return retVal;
|
| 606 | 1 | hiro | } |
| 607 | 1 | hiro | |
| 608 | 1 | hiro | static AddressInterface *addrindex_tag_get_datasource( AddressIndex *addrIndex, AddressIfType ifType, gchar *tag ) {
|
| 609 | 1 | hiro | AddressInterface *retVal = NULL;
|
| 610 | 1 | hiro | GList *node = addrIndex->interfaceList; |
| 611 | 1 | hiro | |
| 612 | 1 | hiro | while( node ) {
|
| 613 | 1 | hiro | AddressInterface *iface = node->data; |
| 614 | 1 | hiro | node = g_list_next( node ); |
| 615 | 1 | hiro | if( iface->type == ifType && iface->itemTag ) {
|
| 616 | 1 | hiro | if( strcmp( iface->itemTag, tag ) == 0 ) { |
| 617 | 1 | hiro | retVal = iface; |
| 618 | 1 | hiro | break;
|
| 619 | 1 | hiro | } |
| 620 | 1 | hiro | } |
| 621 | 1 | hiro | } |
| 622 | 1 | hiro | return retVal;
|
| 623 | 1 | hiro | } |
| 624 | 1 | hiro | |
| 625 | 1 | hiro | /* **********************************************************************
|
| 626 | 1 | hiro | * Interface XML parsing functions. |
| 627 | 1 | hiro | * *********************************************************************** |
| 628 | 1 | hiro | */ |
| 629 | 1 | hiro | #if 0
|
| 630 | 1 | hiro | static void show_attribs( GList *attr ) {
|
| 631 | 1 | hiro | while( attr ) {
|
| 632 | 1 | hiro | gchar *name = ((XMLAttr *)attr->data)->name; |
| 633 | 1 | hiro | gchar *value = ((XMLAttr *)attr->data)->value; |
| 634 | 1 | hiro | printf( "\tattr value : %s :%s:\n", name, value ); |
| 635 | 1 | hiro | attr = g_list_next( attr ); |
| 636 | 1 | hiro | } |
| 637 | 1 | hiro | printf( "\t---\n" ); |
| 638 | 1 | hiro | } |
| 639 | 1 | hiro | #endif |
| 640 | 1 | hiro | |
| 641 | 1 | hiro | static void addrindex_write_elem_s( FILE *fp, gint lvl, gchar *name ) { |
| 642 | 1 | hiro | gint i; |
| 643 | 1 | hiro | for( i = 0; i < lvl; i++ ) fputs( " ", fp ); |
| 644 | 1 | hiro | fputs( "<", fp );
|
| 645 | 1 | hiro | fputs( name, fp ); |
| 646 | 1 | hiro | } |
| 647 | 1 | hiro | |
| 648 | 1 | hiro | static void addrindex_write_elem_e( FILE *fp, gint lvl, gchar *name ) { |
| 649 | 1 | hiro | gint i; |
| 650 | 1 | hiro | for( i = 0; i < lvl; i++ ) fputs( " ", fp ); |
| 651 | 1 | hiro | fputs( "</", fp );
|
| 652 | 1 | hiro | fputs( name, fp ); |
| 653 | 1 | hiro | fputs( ">\n", fp );
|
| 654 | 1 | hiro | } |
| 655 | 1 | hiro | |
| 656 | 1 | hiro | static void addrindex_write_attr( FILE *fp, gchar *name, gchar *value ) { |
| 657 | 1 | hiro | fputs( " ", fp );
|
| 658 | 1 | hiro | fputs( name, fp ); |
| 659 | 1 | hiro | fputs( "=\"", fp );
|
| 660 | 1 | hiro | xml_file_put_escape_str( fp, value ); |
| 661 | 1 | hiro | fputs( "\"", fp );
|
| 662 | 1 | hiro | } |
| 663 | 1 | hiro | |
| 664 | 1 | hiro | /*
|
| 665 | 1 | hiro | * Return list of name-value pairs. |
| 666 | 1 | hiro | */ |
| 667 | 1 | hiro | static GList *addrindex_read_attributes( XMLFile *file ) {
|
| 668 | 1 | hiro | GList *list = NULL;
|
| 669 | 1 | hiro | AddressIfAttrib *nv; |
| 670 | 1 | hiro | GList *attr; |
| 671 | 1 | hiro | gchar *name; |
| 672 | 1 | hiro | gchar *value; |
| 673 | 1 | hiro | |
| 674 | 1 | hiro | attr = xml_get_current_tag_attr( file ); |
| 675 | 1 | hiro | while( attr ) {
|
| 676 | 1 | hiro | name = ((XMLAttr *)attr->data)->name; |
| 677 | 1 | hiro | value = ((XMLAttr *)attr->data)->value; |
| 678 | 1 | hiro | nv = g_new0( AddressIfAttrib, 1 );
|
| 679 | 1 | hiro | nv->name = g_strdup( name ); |
| 680 | 1 | hiro | nv->value = g_strdup( value ); |
| 681 | 1 | hiro | list = g_list_append( list, nv ); |
| 682 | 1 | hiro | attr = g_list_next( attr ); |
| 683 | 1 | hiro | } |
| 684 | 1 | hiro | return list;
|
| 685 | 1 | hiro | } |
| 686 | 1 | hiro | |
| 687 | 1 | hiro | /*
|
| 688 | 1 | hiro | * Output name-value pairs. |
| 689 | 1 | hiro | */ |
| 690 | 1 | hiro | static void addrindex_write_attributes( FILE *fp, gchar *tag, GList *list, gint lvl ) { |
| 691 | 1 | hiro | GList *node; |
| 692 | 1 | hiro | AddressIfAttrib *nv; |
| 693 | 1 | hiro | if( list ) {
|
| 694 | 1 | hiro | addrindex_write_elem_s( fp, lvl, tag ); |
| 695 | 1 | hiro | node = list; |
| 696 | 1 | hiro | while( node ) {
|
| 697 | 1 | hiro | nv = node->data; |
| 698 | 1 | hiro | addrindex_write_attr( fp, nv->name, nv->value ); |
| 699 | 1 | hiro | node = g_list_next( node ); |
| 700 | 1 | hiro | } |
| 701 | 1 | hiro | fputs(" />\n", fp);
|
| 702 | 1 | hiro | } |
| 703 | 1 | hiro | } |
| 704 | 1 | hiro | |
| 705 | 1 | hiro | #if 0
|
| 706 | 1 | hiro | static void addrindex_print_attributes( GList *list, FILE *stream ) {
|
| 707 | 1 | hiro | GList *node = list; |
| 708 | 1 | hiro | while( node ) {
|
| 709 | 1 | hiro | AddressIfAttrib *nv = node->data; |
| 710 | 1 | hiro | fprintf( stream, "%s : %s\n", nv->name, nv->value ); |
| 711 | 1 | hiro | node = g_list_next( node ); |
| 712 | 1 | hiro | } |
| 713 | 1 | hiro | } |
| 714 | 1 | hiro | #endif |
| 715 | 1 | hiro | |
| 716 | 1 | hiro | static AddressDataSource *addrindex_parse_book( XMLFile *file ) {
|
| 717 | 1 | hiro | AddressDataSource *ds = g_new0( AddressDataSource, 1 );
|
| 718 | 1 | hiro | AddressBookFile *abf; |
| 719 | 1 | hiro | GList *attr; |
| 720 | 1 | hiro | |
| 721 | 1 | hiro | abf = addrbook_create_book(); |
| 722 | 1 | hiro | attr = xml_get_current_tag_attr( file ); |
| 723 | 1 | hiro | while( attr ) {
|
| 724 | 1 | hiro | gchar *name = ((XMLAttr *)attr->data)->name; |
| 725 | 1 | hiro | gchar *value = ((XMLAttr *)attr->data)->value; |
| 726 | 1 | hiro | if( strcmp( name, ATTAG_BOOK_NAME ) == 0 ) { |
| 727 | 1 | hiro | addrbook_set_name( abf, value ); |
| 728 | 1 | hiro | } |
| 729 | 1 | hiro | else if( strcmp( name, ATTAG_BOOK_FILE ) == 0) { |
| 730 | 1 | hiro | addrbook_set_file( abf, value ); |
| 731 | 1 | hiro | } |
| 732 | 1 | hiro | attr = g_list_next( attr ); |
| 733 | 1 | hiro | } |
| 734 | 1 | hiro | ds->rawDataSource = abf; |
| 735 | 1 | hiro | return ds;
|
| 736 | 1 | hiro | } |
| 737 | 1 | hiro | |
| 738 | 1 | hiro | static void addrindex_write_book( FILE *fp, AddressDataSource *ds, gint lvl ) { |
| 739 | 1 | hiro | AddressBookFile *abf = ds->rawDataSource; |
| 740 | 1 | hiro | if( abf ) {
|
| 741 | 1 | hiro | addrindex_write_elem_s( fp, lvl, TAG_DS_ADDRESS_BOOK ); |
| 742 | 1 | hiro | addrindex_write_attr( fp, ATTAG_BOOK_NAME, abf->name ); |
| 743 | 1 | hiro | addrindex_write_attr( fp, ATTAG_BOOK_FILE, abf->fileName ); |
| 744 | 1 | hiro | fputs( " />\n", fp );
|
| 745 | 1 | hiro | } |
| 746 | 1 | hiro | } |
| 747 | 1 | hiro | |
| 748 | 1 | hiro | static AddressDataSource *addrindex_parse_vcard( XMLFile *file ) {
|
| 749 | 1 | hiro | AddressDataSource *ds = g_new0( AddressDataSource, 1 );
|
| 750 | 1 | hiro | VCardFile *vcf; |
| 751 | 1 | hiro | GList *attr; |
| 752 | 1 | hiro | |
| 753 | 1 | hiro | vcf = vcard_create(); |
| 754 | 1 | hiro | attr = xml_get_current_tag_attr( file ); |
| 755 | 1 | hiro | while( attr ) {
|
| 756 | 1 | hiro | gchar *name = ((XMLAttr *)attr->data)->name; |
| 757 | 1 | hiro | gchar *value = ((XMLAttr *)attr->data)->value; |
| 758 | 1 | hiro | if( strcmp( name, ATTAG_VCARD_NAME ) == 0 ) { |
| 759 | 1 | hiro | vcard_set_name( vcf, value ); |
| 760 | 1 | hiro | } |
| 761 | 1 | hiro | else if( strcmp( name, ATTAG_VCARD_FILE ) == 0) { |
| 762 | 1 | hiro | vcard_set_file( vcf, value ); |
| 763 | 1 | hiro | } |
| 764 | 1 | hiro | attr = g_list_next( attr ); |
| 765 | 1 | hiro | } |
| 766 | 1 | hiro | ds->rawDataSource = vcf; |
| 767 | 1 | hiro | return ds;
|
| 768 | 1 | hiro | } |
| 769 | 1 | hiro | |
| 770 | 1 | hiro | static void addrindex_write_vcard( FILE *fp, AddressDataSource *ds, gint lvl ) { |
| 771 | 1 | hiro | VCardFile *vcf = ds->rawDataSource; |
| 772 | 1 | hiro | if( vcf ) {
|
| 773 | 1 | hiro | addrindex_write_elem_s( fp, lvl, TAG_DS_VCARD ); |
| 774 | 1 | hiro | addrindex_write_attr( fp, ATTAG_VCARD_NAME, vcf->name ); |
| 775 | 1 | hiro | addrindex_write_attr( fp, ATTAG_VCARD_FILE, vcf->path ); |
| 776 | 1 | hiro | fputs( " />\n", fp );
|
| 777 | 1 | hiro | } |
| 778 | 1 | hiro | } |
| 779 | 1 | hiro | |
| 780 | 1 | hiro | #ifdef USE_JPILOT
|
| 781 | 1 | hiro | static AddressDataSource *addrindex_parse_jpilot( XMLFile *file ) {
|
| 782 | 1 | hiro | AddressDataSource *ds = g_new0( AddressDataSource, 1 );
|
| 783 | 1 | hiro | JPilotFile *jpf; |
| 784 | 1 | hiro | GList *attr; |
| 785 | 1 | hiro | |
| 786 | 1 | hiro | jpf = jpilot_create(); |
| 787 | 1 | hiro | attr = xml_get_current_tag_attr( file ); |
| 788 | 1 | hiro | while( attr ) {
|
| 789 | 1 | hiro | gchar *name = ((XMLAttr *)attr->data)->name; |
| 790 | 1 | hiro | gchar *value = ((XMLAttr *)attr->data)->value; |
| 791 | 1 | hiro | if( strcmp( name, ATTAG_JPILOT_NAME ) == 0 ) { |
| 792 | 1 | hiro | jpilot_set_name( jpf, value ); |
| 793 | 1 | hiro | } |
| 794 | 1 | hiro | else if( strcmp( name, ATTAG_JPILOT_FILE ) == 0 ) { |
| 795 | 1 | hiro | jpilot_set_file( jpf, value ); |
| 796 | 1 | hiro | } |
| 797 | 1 | hiro | else if( strcmp( name, ATTAG_JPILOT_CUSTOM_1 ) == 0 ) { |
| 798 | 1 | hiro | jpilot_add_custom_label( jpf, value ); |
| 799 | 1 | hiro | } |
| 800 | 1 | hiro | else if( strcmp( name, ATTAG_JPILOT_CUSTOM_2 ) == 0 ) { |
| 801 | 1 | hiro | jpilot_add_custom_label( jpf, value ); |
| 802 | 1 | hiro | } |
| 803 | 1 | hiro | else if( strcmp( name, ATTAG_JPILOT_CUSTOM_3 ) == 0 ) { |
| 804 | 1 | hiro | jpilot_add_custom_label( jpf, value ); |
| 805 | 1 | hiro | } |
| 806 | 1 | hiro | else if( strcmp( name, ATTAG_JPILOT_CUSTOM_4 ) == 0 ) { |
| 807 | 1 | hiro | jpilot_add_custom_label( jpf, value ); |
| 808 | 1 | hiro | } |
| 809 | 1 | hiro | attr = g_list_next( attr ); |
| 810 | 1 | hiro | } |
| 811 | 1 | hiro | ds->rawDataSource = jpf; |
| 812 | 1 | hiro | return ds;
|
| 813 | 1 | hiro | } |
| 814 | 1 | hiro | |
| 815 | 1 | hiro | static void addrindex_write_jpilot( FILE *fp,AddressDataSource *ds, gint lvl ) { |
| 816 | 1 | hiro | JPilotFile *jpf = ds->rawDataSource; |
| 817 | 1 | hiro | if( jpf ) {
|
| 818 | 1 | hiro | gint ind; |
| 819 | 1 | hiro | GList *node; |
| 820 | 1 | hiro | GList *customLbl = jpilot_get_custom_labels( jpf ); |
| 821 | 1 | hiro | addrindex_write_elem_s( fp, lvl, TAG_DS_JPILOT ); |
| 822 | 1 | hiro | addrindex_write_attr( fp, ATTAG_JPILOT_NAME, jpf->name ); |
| 823 | 1 | hiro | addrindex_write_attr( fp, ATTAG_JPILOT_FILE, jpf->path ); |
| 824 | 1 | hiro | node = customLbl; |
| 825 | 1 | hiro | ind = 1;
|
| 826 | 1 | hiro | while( node ) {
|
| 827 | 1 | hiro | gchar name[256];
|
| 828 | 1 | hiro | sprintf( name, "%s%d", ATTAG_JPILOT_CUSTOM, ind );
|
| 829 | 1 | hiro | addrindex_write_attr( fp, name, node->data ); |
| 830 | 1 | hiro | ind++; |
| 831 | 1 | hiro | node = g_list_next( node ); |
| 832 | 1 | hiro | } |
| 833 | 1 | hiro | fputs( " />\n", fp );
|
| 834 | 1 | hiro | } |
| 835 | 1 | hiro | } |
| 836 | 1 | hiro | #else
|
| 837 | 1 | hiro | /* Just read/write name-value pairs */
|
| 838 | 1 | hiro | static AddressDataSource *addrindex_parse_jpilot( XMLFile *file ) {
|
| 839 | 1 | hiro | AddressDataSource *ds = g_new0( AddressDataSource, 1 );
|
| 840 | 1 | hiro | GList *list = addrindex_read_attributes( file ); |
| 841 | 1 | hiro | ds->rawDataSource = list; |
| 842 | 1 | hiro | return ds;
|
| 843 | 1 | hiro | } |
| 844 | 1 | hiro | |
| 845 | 1 | hiro | static void addrindex_write_jpilot( FILE *fp, AddressDataSource *ds, gint lvl ) { |
| 846 | 1 | hiro | GList *list = ds->rawDataSource; |
| 847 | 1 | hiro | if( list ) {
|
| 848 | 1 | hiro | addrindex_write_attributes( fp, TAG_DS_JPILOT, list, lvl ); |
| 849 | 1 | hiro | } |
| 850 | 1 | hiro | } |
| 851 | 1 | hiro | #endif
|
| 852 | 1 | hiro | |
| 853 | 1 | hiro | #ifdef USE_LDAP
|
| 854 | 1 | hiro | static AddressDataSource *addrindex_parse_ldap( XMLFile *file ) {
|
| 855 | 1 | hiro | AddressDataSource *ds = g_new0( AddressDataSource, 1 );
|
| 856 | 1 | hiro | SyldapServer *server; |
| 857 | 1 | hiro | GList *attr; |
| 858 | 1 | hiro | |
| 859 | 1 | hiro | server = syldap_create(); |
| 860 | 1 | hiro | attr = xml_get_current_tag_attr( file ); |
| 861 | 1 | hiro | while( attr ) {
|
| 862 | 1 | hiro | gchar *name = ((XMLAttr *)attr->data)->name; |
| 863 | 1 | hiro | gchar *value = ((XMLAttr *)attr->data)->value; |
| 864 | 1 | hiro | gint ivalue = atoi( value ); |
| 865 | 1 | hiro | if( strcmp( name, ATTAG_LDAP_NAME ) == 0 ) { |
| 866 | 1 | hiro | syldap_set_name( server, value ); |
| 867 | 1 | hiro | } |
| 868 | 1 | hiro | else if( strcmp( name, ATTAG_LDAP_HOST ) == 0 ) { |
| 869 | 1 | hiro | syldap_set_host( server, value ); |
| 870 | 1 | hiro | } |
| 871 | 1 | hiro | else if( strcmp( name, ATTAG_LDAP_PORT ) == 0 ) { |
| 872 | 1 | hiro | syldap_set_port( server, ivalue ); |
| 873 | 1 | hiro | } |
| 874 | 1 | hiro | else if( strcmp( name, ATTAG_LDAP_BASE_DN ) == 0 ) { |
| 875 | 1 | hiro | syldap_set_base_dn( server, value ); |
| 876 | 1 | hiro | } |
| 877 | 1 | hiro | else if( strcmp( name, ATTAG_LDAP_BIND_DN ) == 0 ) { |
| 878 | 1 | hiro | syldap_set_bind_dn( server, value ); |
| 879 | 1 | hiro | } |
| 880 | 1 | hiro | else if( strcmp( name, ATTAG_LDAP_BIND_PASS ) == 0 ) { |
| 881 | 1 | hiro | syldap_set_bind_password( server, value ); |
| 882 | 1 | hiro | } |
| 883 | 1 | hiro | else if( strcmp( name, ATTAG_LDAP_CRITERIA ) == 0 ) { |
| 884 | 1 | hiro | syldap_set_search_criteria( server, value ); |
| 885 | 1 | hiro | } |
| 886 | 1 | hiro | else if( strcmp( name, ATTAG_LDAP_MAX_ENTRY ) == 0 ) { |
| 887 | 1 | hiro | syldap_set_max_entries( server, ivalue ); |
| 888 | 1 | hiro | } |
| 889 | 1 | hiro | else if( strcmp( name, ATTAG_LDAP_TIMEOUT ) == 0 ) { |
| 890 | 1 | hiro | syldap_set_timeout( server, ivalue ); |
| 891 | 1 | hiro | } |
| 892 | 1 | hiro | attr = g_list_next( attr ); |
| 893 | 1 | hiro | } |
| 894 | 1 | hiro | |
| 895 | 1 | hiro | ds->rawDataSource = server; |
| 896 | 1 | hiro | return ds;
|
| 897 | 1 | hiro | } |
| 898 | 1 | hiro | |
| 899 | 1 | hiro | static void addrindex_write_ldap( FILE *fp, AddressDataSource *ds, gint lvl ) { |
| 900 | 1 | hiro | SyldapServer *server = ds->rawDataSource; |
| 901 | 1 | hiro | if( server ) {
|
| 902 | 1 | hiro | gchar value[256];
|
| 903 | 1 | hiro | |
| 904 | 1 | hiro | addrindex_write_elem_s( fp, lvl, TAG_DS_LDAP ); |
| 905 | 1 | hiro | addrindex_write_attr( fp, ATTAG_LDAP_NAME, server->name ); |
| 906 | 1 | hiro | addrindex_write_attr( fp, ATTAG_LDAP_HOST, server->hostName ); |
| 907 | 1 | hiro | |
| 908 | 1 | hiro | sprintf( value, "%d", server->port );
|
| 909 | 1 | hiro | addrindex_write_attr( fp, ATTAG_LDAP_PORT, value ); |
| 910 | 1 | hiro | |
| 911 | 1 | hiro | addrindex_write_attr( fp, ATTAG_LDAP_BASE_DN, server->baseDN ); |
| 912 | 1 | hiro | addrindex_write_attr( fp, ATTAG_LDAP_BIND_DN, server->bindDN ); |
| 913 | 1 | hiro | addrindex_write_attr( fp, ATTAG_LDAP_BIND_PASS, server->bindPass ); |
| 914 | 1 | hiro | addrindex_write_attr( fp, ATTAG_LDAP_CRITERIA, server->searchCriteria ); |
| 915 | 1 | hiro | |
| 916 | 1 | hiro | sprintf( value, "%d", server->maxEntries );
|
| 917 | 1 | hiro | addrindex_write_attr( fp, ATTAG_LDAP_MAX_ENTRY, value ); |
| 918 | 1 | hiro | sprintf( value, "%d", server->timeOut );
|
| 919 | 1 | hiro | addrindex_write_attr( fp, ATTAG_LDAP_TIMEOUT, value ); |
| 920 | 1 | hiro | |
| 921 | 1 | hiro | fputs(" />\n", fp);
|
| 922 | 1 | hiro | } |
| 923 | 1 | hiro | } |
| 924 | 1 | hiro | #else
|
| 925 | 1 | hiro | /* Just read/write name-value pairs */
|
| 926 | 1 | hiro | static AddressDataSource *addrindex_parse_ldap( XMLFile *file ) {
|
| 927 | 1 | hiro | AddressDataSource *ds = g_new0( AddressDataSource, 1 );
|
| 928 | 1 | hiro | GList *list = addrindex_read_attributes( file ); |
| 929 | 1 | hiro | ds->rawDataSource = list; |
| 930 | 1 | hiro | return ds;
|
| 931 | 1 | hiro | } |
| 932 | 1 | hiro | |
| 933 | 1 | hiro | static void addrindex_write_ldap( FILE *fp, AddressDataSource *ds, gint lvl ) { |
| 934 | 1 | hiro | GList *list = ds->rawDataSource; |
| 935 | 1 | hiro | if( list ) {
|
| 936 | 1 | hiro | addrindex_write_attributes( fp, TAG_DS_LDAP, list, lvl ); |
| 937 | 1 | hiro | } |
| 938 | 1 | hiro | } |
| 939 | 1 | hiro | #endif
|
| 940 | 1 | hiro | |
| 941 | 1 | hiro | /* **********************************************************************
|
| 942 | 1 | hiro | * Address index I/O functions. |
| 943 | 1 | hiro | * *********************************************************************** |
| 944 | 1 | hiro | */ |
| 945 | 1 | hiro | static void addrindex_read_index( AddressIndex *addrIndex, XMLFile *file ) { |
| 946 | 1 | hiro | guint prev_level; |
| 947 | 1 | hiro | /* gchar *element; */
|
| 948 | 1 | hiro | /* GList *attr; */
|
| 949 | 1 | hiro | XMLTag *xtag; |
| 950 | 1 | hiro | AddressInterface *iface = NULL, *dsIFace = NULL; |
| 951 | 1 | hiro | AddressDataSource *ds; |
| 952 | 1 | hiro | |
| 953 | 1 | hiro | for (;;) {
|
| 954 | 1 | hiro | prev_level = file->level; |
| 955 | 1 | hiro | xml_parse_next_tag( file ); |
| 956 | 1 | hiro | if( file->level < prev_level ) return; |
| 957 | 1 | hiro | |
| 958 | 1 | hiro | xtag = xml_get_current_tag( file ); |
| 959 | 1 | hiro | /* printf( "tag : %s\n", xtag->tag ); */
|
| 960 | 1 | hiro | |
| 961 | 1 | hiro | iface = addrindex_tag_get_interface( addrIndex, xtag->tag, ADDR_IF_NONE ); |
| 962 | 1 | hiro | if( iface ) {
|
| 963 | 1 | hiro | addrIndex->lastType = iface->type; |
| 964 | 1 | hiro | if( iface->legacyFlag ) addrIndex->needsConversion = TRUE;
|
| 965 | 1 | hiro | /* printf( "found : %s\n", iface->name ); */
|
| 966 | 1 | hiro | } |
| 967 | 1 | hiro | else {
|
| 968 | 1 | hiro | dsIFace = addrindex_tag_get_datasource( addrIndex, addrIndex->lastType, xtag->tag ); |
| 969 | 1 | hiro | if( dsIFace ) {
|
| 970 | 1 | hiro | /* Add data source to list */
|
| 971 | 1 | hiro | /* printf( "\tdata source: %s\n", dsIFace->name ); */
|
| 972 | 1 | hiro | ds = NULL;
|
| 973 | 1 | hiro | if( addrIndex->lastType == ADDR_IF_BOOK ) {
|
| 974 | 1 | hiro | ds = addrindex_parse_book( file ); |
| 975 | 1 | hiro | if( ds->rawDataSource ) {
|
| 976 | 1 | hiro | addrbook_set_path( ds->rawDataSource, addrIndex->filePath ); |
| 977 | 1 | hiro | /* addrbook_print_book( ds->rawDataSource, stdout ); */
|
| 978 | 1 | hiro | } |
| 979 | 1 | hiro | } |
| 980 | 1 | hiro | else if( addrIndex->lastType == ADDR_IF_VCARD ) { |
| 981 | 1 | hiro | ds = addrindex_parse_vcard( file ); |
| 982 | 1 | hiro | /* if( ds->rawDataSource ) { */
|
| 983 | 1 | hiro | /* vcard_print_file( ds->rawDataSource, stdout ); */
|
| 984 | 1 | hiro | /* } */
|
| 985 | 1 | hiro | } |
| 986 | 1 | hiro | else if( addrIndex->lastType == ADDR_IF_JPILOT ) { |
| 987 | 1 | hiro | ds = addrindex_parse_jpilot( file ); |
| 988 | 1 | hiro | /*
|
| 989 | 1 | hiro | if( ds->rawDataSource ) {
|
| 990 | 1 | hiro | jpilot_print_file( ds->rawDataSource, stdout ); |
| 991 | 1 | hiro | // addrindex_print_attributes( ds->rawDataSource, stdout ); |
| 992 | 1 | hiro | } |
| 993 | 1 | hiro | */ |
| 994 | 1 | hiro | } |
| 995 | 1 | hiro | else if( addrIndex->lastType == ADDR_IF_LDAP ) { |
| 996 | 1 | hiro | ds = addrindex_parse_ldap( file ); |
| 997 | 1 | hiro | /*
|
| 998 | 1 | hiro | if( ds->rawDataSource ) {
|
| 999 | 1 | hiro | syldap_print_data( ds->rawDataSource, stdout ); |
| 1000 | 1 | hiro | // addrindex_print_attributes( ds->rawDataSource, stdout ); |
| 1001 | 1 | hiro | } |
| 1002 | 1 | hiro | */ |
| 1003 | 1 | hiro | } |
| 1004 | 1 | hiro | if( ds ) {
|
| 1005 | 1 | hiro | ds->type = addrIndex->lastType; |
| 1006 | 2844 | hiro | ds->iface = dsIFace; |
| 1007 | 1 | hiro | dsIFace->listSource = g_list_append( dsIFace->listSource, ds ); |
| 1008 | 1 | hiro | } |
| 1009 | 1 | hiro | /* printf( "=============================\n\n" ); */
|
| 1010 | 1 | hiro | } |
| 1011 | 1 | hiro | } |
| 1012 | 1 | hiro | /*
|
| 1013 | 1 | hiro | element = xml_get_element( file ); |
| 1014 | 1 | hiro | attr = xml_get_current_tag_attr( file ); |
| 1015 | 1 | hiro | if( _interfaceLast_ && ! _interfaceLast_->legacyFlag ) {
|
| 1016 | 1 | hiro | show_attribs( attr ); |
| 1017 | 1 | hiro | printf( "\ttag value : %s :\n", element ); |
| 1018 | 1 | hiro | } |
| 1019 | 1 | hiro | */ |
| 1020 | 1 | hiro | addrindex_read_index( addrIndex, file ); |
| 1021 | 1 | hiro | } |
| 1022 | 1 | hiro | } |
| 1023 | 1 | hiro | |
| 1024 | 1 | hiro | static gint addrindex_read_file( AddressIndex *addrIndex ) {
|
| 1025 | 1 | hiro | XMLFile *file = NULL;
|
| 1026 | 1 | hiro | gchar *fileSpec = NULL;
|
| 1027 | 1 | hiro | |
| 1028 | 1 | hiro | g_return_val_if_fail( addrIndex != NULL, -1 ); |
| 1029 | 1 | hiro | |
| 1030 | 1 | hiro | fileSpec = g_strconcat( addrIndex->filePath, G_DIR_SEPARATOR_S, addrIndex->fileName, NULL );
|
| 1031 | 1 | hiro | addrIndex->retVal = MGU_NO_FILE; |
| 1032 | 1 | hiro | file = xml_open_file( fileSpec ); |
| 1033 | 1 | hiro | g_free( fileSpec ); |
| 1034 | 1 | hiro | |
| 1035 | 1 | hiro | if( file == NULL ) { |
| 1036 | 1 | hiro | /* fprintf( stdout, " file '%s' does not exist.\n", addrIndex->fileName ); */
|
| 1037 | 1 | hiro | return addrIndex->retVal;
|
| 1038 | 1 | hiro | } |
| 1039 | 1 | hiro | |
| 1040 | 1 | hiro | addrIndex->retVal = MGU_BAD_FORMAT; |
| 1041 | 1 | hiro | if( xml_get_dtd( file ) == 0 ) { |
| 1042 | 1 | hiro | if( xml_parse_next_tag( file ) == 0 ) { |
| 1043 | 1 | hiro | if( xml_compare_tag( file, TAG_ADDRESS_INDEX ) ) {
|
| 1044 | 1 | hiro | addrindex_read_index( addrIndex, file ); |
| 1045 | 1 | hiro | addrIndex->retVal = MGU_SUCCESS; |
| 1046 | 1 | hiro | } |
| 1047 | 1 | hiro | } |
| 1048 | 1 | hiro | } |
| 1049 | 1 | hiro | xml_close_file( file ); |
| 1050 | 1 | hiro | |
| 1051 | 1 | hiro | return addrIndex->retVal;
|
| 1052 | 1 | hiro | } |
| 1053 | 1 | hiro | |
| 1054 | 1 | hiro | static void addrindex_write_index( AddressIndex *addrIndex, FILE *fp ) { |
| 1055 | 1 | hiro | GList *nodeIF, *nodeDS; |
| 1056 | 1 | hiro | gint lvlList = 1;
|
| 1057 | 1 | hiro | gint lvlItem = 1 + lvlList;
|
| 1058 | 1 | hiro | |
| 1059 | 1 | hiro | nodeIF = addrIndex->interfaceList; |
| 1060 | 1 | hiro | while( nodeIF ) {
|
| 1061 | 1 | hiro | AddressInterface *iface = nodeIF->data; |
| 1062 | 1 | hiro | if( ! iface->legacyFlag ) {
|
| 1063 | 1 | hiro | nodeDS = iface->listSource; |
| 1064 | 1 | hiro | addrindex_write_elem_s( fp, lvlList, iface->listTag ); |
| 1065 | 1 | hiro | fputs( ">\n", fp );
|
| 1066 | 1 | hiro | while( nodeDS ) {
|
| 1067 | 1 | hiro | AddressDataSource *ds = nodeDS->data; |
| 1068 | 1 | hiro | if( ds ) {
|
| 1069 | 1 | hiro | if( iface->type == ADDR_IF_BOOK ) {
|
| 1070 | 1 | hiro | addrindex_write_book( fp, ds, lvlItem ); |
| 1071 | 1 | hiro | } |
| 1072 | 1 | hiro | if( iface->type == ADDR_IF_VCARD ) {
|
| 1073 | 1 | hiro | addrindex_write_vcard( fp, ds, lvlItem ); |
| 1074 | 1 | hiro | } |
| 1075 | 1 | hiro | if( iface->type == ADDR_IF_JPILOT ) {
|
| 1076 | 1 | hiro | addrindex_write_jpilot( fp, ds, lvlItem ); |
| 1077 | 1 | hiro | } |
| 1078 | 1 | hiro | if( iface->type == ADDR_IF_LDAP ) {
|
| 1079 | 1 | hiro | addrindex_write_ldap( fp, ds, lvlItem ); |
| 1080 | 1 | hiro | } |
| 1081 | 1 | hiro | } |
| 1082 | 1 | hiro | nodeDS = g_list_next( nodeDS ); |
| 1083 | 1 | hiro | } |
| 1084 | 1 | hiro | addrindex_write_elem_e( fp, lvlList, iface->listTag ); |
| 1085 | 1 | hiro | } |
| 1086 | 1 | hiro | nodeIF = g_list_next( nodeIF ); |
| 1087 | 1 | hiro | } |
| 1088 | 1 | hiro | } |
| 1089 | 1 | hiro | |
| 1090 | 1 | hiro | /*
|
| 1091 | 1 | hiro | * Write data to specified file. |
| 1092 | 1 | hiro | * Enter: addrIndex Address index object. |
| 1093 | 1 | hiro | * newFile New file name. |
| 1094 | 1 | hiro | * return: Status code, from addrIndex->retVal. |
| 1095 | 1 | hiro | * Note: File will be created in directory specified by addrIndex. |
| 1096 | 1 | hiro | */ |
| 1097 | 1 | hiro | gint addrindex_write_to( AddressIndex *addrIndex, const gchar *newFile ) {
|
| 1098 | 1 | hiro | FILE *fp; |
| 1099 | 1 | hiro | gchar *fileSpec; |
| 1100 | 1 | hiro | #ifndef DEV_STANDALONE
|
| 1101 | 1 | hiro | PrefFile *pfile; |
| 1102 | 1 | hiro | #endif
|
| 1103 | 1 | hiro | |
| 1104 | 1 | hiro | g_return_val_if_fail( addrIndex != NULL, -1 ); |
| 1105 | 1 | hiro | |
| 1106 | 1 | hiro | fileSpec = g_strconcat( addrIndex->filePath, G_DIR_SEPARATOR_S, newFile, NULL );
|
| 1107 | 1 | hiro | addrIndex->retVal = MGU_OPEN_FILE; |
| 1108 | 1 | hiro | #ifdef DEV_STANDALONE
|
| 1109 | 478 | hiro | fp = g_fopen( fileSpec, "wb" );
|
| 1110 | 1 | hiro | g_free( fileSpec ); |
| 1111 | 1 | hiro | if( fp ) {
|
| 1112 | 1 | hiro | fputs( "<?xml version=\"1.0\" ?>\n", fp );
|
| 1113 | 1 | hiro | #else
|
| 1114 | 1 | hiro | pfile = prefs_file_open( fileSpec ); |
| 1115 | 1 | hiro | g_free( fileSpec ); |
| 1116 | 1 | hiro | if( pfile ) {
|
| 1117 | 1 | hiro | fp = pfile->fp; |
| 1118 | 41 | hiro | fprintf( fp, "<?xml version=\"1.0\" encoding=\"%s\" ?>\n", CS_INTERNAL );
|
| 1119 | 1 | hiro | #endif
|
| 1120 | 1 | hiro | addrindex_write_elem_s( fp, 0, TAG_ADDRESS_INDEX );
|
| 1121 | 1 | hiro | fputs( ">\n", fp );
|
| 1122 | 1 | hiro | |
| 1123 | 1 | hiro | addrindex_write_index( addrIndex, fp ); |
| 1124 | 1 | hiro | addrindex_write_elem_e( fp, 0, TAG_ADDRESS_INDEX );
|
| 1125 | 1 | hiro | |
| 1126 | 1 | hiro | addrIndex->retVal = MGU_SUCCESS; |
| 1127 | 1 | hiro | #ifdef DEV_STANDALONE
|
| 1128 | 1 | hiro | fclose( fp ); |
| 1129 | 1 | hiro | #else
|
| 1130 | 1 | hiro | if( prefs_file_close( pfile ) < 0 ) { |
| 1131 | 1 | hiro | addrIndex->retVal = MGU_ERROR_WRITE; |
| 1132 | 1 | hiro | } |
| 1133 | 1 | hiro | #endif
|
| 1134 | 1 | hiro | } |
| 1135 | 1 | hiro | |
| 1136 | 1 | hiro | fileSpec = NULL;
|
| 1137 | 1 | hiro | return addrIndex->retVal;
|
| 1138 | 1 | hiro | } |
| 1139 | 1 | hiro | |
| 1140 | 1 | hiro | /*
|
| 1141 | 1 | hiro | * Save address index data to original file. |
| 1142 | 1 | hiro | * return: Status code, from addrIndex->retVal. |
| 1143 | 1 | hiro | */ |
| 1144 | 1 | hiro | gint addrindex_save_data( AddressIndex *addrIndex ) {
|
| 1145 | 1 | hiro | g_return_val_if_fail( addrIndex != NULL, -1 ); |
| 1146 | 1 | hiro | |
| 1147 | 1 | hiro | addrIndex->retVal = MGU_NO_FILE; |
| 1148 | 1 | hiro | if( addrIndex->fileName == NULL || *addrIndex->fileName == '\0' ) return addrIndex->retVal; |
| 1149 | 1 | hiro | if( addrIndex->filePath == NULL || *addrIndex->filePath == '\0' ) return addrIndex->retVal; |
| 1150 | 1 | hiro | |
| 1151 | 1 | hiro | addrindex_write_to( addrIndex, addrIndex->fileName ); |
| 1152 | 1 | hiro | if( addrIndex->retVal == MGU_SUCCESS ) {
|
| 1153 | 1 | hiro | addrIndex->dirtyFlag = FALSE; |
| 1154 | 1 | hiro | } |
| 1155 | 1 | hiro | return addrIndex->retVal;
|
| 1156 | 1 | hiro | } |
| 1157 | 1 | hiro | |
| 1158 | 1 | hiro | /*
|
| 1159 | 1 | hiro | * Save all address book files which may have changed. |
| 1160 | 1 | hiro | * Return: Status code, set if there was a problem saving data. |
| 1161 | 1 | hiro | */ |
| 1162 | 1 | hiro | gint addrindex_save_all_books( AddressIndex *addrIndex ) {
|
| 1163 | 1 | hiro | gint retVal = MGU_SUCCESS; |
| 1164 | 1 | hiro | GList *nodeIf, *nodeDS; |
| 1165 | 1 | hiro | |
| 1166 | 1 | hiro | nodeIf = addrIndex->interfaceList; |
| 1167 | 1 | hiro | while( nodeIf ) {
|
| 1168 | 1 | hiro | AddressInterface *iface = nodeIf->data; |
| 1169 | 1 | hiro | if( iface->type == ADDR_IF_BOOK ) {
|
| 1170 | 1 | hiro | nodeDS = iface->listSource; |
| 1171 | 1 | hiro | while( nodeDS ) {
|
| 1172 | 1 | hiro | AddressDataSource *ds = nodeDS->data; |
| 1173 | 1 | hiro | AddressBookFile *abf = ds->rawDataSource; |
| 1174 | 1 | hiro | if( abf->dirtyFlag ) {
|
| 1175 | 1 | hiro | if( abf->readFlag ) {
|
| 1176 | 1 | hiro | addrbook_save_data( abf ); |
| 1177 | 1 | hiro | if( abf->retVal != MGU_SUCCESS ) {
|
| 1178 | 1 | hiro | retVal = abf->retVal; |
| 1179 | 1 | hiro | } |
| 1180 | 1 | hiro | } |
| 1181 | 1 | hiro | } |
| 1182 | 1 | hiro | nodeDS = g_list_next( nodeDS ); |
| 1183 | 1 | hiro | } |
| 1184 | 1 | hiro | break;
|
| 1185 | 1 | hiro | } |
| 1186 | 1 | hiro | nodeIf = g_list_next( nodeIf ); |
| 1187 | 1 | hiro | } |
| 1188 | 1 | hiro | return retVal;
|
| 1189 | 1 | hiro | } |
| 1190 | 1 | hiro | |
| 1191 | 1 | hiro | |
| 1192 | 1 | hiro | /* **********************************************************************
|
| 1193 | 1 | hiro | * Address book conversion to new format. |
| 1194 | 1 | hiro | * *********************************************************************** |
| 1195 | 1 | hiro | */ |
| 1196 | 1 | hiro | |
| 1197 | 1 | hiro | #define ELTAG_IF_OLD_FOLDER "folder" |
| 1198 | 1 | hiro | #define ELTAG_IF_OLD_GROUP "group" |
| 1199 | 1 | hiro | #define ELTAG_IF_OLD_ITEM "item" |
| 1200 | 1 | hiro | #define ELTAG_IF_OLD_NAME "name" |
| 1201 | 1 | hiro | #define ELTAG_IF_OLD_ADDRESS "address" |
| 1202 | 1 | hiro | #define ELTAG_IF_OLD_REMARKS "remarks" |
| 1203 | 1 | hiro | #define ATTAG_IF_OLD_NAME "name" |
| 1204 | 1 | hiro | |
| 1205 | 1 | hiro | #define TEMPNODE_ROOT 0 |
| 1206 | 1 | hiro | #define TEMPNODE_FOLDER 1 |
| 1207 | 1 | hiro | #define TEMPNODE_GROUP 2 |
| 1208 | 1 | hiro | #define TEMPNODE_ADDRESS 3 |
| 1209 | 1 | hiro | |
| 1210 | 1 | hiro | typedef struct _AddressCvt_Node AddressCvtNode; |
| 1211 | 1 | hiro | struct _AddressCvt_Node {
|
| 1212 | 1 | hiro | gint type; |
| 1213 | 1 | hiro | gchar *name; |
| 1214 | 1 | hiro | gchar *address; |
| 1215 | 1 | hiro | gchar *remarks; |
| 1216 | 1 | hiro | GList *list; |
| 1217 | 1 | hiro | }; |
| 1218 | 1 | hiro | |
| 1219 | 1 | hiro | /*
|
| 1220 | 1 | hiro | * Parse current address item. |
| 1221 | 1 | hiro | */ |
| 1222 | 1 | hiro | static AddressCvtNode *addrindex_parse_item( XMLFile *file ) {
|
| 1223 | 1 | hiro | gchar *element; |
| 1224 | 1 | hiro | guint level; |
| 1225 | 1 | hiro | AddressCvtNode *nn; |
| 1226 | 1 | hiro | |
| 1227 | 1 | hiro | nn = g_new0( AddressCvtNode, 1 );
|
| 1228 | 1 | hiro | nn->type = TEMPNODE_ADDRESS; |
| 1229 | 1 | hiro | nn->list = NULL;
|
| 1230 | 1 | hiro | |
| 1231 | 1 | hiro | level = file->level; |
| 1232 | 1 | hiro | |
| 1233 | 1 | hiro | for (;;) {
|
| 1234 | 1 | hiro | xml_parse_next_tag(file); |
| 1235 | 1 | hiro | if (file->level < level) return nn; |
| 1236 | 1 | hiro | |
| 1237 | 1 | hiro | element = xml_get_element( file ); |
| 1238 | 1 | hiro | if( xml_compare_tag( file, ELTAG_IF_OLD_NAME ) ) {
|
| 1239 | 1 | hiro | nn->name = g_strdup( element ); |
| 1240 | 1 | hiro | } |
| 1241 | 1 | hiro | if( xml_compare_tag( file, ELTAG_IF_OLD_ADDRESS ) ) {
|
| 1242 | 1 | hiro | nn->address = g_strdup( element ); |
| 1243 | 1 | hiro | } |
| 1244 | 1 | hiro | if( xml_compare_tag( file, ELTAG_IF_OLD_REMARKS ) ) {
|
| 1245 | 1 | hiro | nn->remarks = g_strdup( element ); |
| 1246 | 1 | hiro | } |
| 1247 | 1 | hiro | xml_parse_next_tag(file); |
| 1248 | 1 | hiro | } |
| 1249 | 1 | hiro | } |
| 1250 | 1 | hiro | |
| 1251 | 1 | hiro | /*
|
| 1252 | 1 | hiro | * Create a temporary node below specified node. |
| 1253 | 1 | hiro | */ |
| 1254 | 1 | hiro | static AddressCvtNode *addrindex_add_object( AddressCvtNode *node, gint type, gchar *name, gchar *addr, char *rem ) { |
| 1255 | 1 | hiro | AddressCvtNode *nn; |
| 1256 | 1 | hiro | nn = g_new0( AddressCvtNode, 1 );
|
| 1257 | 1 | hiro | nn->type = type; |
| 1258 | 1 | hiro | nn->name = g_strdup( name ); |
| 1259 | 1 | hiro | nn->remarks = g_strdup( rem ); |
| 1260 | 1 | hiro | node->list = g_list_append( node->list, nn ); |
| 1261 | 1 | hiro | return nn;
|
| 1262 | 1 | hiro | } |
| 1263 | 1 | hiro | |
| 1264 | 1 | hiro | /*
|
| 1265 | 1 | hiro | * Process current temporary node. |
| 1266 | 1 | hiro | */ |
| 1267 | 1 | hiro | static void addrindex_add_obj( XMLFile *file, AddressCvtNode *node ) { |
| 1268 | 1 | hiro | GList *attr; |
| 1269 | 1 | hiro | guint prev_level; |
| 1270 | 1 | hiro | AddressCvtNode *newNode = NULL;
|
| 1271 | 1 | hiro | gchar *name; |
| 1272 | 1 | hiro | gchar *value; |
| 1273 | 1 | hiro | |
| 1274 | 1 | hiro | for (;;) {
|
| 1275 | 1 | hiro | prev_level = file->level; |
| 1276 | 1 | hiro | xml_parse_next_tag( file ); |
| 1277 | 1 | hiro | if (file->level < prev_level) return; |
| 1278 | 1 | hiro | name = NULL;
|
| 1279 | 1 | hiro | value = NULL;
|
| 1280 | 1 | hiro | |
| 1281 | 1 | hiro | if( xml_compare_tag( file, ELTAG_IF_OLD_GROUP ) ) {
|
| 1282 | 1 | hiro | attr = xml_get_current_tag_attr(file); |
| 1283 | 1 | hiro | if (attr) {
|
| 1284 | 1 | hiro | name = ((XMLAttr *)attr->data)->name; |
| 1285 | 1 | hiro | if( strcmp( name, ATTAG_IF_OLD_NAME ) == 0 ) { |
| 1286 | 1 | hiro | value = ((XMLAttr *)attr->data)->value; |
| 1287 | 1 | hiro | } |
| 1288 | 1 | hiro | } |
| 1289 | 1 | hiro | newNode = addrindex_add_object( node, TEMPNODE_GROUP, value, "", "" ); |
| 1290 | 1 | hiro | addrindex_add_obj( file, newNode ); |
| 1291 | 1 | hiro | |
| 1292 | 1 | hiro | } |
| 1293 | 1 | hiro | else if( xml_compare_tag( file, ELTAG_IF_OLD_FOLDER ) ) { |
| 1294 | 1 | hiro | attr = xml_get_current_tag_attr(file); |
| 1295 | 1 | hiro | if (attr) {
|
| 1296 | 1 | hiro | name = ((XMLAttr *)attr->data)->name; |
| 1297 | 1 | hiro | if( strcmp( name, ATTAG_IF_OLD_NAME ) == 0 ) { |
| 1298 | 1 | hiro | value = ((XMLAttr *)attr->data)->value; |
| 1299 | 1 | hiro | } |
| 1300 | 1 | hiro | } |
| 1301 | 1 | hiro | newNode = addrindex_add_object( node, TEMPNODE_FOLDER, value, "", "" ); |
| 1302 | 1 | hiro | addrindex_add_obj( file, newNode ); |
| 1303 | 1 | hiro | } |
| 1304 | 1 | hiro | else if( xml_compare_tag( file, ELTAG_IF_OLD_ITEM ) ) { |
| 1305 | 1 | hiro | newNode = addrindex_parse_item( file ); |
| 1306 | 1 | hiro | node->list = g_list_append( node->list, newNode ); |
| 1307 | 1 | hiro | } |
| 1308 | 1 | hiro | else {
|
| 1309 | 1 | hiro | /* printf( "invalid: !!! \n" ); */
|
| 1310 | 1 | hiro | attr = xml_get_current_tag_attr( file ); |
| 1311 | 1 | hiro | } |
| 1312 | 1 | hiro | } |
| 1313 | 1 | hiro | } |
| 1314 | 1 | hiro | |
| 1315 | 1 | hiro | /*
|
| 1316 | 1 | hiro | * Consume all nodes below current tag. |
| 1317 | 1 | hiro | */ |
| 1318 | 1 | hiro | static void addrindex_consume_tree( XMLFile *file ) { |
| 1319 | 1 | hiro | guint prev_level; |
| 1320 | 1 | hiro | gchar *element; |
| 1321 | 1 | hiro | GList *attr; |
| 1322 | 1 | hiro | XMLTag *xtag; |
| 1323 | 1 | hiro | |
| 1324 | 1 | hiro | for (;;) {
|
| 1325 | 1 | hiro | prev_level = file->level; |
| 1326 | 1 | hiro | xml_parse_next_tag( file ); |
| 1327 | 1 | hiro | if (file->level < prev_level) return; |
| 1328 | 1 | hiro | |
| 1329 | 1 | hiro | xtag = xml_get_current_tag( file ); |
| 1330 | 1 | hiro | /* printf( "tag : %s\n", xtag->tag ); */
|
| 1331 | 1 | hiro | element = xml_get_element( file ); |
| 1332 | 1 | hiro | attr = xml_get_current_tag_attr( file ); |
| 1333 | 1 | hiro | /* show_attribs( attr ); */
|
| 1334 | 1 | hiro | /* printf( "\ttag value : %s :\n", element ); */
|
| 1335 | 1 | hiro | addrindex_consume_tree( file ); |
| 1336 | 1 | hiro | } |
| 1337 | 1 | hiro | } |
| 1338 | 1 | hiro | |
| 1339 | 1 | hiro | /*
|
| 1340 | 1 | hiro | * Print temporary tree. |
| 1341 | 1 | hiro | */ |
| 1342 | 1 | hiro | static void addrindex_print_node( AddressCvtNode *node, FILE *stream ) { |
| 1343 | 1 | hiro | GList *list; |
| 1344 | 1 | hiro | |
| 1345 | 1 | hiro | fprintf( stream, "Node:\ttype :%d:\n", node->type );
|
| 1346 | 1 | hiro | fprintf( stream, "\tname :%s:\n", node->name );
|
| 1347 | 1 | hiro | fprintf( stream, "\taddr :%s:\n", node->address );
|
| 1348 | 1 | hiro | fprintf( stream, "\trems :%s:\n", node->remarks );
|
| 1349 | 1 | hiro | if( node->list ) {
|
| 1350 | 1 | hiro | fprintf( stream, "\t--list----\n" );
|
| 1351 | 1 | hiro | } |
| 1352 | 1 | hiro | list = node->list; |
| 1353 | 1 | hiro | while( list ) {
|
| 1354 | 1 | hiro | AddressCvtNode *lNode = list->data; |
| 1355 | 1 | hiro | list = g_list_next( list ); |
| 1356 | 1 | hiro | addrindex_print_node( lNode, stream ); |
| 1357 | 1 | hiro | } |
| 1358 | 1 | hiro | fprintf( stream, "\t==list-%d==\n", node->type );
|
| 1359 | 1 | hiro | } |
| 1360 | 1 | hiro | |
| 1361 | 1 | hiro | /*
|
| 1362 | 1 | hiro | * Free up temporary tree. |
| 1363 | 1 | hiro | */ |
| 1364 | 1 | hiro | static void addrindex_free_node( AddressCvtNode *node ) { |
| 1365 | 1 | hiro | GList *list = node->list; |
| 1366 | 1 | hiro | |
| 1367 | 1 | hiro | while( list ) {
|
| 1368 | 1 | hiro | AddressCvtNode *lNode = list->data; |
| 1369 | 1 | hiro | list = g_list_next( list ); |
| 1370 | 1 | hiro | addrindex_free_node( lNode ); |
| 1371 | 1 | hiro | } |
| 1372 | 1 | hiro | node->type = TEMPNODE_ROOT; |
| 1373 | 1 | hiro | g_free( node->name ); |
| 1374 | 1 | hiro | g_free( node->address ); |
| 1375 | 1 | hiro | g_free( node->remarks ); |
| 1376 | 1 | hiro | g_list_free( node->list ); |
| 1377 | 1 | hiro | g_free( node ); |
| 1378 | 1 | hiro | } |
| 1379 | 1 | hiro | |
| 1380 | 1 | hiro | /*
|
| 1381 | 1 | hiro | * Process address book for specified node. |
| 1382 | 1 | hiro | */ |
| 1383 | 1 | hiro | static void addrindex_process_node( |
| 1384 | 1 | hiro | AddressBookFile *abf, AddressCvtNode *node, ItemFolder *parent, |
| 1385 | 1 | hiro | ItemGroup *parentGrp, ItemFolder *folderGrp ) |
| 1386 | 1 | hiro | {
|
| 1387 | 1 | hiro | GList *list; |
| 1388 | 1 | hiro | ItemFolder *itemFolder = NULL;
|
| 1389 | 1 | hiro | ItemGroup *itemGParent = parentGrp; |
| 1390 | 1 | hiro | ItemFolder *itemGFolder = folderGrp; |
| 1391 | 1 | hiro | AddressCache *cache = abf->addressCache; |
| 1392 | 1 | hiro | |
| 1393 | 1 | hiro | if( node->type == TEMPNODE_ROOT ) {
|
| 1394 | 1 | hiro | itemFolder = parent; |
| 1395 | 1 | hiro | } |
| 1396 | 1 | hiro | else if( node->type == TEMPNODE_FOLDER ) { |
| 1397 | 1 | hiro | itemFolder = addritem_create_item_folder(); |
| 1398 | 1 | hiro | addritem_folder_set_name( itemFolder, node->name ); |
| 1399 | 1 | hiro | addrcache_id_folder( cache, itemFolder ); |
| 1400 | 1 | hiro | addrcache_folder_add_folder( cache, parent, itemFolder ); |
| 1401 | 1 | hiro | itemGFolder = NULL;
|
| 1402 | 1 | hiro | } |
| 1403 | 1 | hiro | else if( node->type == TEMPNODE_GROUP ) { |
| 1404 | 1 | hiro | ItemGroup *itemGroup; |
| 1405 | 1 | hiro | gchar *fName; |
| 1406 | 1 | hiro | |
| 1407 | 1 | hiro | /* Create a folder for group */
|
| 1408 | 1 | hiro | fName = g_strdup_printf( "Cvt - %s", node->name );
|
| 1409 | 1 | hiro | itemGFolder = addritem_create_item_folder(); |
| 1410 | 1 | hiro | addritem_folder_set_name( itemGFolder, fName ); |
| 1411 | 1 | hiro | addrcache_id_folder( cache, itemGFolder ); |
| 1412 | 1 | hiro | addrcache_folder_add_folder( cache, parent, itemGFolder ); |
| 1413 | 1 | hiro | g_free( fName ); |
| 1414 | 1 | hiro | |
| 1415 | 1 | hiro | /* Add group into folder */
|
| 1416 | 1 | hiro | itemGroup = addritem_create_item_group(); |
| 1417 | 1 | hiro | addritem_group_set_name( itemGroup, node->name ); |
| 1418 | 1 | hiro | addrcache_id_group( cache, itemGroup ); |
| 1419 | 1 | hiro | addrcache_folder_add_group( cache, itemGFolder, itemGroup ); |
| 1420 | 1 | hiro | itemGParent = itemGroup; |
| 1421 | 1 | hiro | } |
| 1422 | 1 | hiro | else if( node->type == TEMPNODE_ADDRESS ) { |
| 1423 | 1 | hiro | ItemPerson *itemPerson; |
| 1424 | 1 | hiro | ItemEMail *itemEMail; |
| 1425 | 1 | hiro | |
| 1426 | 1 | hiro | /* Create person and email objects */
|
| 1427 | 1 | hiro | itemPerson = addritem_create_item_person(); |
| 1428 | 1 | hiro | addritem_person_set_common_name( itemPerson, node->name ); |
| 1429 | 1 | hiro | addrcache_id_person( cache, itemPerson ); |
| 1430 | 1 | hiro | itemEMail = addritem_create_item_email(); |
| 1431 | 1 | hiro | addritem_email_set_address( itemEMail, node->address ); |
| 1432 | 1 | hiro | addritem_email_set_remarks( itemEMail, node->remarks ); |
| 1433 | 1 | hiro | addrcache_id_email( cache, itemEMail ); |
| 1434 | 1 | hiro | addrcache_person_add_email( cache, itemPerson, itemEMail ); |
| 1435 | 1 | hiro | |
| 1436 | 1 | hiro | /* Add person into appropriate folder */
|
| 1437 | 1 | hiro | if( itemGFolder ) {
|
| 1438 | 1 | hiro | addrcache_folder_add_person( cache, itemGFolder, itemPerson ); |
| 1439 | 1 | hiro | } |
| 1440 | 1 | hiro | else {
|
| 1441 | 1 | hiro | addrcache_folder_add_person( cache, parent, itemPerson ); |
| 1442 | 1 | hiro | } |
| 1443 | 1 | hiro | |
| 1444 | 1 | hiro | /* Add email address only into group */
|
| 1445 | 1 | hiro | if( parentGrp ) {
|
| 1446 | 1 | hiro | addrcache_group_add_email( cache, parentGrp, itemEMail ); |
| 1447 | 1 | hiro | } |
| 1448 | 1 | hiro | } |
| 1449 | 1 | hiro | |
| 1450 | 1 | hiro | list = node->list; |
| 1451 | 1 | hiro | while( list ) {
|
| 1452 | 1 | hiro | AddressCvtNode *lNode = list->data; |
| 1453 | 1 | hiro | list = g_list_next( list ); |
| 1454 | 1 | hiro | addrindex_process_node( abf, lNode, itemFolder, itemGParent, itemGFolder ); |
| 1455 | 1 | hiro | } |
| 1456 | 1 | hiro | } |
| 1457 | 1 | hiro | |
| 1458 | 1 | hiro | /*
|
| 1459 | 1 | hiro | * Process address book to specified file number. |
| 1460 | 1 | hiro | */ |
| 1461 | 1 | hiro | static gboolean addrindex_process_book( AddressIndex *addrIndex, XMLFile *file, gchar *displayName ) {
|
| 1462 | 1 | hiro | gboolean retVal = FALSE; |
| 1463 | 1 | hiro | AddressBookFile *abf = NULL;
|
| 1464 | 1 | hiro | AddressCvtNode *rootNode = NULL;
|
| 1465 | 1 | hiro | gchar *newFile = NULL;
|
| 1466 | 1 | hiro | GList *fileList = NULL;
|
| 1467 | 1 | hiro | gint fileNum = 0;
|
| 1468 | 1 | hiro | |
| 1469 | 1 | hiro | /* Setup root node */
|
| 1470 | 1 | hiro | rootNode = g_new0( AddressCvtNode, 1 );
|
| 1471 | 1 | hiro | rootNode->type = TEMPNODE_ROOT; |
| 1472 | 1 | hiro | rootNode->name = g_strdup( "root" );
|
| 1473 | 1 | hiro | rootNode->list = NULL;
|
| 1474 | 1 | hiro | addrindex_add_obj( file, rootNode ); |
| 1475 | 1 | hiro | /* addrindex_print_node( rootNode, stdout ); */
|
| 1476 | 1 | hiro | |
| 1477 | 1 | hiro | /* Create new address book */
|
| 1478 | 1 | hiro | abf = addrbook_create_book(); |
| 1479 | 1 | hiro | addrbook_set_name( abf, displayName ); |
| 1480 | 1 | hiro | addrbook_set_path( abf, addrIndex->filePath ); |
| 1481 | 1 | hiro | |
| 1482 | 1 | hiro | /* Determine next available file number */
|
| 1483 | 1 | hiro | fileList = addrbook_get_bookfile_list( abf ); |
| 1484 | 1 | hiro | if( fileList ) {
|
| 1485 | 1 | hiro | fileNum = 1 + abf->maxValue;
|
| 1486 | 1 | hiro | } |
| 1487 | 1 | hiro | g_list_free( fileList ); |
| 1488 | 1 | hiro | fileList = NULL;
|
| 1489 | 1 | hiro | |
| 1490 | 1 | hiro | newFile = addrbook_gen_new_file_name( fileNum ); |
| 1491 | 1 | hiro | if( newFile ) {
|
| 1492 | 1 | hiro | addrbook_set_file( abf, newFile ); |
| 1493 | 1 | hiro | } |
| 1494 | 1 | hiro | |
| 1495 | 1 | hiro | addrindex_process_node( abf, rootNode, abf->addressCache->rootFolder, NULL, NULL ); |
| 1496 | 1 | hiro | |
| 1497 | 1 | hiro | /* addrbook_dump_book( abf, stdout ); */
|
| 1498 | 1 | hiro | addrbook_save_data( abf ); |
| 1499 | 1 | hiro | addrIndex->retVal = abf->retVal; |
| 1500 | 1 | hiro | if( abf->retVal == MGU_SUCCESS ) retVal = TRUE;
|
| 1501 | 1 | hiro | |
| 1502 | 1 | hiro | addrbook_free_book( abf ); |
| 1503 | 1 | hiro | abf = NULL;
|
| 1504 | 1 | hiro | addrindex_free_node( rootNode ); |
| 1505 | 1 | hiro | rootNode = NULL;
|
| 1506 | 1 | hiro | |
| 1507 | 1 | hiro | /* Create entries in address index */
|
| 1508 | 1 | hiro | if( retVal ) {
|
| 1509 | 1 | hiro | abf = addrbook_create_book(); |
| 1510 | 1 | hiro | addrbook_set_name( abf, displayName ); |
| 1511 | 1 | hiro | addrbook_set_path( abf, addrIndex->filePath ); |
| 1512 | 1 | hiro | addrbook_set_file( abf, newFile ); |
| 1513 | 1 | hiro | addrindex_index_add_datasource( addrIndex, ADDR_IF_BOOK, abf ); |
| 1514 | 1 | hiro | } |
| 1515 | 1 | hiro | |
| 1516 | 1 | hiro | return retVal;
|
| 1517 | 1 | hiro | } |
| 1518 | 1 | hiro | |
| 1519 | 1 | hiro | /*
|
| 1520 | 1 | hiro | * Process tree converting data. |
| 1521 | 1 | hiro | */ |
| 1522 | 1 | hiro | static void addrindex_convert_tree( AddressIndex *addrIndex, XMLFile *file ) { |
| 1523 | 1 | hiro | guint prev_level; |
| 1524 | 1 | hiro | gchar *element; |
| 1525 | 1 | hiro | GList *attr; |
| 1526 | 1 | hiro | XMLTag *xtag; |
| 1527 | 1 | hiro | |
| 1528 | 1 | hiro | /* Process file */
|
| 1529 | 1 | hiro | for (;;) {
|
| 1530 | 1 | hiro | prev_level = file->level; |
| 1531 | 1 | hiro | xml_parse_next_tag( file ); |
| 1532 | 1 | hiro | if (file->level < prev_level) return; |
| 1533 | 1 | hiro | |
| 1534 | 1 | hiro | xtag = xml_get_current_tag( file ); |
| 1535 | 1 | hiro | /* printf( "tag : %d : %s\n", prev_level, xtag->tag ); */
|
| 1536 | 1 | hiro | if( strcmp( xtag->tag, TAG_IF_OLD_COMMON ) == 0 ) { |
| 1537 | 1 | hiro | if( addrindex_process_book( addrIndex, file, DISP_OLD_COMMON ) ) {
|
| 1538 | 1 | hiro | addrIndex->needsConversion = FALSE; |
| 1539 | 1 | hiro | addrIndex->wasConverted = TRUE; |
| 1540 | 1 | hiro | continue;
|
| 1541 | 1 | hiro | } |
| 1542 | 1 | hiro | return;
|
| 1543 | 1 | hiro | } |
| 1544 | 1 | hiro | if( strcmp( xtag->tag, TAG_IF_OLD_PERSONAL ) == 0 ) { |
| 1545 | 1 | hiro | if( addrindex_process_book( addrIndex, file, DISP_OLD_PERSONAL ) ) {
|
| 1546 | 1 | hiro | addrIndex->needsConversion = FALSE; |
| 1547 | 1 | hiro | addrIndex->wasConverted = TRUE; |
| 1548 | 1 | hiro | continue;
|
| 1549 | 1 | hiro | } |
| 1550 | 1 | hiro | return;
|
| 1551 | 1 | hiro | } |
| 1552 | 1 | hiro | element = xml_get_element( file ); |
| 1553 | 1 | hiro | attr = xml_get_current_tag_attr( file ); |
| 1554 | 1 | hiro | /* show_attribs( attr ); */
|
| 1555 | 1 | hiro | /* printf( "\ttag value : %s :\n", element ); */
|
| 1556 | 1 | hiro | addrindex_consume_tree( file ); |
| 1557 | 1 | hiro | } |
| 1558 | 1 | hiro | } |
| 1559 | 1 | hiro | |
| 1560 | 1 | hiro | static gint addrindex_convert_data( AddressIndex *addrIndex ) {
|
| 1561 | 1 | hiro | XMLFile *file = NULL;
|
| 1562 | 1 | hiro | gchar *fileSpec; |
| 1563 | 1 | hiro | |
| 1564 | 1 | hiro | fileSpec = g_strconcat( addrIndex->filePath, G_DIR_SEPARATOR_S, addrIndex->fileName, NULL );
|
| 1565 | 1 | hiro | addrIndex->retVal = MGU_NO_FILE; |
| 1566 | 1 | hiro | file = xml_open_file( fileSpec ); |
| 1567 | 1 | hiro | g_free( fileSpec ); |
| 1568 | 1 | hiro | |
| 1569 | 1 | hiro | if( file == NULL ) { |
| 1570 | 1 | hiro | /* fprintf( stdout, " file '%s' does not exist.\n", addrIndex->fileName ); */
|
| 1571 | 1 | hiro | return addrIndex->retVal;
|
| 1572 | 1 | hiro | } |
| 1573 | 1 | hiro | |
| 1574 | 1 | hiro | addrIndex->retVal = MGU_BAD_FORMAT; |
| 1575 | 1 | hiro | if( xml_get_dtd( file ) == 0 ) { |
| 1576 | 1 | hiro | if( xml_parse_next_tag( file ) == 0 ) { |
| 1577 | 1 | hiro | if( xml_compare_tag( file, TAG_ADDRESS_INDEX ) ) {
|
| 1578 | 1 | hiro | addrindex_convert_tree( addrIndex, file ); |
| 1579 | 1 | hiro | } |
| 1580 | 1 | hiro | } |
| 1581 | 1 | hiro | } |
| 1582 | 1 | hiro | xml_close_file( file ); |
| 1583 | 1 | hiro | return addrIndex->retVal;
|
| 1584 | 1 | hiro | } |
| 1585 | 1 | hiro | |
| 1586 | 1 | hiro | /*
|
| 1587 | 1 | hiro | * Create a new address book file. |
| 1588 | 1 | hiro | */ |
| 1589 | 1 | hiro | static gboolean addrindex_create_new_book( AddressIndex *addrIndex, gchar *displayName ) {
|
| 1590 | 1 | hiro | gboolean retVal = FALSE; |
| 1591 | 1 | hiro | AddressBookFile *abf = NULL;
|
| 1592 | 1 | hiro | gchar *newFile = NULL;
|
| 1593 | 1 | hiro | GList *fileList = NULL;
|
| 1594 | 1 | hiro | gint fileNum = 0;
|
| 1595 | 1 | hiro | |
| 1596 | 1 | hiro | /* Create new address book */
|
| 1597 | 1 | hiro | abf = addrbook_create_book(); |
| 1598 | 1 | hiro | addrbook_set_name( abf, displayName ); |
| 1599 | 1 | hiro | addrbook_set_path( abf, addrIndex->filePath ); |
| 1600 | 1 | hiro | |
| 1601 | 1 | hiro | /* Determine next available file number */
|
| 1602 | 1 | hiro | fileList = addrbook_get_bookfile_list( abf ); |
| 1603 | 1 | hiro | if( fileList ) {
|
| 1604 | 1 | hiro | fileNum = 1 + abf->maxValue;
|
| 1605 | 1 | hiro | } |
| 1606 | 1 | hiro | g_list_free( fileList ); |
| 1607 | 1 | hiro | fileList = NULL;
|
| 1608 | 1 | hiro | |
| 1609 | 1 | hiro | newFile = addrbook_gen_new_file_name( fileNum ); |
| 1610 | 1 | hiro | if( newFile ) {
|
| 1611 | 1 | hiro | addrbook_set_file( abf, newFile ); |
| 1612 | 1 | hiro | } |
| 1613 | 1 | hiro | |
| 1614 | 1 | hiro | addrbook_save_data( abf ); |
| 1615 | 1 | hiro | addrIndex->retVal = abf->retVal; |
| 1616 | 1 | hiro | if( abf->retVal == MGU_SUCCESS ) retVal = TRUE;
|
| 1617 | 1 | hiro | addrbook_free_book( abf ); |
| 1618 | 1 | hiro | abf = NULL;
|
| 1619 | 1 | hiro | |
| 1620 | 1 | hiro | /* Create entries in address index */
|
| 1621 | 1 | hiro | if( retVal ) {
|
| 1622 | 1 | hiro | abf = addrbook_create_book(); |
| 1623 | 1 | hiro | addrbook_set_name( abf, displayName ); |
| 1624 | 1 | hiro | addrbook_set_path( abf, addrIndex->filePath ); |
| 1625 | 1 | hiro | addrbook_set_file( abf, newFile ); |
| 1626 | 1 | hiro | addrindex_index_add_datasource( addrIndex, ADDR_IF_BOOK, abf ); |
| 1627 | 1 | hiro | } |
| 1628 | 1 | hiro | |
| 1629 | 1 | hiro | return retVal;
|
| 1630 | 1 | hiro | } |
| 1631 | 1 | hiro | |
| 1632 | 1 | hiro | /*
|
| 1633 | 1 | hiro | * Read data for address index performing a conversion if necesary. |
| 1634 | 1 | hiro | * Enter: addrIndex Address index object. |
| 1635 | 1 | hiro | * return: Status code, from addrIndex->retVal. |
| 1636 | 1 | hiro | * Note: New address book files will be created in directory specified by |
| 1637 | 1 | hiro | * addrIndex. Three files will be created, for the following: |
| 1638 | 1 | hiro | * "Common addresses" |
| 1639 | 1 | hiro | * "Personal addresses" |
| 1640 | 2442 | hiro | * "Auto-registered" - a new address book. |
| 1641 | 1 | hiro | */ |
| 1642 | 1 | hiro | gint addrindex_read_data( AddressIndex *addrIndex ) {
|
| 1643 | 1 | hiro | g_return_val_if_fail( addrIndex != NULL, -1 ); |
| 1644 | 1 | hiro | |
| 1645 | 1 | hiro | addrIndex->conversionError = FALSE; |
| 1646 | 1 | hiro | addrindex_read_file( addrIndex ); |
| 1647 | 1 | hiro | if( addrIndex->retVal == MGU_SUCCESS ) {
|
| 1648 | 1 | hiro | if( addrIndex->needsConversion ) {
|
| 1649 | 1 | hiro | if( addrindex_convert_data( addrIndex ) == MGU_SUCCESS ) {
|
| 1650 | 1 | hiro | addrIndex->conversionError = TRUE; |
| 1651 | 1 | hiro | } |
| 1652 | 1 | hiro | else {
|
| 1653 | 1 | hiro | addrIndex->conversionError = TRUE; |
| 1654 | 1 | hiro | } |
| 1655 | 1 | hiro | } |
| 1656 | 1 | hiro | addrIndex->dirtyFlag = TRUE; |
| 1657 | 1 | hiro | } |
| 1658 | 1 | hiro | return addrIndex->retVal;
|
| 1659 | 1 | hiro | } |
| 1660 | 1 | hiro | |
| 1661 | 1 | hiro | /*
|
| 1662 | 1 | hiro | * Create new address books for a new address index. |
| 1663 | 1 | hiro | * Enter: addrIndex Address index object. |
| 1664 | 1 | hiro | * return: Status code, from addrIndex->retVal. |
| 1665 | 1 | hiro | * Note: New address book files will be created in directory specified by |
| 1666 | 1 | hiro | * addrIndex. Three files will be created, for the following: |
| 1667 | 1 | hiro | * "Common addresses" |
| 1668 | 1 | hiro | * "Personal addresses" |
| 1669 | 2442 | hiro | * "Auto-registered" - a new address book. |
| 1670 | 1 | hiro | */ |
| 1671 | 1 | hiro | gint addrindex_create_new_books( AddressIndex *addrIndex ) {
|
| 1672 | 1 | hiro | gboolean flg; |
| 1673 | 1 | hiro | |
| 1674 | 1 | hiro | g_return_val_if_fail( addrIndex != NULL, -1 ); |
| 1675 | 1 | hiro | |
| 1676 | 1 | hiro | flg = addrindex_create_new_book( addrIndex, DISP_NEW_COMMON ); |
| 1677 | 1 | hiro | if( flg ) {
|
| 1678 | 1 | hiro | flg = addrindex_create_new_book( addrIndex, DISP_NEW_PERSONAL ); |
| 1679 | 2442 | hiro | flg = addrindex_create_new_book( addrIndex, ADDR_DS_AUTOREG ); |
| 1680 | 1 | hiro | addrIndex->dirtyFlag = TRUE; |
| 1681 | 1 | hiro | } |
| 1682 | 1 | hiro | return addrIndex->retVal;
|
| 1683 | 1 | hiro | } |
| 1684 | 1 | hiro | |
| 1685 | 2442 | hiro | gint addrindex_create_extra_books( AddressIndex *addrIndex ) {
|
| 1686 | 2442 | hiro | GList *node_ds; |
| 1687 | 2850 | hiro | AddressInterface *iface = NULL;
|
| 1688 | 2442 | hiro | AddressDataSource *ds = NULL;
|
| 1689 | 2442 | hiro | const gchar *ds_name;
|
| 1690 | 2442 | hiro | |
| 1691 | 2442 | hiro | g_return_val_if_fail(addrIndex != NULL, -1); |
| 1692 | 2442 | hiro | |
| 1693 | 2850 | hiro | iface = addrindex_get_interface(addrIndex, ADDR_IF_BOOK); |
| 1694 | 2850 | hiro | if (!iface)
|
| 1695 | 2442 | hiro | return -1; |
| 1696 | 2442 | hiro | |
| 1697 | 2850 | hiro | for (node_ds = iface->listSource; node_ds != NULL; |
| 1698 | 2442 | hiro | node_ds = node_ds->next) {
|
| 1699 | 2442 | hiro | ds = node_ds->data; |
| 1700 | 2442 | hiro | ds_name = addrindex_ds_get_name(ds); |
| 1701 | 2442 | hiro | if (!ds_name)
|
| 1702 | 2442 | hiro | continue;
|
| 1703 | 2442 | hiro | if (!strcmp(ds_name, ADDR_DS_AUTOREG)) {
|
| 1704 | 2442 | hiro | debug_print("%s found\n", ADDR_DS_AUTOREG);
|
| 1705 | 2442 | hiro | return 0; |
| 1706 | 2442 | hiro | } |
| 1707 | 2442 | hiro | } |
| 1708 | 2442 | hiro | |
| 1709 | 2442 | hiro | debug_print("%s not found, creating new one\n", ADDR_DS_AUTOREG);
|
| 1710 | 2442 | hiro | if (addrindex_create_new_book(addrIndex, ADDR_DS_AUTOREG)) {
|
| 1711 | 2442 | hiro | addrIndex->dirtyFlag = TRUE; |
| 1712 | 2442 | hiro | } |
| 1713 | 2442 | hiro | |
| 1714 | 2442 | hiro | return addrIndex->retVal;
|
| 1715 | 2442 | hiro | } |
| 1716 | 2442 | hiro | |
| 1717 | 1 | hiro | /* **********************************************************************
|
| 1718 | 1 | hiro | * New interface stuff. |
| 1719 | 1 | hiro | * *********************************************************************** |
| 1720 | 1 | hiro | */ |
| 1721 | 1 | hiro | |
| 1722 | 1 | hiro | /*
|
| 1723 | 1 | hiro | * Return modified flag for specified data source. |
| 1724 | 1 | hiro | */ |
| 1725 | 1 | hiro | gboolean addrindex_ds_get_modify_flag( AddressDataSource *ds ) {
|
| 1726 | 1 | hiro | gboolean retVal = FALSE; |
| 1727 | 1 | hiro | AddressInterface *iface; |
| 1728 | 1 | hiro | |
| 1729 | 1 | hiro | if( ds == NULL ) return retVal; |
| 1730 | 2844 | hiro | iface = ds->iface; |
| 1731 | 1 | hiro | if( iface == NULL ) return retVal; |
| 1732 | 1 | hiro | if( iface->getModifyFlag ) {
|
| 1733 | 1 | hiro | retVal = ( iface->getModifyFlag ) ( ds->rawDataSource ); |
| 1734 | 1 | hiro | } |
| 1735 | 1 | hiro | return retVal;
|
| 1736 | 1 | hiro | } |
| 1737 | 1 | hiro | |
| 1738 | 1 | hiro | /*
|
| 1739 | 1 | hiro | * Return accessed flag for specified data source. |
| 1740 | 1 | hiro | */ |
| 1741 | 1 | hiro | gboolean addrindex_ds_get_access_flag( AddressDataSource *ds ) {
|
| 1742 | 1 | hiro | gboolean retVal = FALSE; |
| 1743 | 1 | hiro | AddressInterface *iface; |
| 1744 | 1 | hiro | |
| 1745 | 1 | hiro | if( ds == NULL ) return retVal; |
| 1746 | 2844 | hiro | iface = ds->iface; |
| 1747 | 1 | hiro | if( iface == NULL ) return retVal; |
| 1748 | 1 | hiro | if( iface->getAccessFlag ) {
|
| 1749 | 1 | hiro | retVal = ( iface->getAccessFlag ) ( ds->rawDataSource ); |
| 1750 | 1 | hiro | } |
| 1751 | 1 | hiro | return retVal;
|
| 1752 | 1 | hiro | } |
| 1753 | 1 | hiro | |
| 1754 | 1 | hiro | /*
|
| 1755 | 1 | hiro | * Return data read flag for specified data source. |
| 1756 | 1 | hiro | */ |
| 1757 | 1 | hiro | gboolean addrindex_ds_get_read_flag( AddressDataSource *ds ) {
|
| 1758 | 1 | hiro | gboolean retVal = TRUE; |
| 1759 | 1 | hiro | AddressInterface *iface; |
| 1760 | 1 | hiro | |
| 1761 | 1 | hiro | if( ds == NULL ) return retVal; |
| 1762 | 2844 | hiro | iface = ds->iface; |
| 1763 | 1 | hiro | if( iface == NULL ) return retVal; |
| 1764 | 1 | hiro | if( iface->getReadFlag ) {
|
| 1765 | 1 | hiro | retVal = ( iface->getReadFlag ) ( ds->rawDataSource ); |
| 1766 | 1 | hiro | } |
| 1767 | 1 | hiro | return retVal;
|
| 1768 | 1 | hiro | } |
| 1769 | 1 | hiro | |
| 1770 | 1 | hiro | /*
|
| 1771 | 1 | hiro | * Return status code for specified data source. |
| 1772 | 1 | hiro | */ |
| 1773 | 1 | hiro | gint addrindex_ds_get_status_code( AddressDataSource *ds ) {
|
| 1774 | 1 | hiro | gint retVal = MGU_SUCCESS; |
| 1775 | 1 | hiro | AddressInterface *iface; |
| 1776 | 1 | hiro | |
| 1777 | 1 | hiro | if( ds == NULL ) return retVal; |
| 1778 | 2844 | hiro | iface = ds->iface; |
| 1779 | 1 | hiro | if( iface == NULL ) return retVal; |
| 1780 | 1 | hiro | if( iface->getStatusCode ) {
|
| 1781 | 1 | hiro | retVal = ( iface->getStatusCode ) ( ds->rawDataSource ); |
| 1782 | 1 | hiro | } |
| 1783 | 1 | hiro | return retVal;
|
| 1784 | 1 | hiro | } |
| 1785 | 1 | hiro | |
| 1786 | 1 | hiro | /*
|
| 1787 | 1 | hiro | * Return data read flag for specified data source. |
| 1788 | 1 | hiro | */ |
| 1789 | 1 | hiro | gint addrindex_ds_read_data( AddressDataSource *ds ) {
|
| 1790 | 1 | hiro | gint retVal = MGU_SUCCESS; |
| 1791 | 1 | hiro | AddressInterface *iface; |
| 1792 | 1 | hiro | |
| 1793 | 1 | hiro | if( ds == NULL ) return retVal; |
| 1794 | 2844 | hiro | iface = ds->iface; |
| 1795 | 1 | hiro | if( iface == NULL ) return retVal; |
| 1796 | 1 | hiro | if( iface->getReadData ) {
|
| 1797 | 1 | hiro | retVal = ( iface->getReadData ) ( ds->rawDataSource ); |
| 1798 | 1 | hiro | } |
| 1799 | 1 | hiro | return retVal;
|
| 1800 | 1 | hiro | } |
| 1801 | 1 | hiro | |
| 1802 | 1 | hiro | /*
|
| 1803 | 1 | hiro | * Return data read flag for specified data source. |
| 1804 | 1 | hiro | */ |
| 1805 | 1 | hiro | ItemFolder *addrindex_ds_get_root_folder( AddressDataSource *ds ) {
|
| 1806 | 1 | hiro | ItemFolder *retVal = NULL;
|
| 1807 | 1 | hiro | AddressInterface *iface; |
| 1808 | 1 | hiro | |
| 1809 | 1 | hiro | if( ds == NULL ) return retVal; |
| 1810 | 2844 | hiro | iface = ds->iface; |
| 1811 | 1 | hiro | if( iface == NULL ) return retVal; |
| 1812 | 1 | hiro | if( iface->getRootFolder ) {
|
| 1813 | 1 | hiro | retVal = ( iface->getRootFolder ) ( ds->rawDataSource ); |
| 1814 | 1 | hiro | } |
| 1815 | 1 | hiro | return retVal;
|
| 1816 | 1 | hiro | } |
| 1817 | 1 | hiro | |
| 1818 | 1 | hiro | /*
|
| 1819 | 1 | hiro | * Return list of folders for specified data source. |
| 1820 | 1 | hiro | */ |
| 1821 | 1 | hiro | GList *addrindex_ds_get_list_folder( AddressDataSource *ds ) {
|
| 1822 | 1 | hiro | GList *retVal = FALSE; |
| 1823 | 1 | hiro | AddressInterface *iface; |
| 1824 | 1 | hiro | |
| 1825 | 1 | hiro | if( ds == NULL ) return retVal; |
| 1826 | 2844 | hiro | iface = ds->iface; |
| 1827 | 1 | hiro | if( iface == NULL ) return retVal; |
| 1828 | 1 | hiro | if( iface->getListFolder ) {
|
| 1829 | 1 | hiro | retVal = ( iface->getListFolder ) ( ds->rawDataSource ); |
| 1830 | 1 | hiro | } |
| 1831 | 1 | hiro | return retVal;
|
| 1832 | 1 | hiro | } |
| 1833 | 1 | hiro | |
| 1834 | 1 | hiro | /*
|
| 1835 | 1 | hiro | * Return list of persons in root folder for specified data source. |
| 1836 | 1 | hiro | */ |
| 1837 | 1 | hiro | GList *addrindex_ds_get_list_person( AddressDataSource *ds ) {
|
| 1838 | 1 | hiro | GList *retVal = FALSE; |
| 1839 | 1 | hiro | AddressInterface *iface; |
| 1840 | 1 | hiro | |
| 1841 | 1 | hiro | if( ds == NULL ) return retVal; |
| 1842 | 2844 | hiro | iface = ds->iface; |
| 1843 | 1 | hiro | if( iface == NULL ) return retVal; |
| 1844 | 1 | hiro | if( iface->getListPerson ) {
|
| 1845 | 1 | hiro | retVal = ( iface->getListPerson ) ( ds->rawDataSource ); |
| 1846 | 1 | hiro | } |
| 1847 | 1 | hiro | return retVal;
|
| 1848 | 1 | hiro | } |
| 1849 | 1 | hiro | |
| 1850 | 1 | hiro | /*
|
| 1851 | 1 | hiro | * Return name for specified data source. |
| 1852 | 1 | hiro | */ |
| 1853 | 1 | hiro | gchar *addrindex_ds_get_name( AddressDataSource *ds ) {
|
| 1854 | 1 | hiro | gchar *retVal = FALSE; |
| 1855 | 1 | hiro | AddressInterface *iface; |
| 1856 | 1 | hiro | |
| 1857 | 1 | hiro | if( ds == NULL ) return retVal; |
| 1858 | 2844 | hiro | iface = ds->iface; |
| 1859 | 1 | hiro | if( iface == NULL ) return retVal; |
| 1860 | 1 | hiro | if( iface->getName ) {
|
| 1861 | 1 | hiro | retVal = ( iface->getName ) ( ds->rawDataSource ); |
| 1862 | 1 | hiro | } |
| 1863 | 1 | hiro | return retVal;
|
| 1864 | 1 | hiro | } |
| 1865 | 1 | hiro | |
| 1866 | 1 | hiro | /*
|
| 1867 | 1 | hiro | * Set the access flag inside the data source. |
| 1868 | 1 | hiro | */ |
| 1869 | 1 | hiro | void addrindex_ds_set_access_flag( AddressDataSource *ds, gboolean *value ) {
|
| 1870 | 1 | hiro | AddressInterface *iface; |
| 1871 | 1 | hiro | |
| 1872 | 1 | hiro | if( ds == NULL ) return; |
| 1873 | 2844 | hiro | iface = ds->iface; |
| 1874 | 1 | hiro | if( iface == NULL ) return; |
| 1875 | 1 | hiro | if( iface->setAccessFlag ) {
|
| 1876 | 1 | hiro | ( iface->setAccessFlag ) ( ds->rawDataSource, value ); |
| 1877 | 1 | hiro | } |
| 1878 | 1 | hiro | } |
| 1879 | 1 | hiro | |
| 1880 | 1 | hiro | /*
|
| 1881 | 1 | hiro | * Return read only flag for specified data source. |
| 1882 | 1 | hiro | */ |
| 1883 | 1 | hiro | gboolean addrindex_ds_get_readonly( AddressDataSource *ds ) {
|
| 1884 | 1 | hiro | AddressInterface *iface; |
| 1885 | 1 | hiro | if( ds == NULL ) return TRUE; |
| 1886 | 2844 | hiro | iface = ds->iface; |
| 1887 | 1 | hiro | if( iface == NULL ) return TRUE; |
| 1888 | 1 | hiro | return iface->readOnly;
|
| 1889 | 1 | hiro | } |
| 1890 | 1 | hiro | |
| 1891 | 1 | hiro | /*
|
| 1892 | 1 | hiro | * Return list of all persons for specified data source. |
| 1893 | 1 | hiro | */ |
| 1894 | 1 | hiro | GList *addrindex_ds_get_all_persons( AddressDataSource *ds ) {
|
| 1895 | 1 | hiro | GList *retVal = NULL;
|
| 1896 | 1 | hiro | AddressInterface *iface; |
| 1897 | 1 | hiro | |
| 1898 | 1 | hiro | if( ds == NULL ) return retVal; |
| 1899 | 2844 | hiro | iface = ds->iface; |
| 1900 | 1 | hiro | if( iface == NULL ) return retVal; |
| 1901 | 1 | hiro | if( iface->getAllPersons ) {
|
| 1902 | 1 | hiro | retVal = ( iface->getAllPersons ) ( ds->rawDataSource ); |
| 1903 | 1 | hiro | } |
| 1904 | 1 | hiro | return retVal;
|
| 1905 | 1 | hiro | } |
| 1906 | 1 | hiro | |
| 1907 | 1 | hiro | /*
|
| 1908 | 1 | hiro | * Return list of all groups for specified data source. |
| 1909 | 1 | hiro | */ |
| 1910 | 1 | hiro | GList *addrindex_ds_get_all_groups( AddressDataSource *ds ) {
|
| 1911 | 1 | hiro | GList *retVal = NULL;
|
| 1912 | 1 | hiro | AddressInterface *iface; |
| 1913 | 1 | hiro | |
| 1914 | 1 | hiro | if( ds == NULL ) return retVal; |
| 1915 | 2844 | hiro | iface = ds->iface; |
| 1916 | 1 | hiro | if( iface == NULL ) return retVal; |
| 1917 | 1 | hiro | if( iface->getAllGroups ) {
|
| 1918 | 1 | hiro | retVal = ( iface->getAllGroups ) ( ds->rawDataSource ); |
| 1919 | 1 | hiro | } |
| 1920 | 1 | hiro | return retVal;
|
| 1921 | 1 | hiro | } |
| 1922 | 1 | hiro | |
| 1923 | 1 | hiro | /*
|
| 1924 | 1 | hiro | * End of Source. |
| 1925 | 1 | hiro | */ |