- Timestamp:
- 2015-02-20T22:50:54Z (9 years ago)
- Branches:
- master
- Children:
- 0b9daac, 3d45471, 7733b8c
- Parents:
- af359b4
- git-author:
- Indent <please@…> (19-02-15 05:47:20)
- git-committer:
- dequis <dx@…> (20-02-15 22:50:54)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
storage.c
raf359b4 r5ebff60 1 1 /********************************************************************\ 2 2 * BitlBee -- An IRC to other IM-networks gateway * 3 3 * * … … 46 46 for (gl = storage_backends; gl; gl = gl->next) { 47 47 st = gl->data; 48 if (strcmp(st->name, name) == 0) 48 if (strcmp(st->name, name) == 0) { 49 49 break; 50 } 51 52 if (gl == NULL) 50 } 51 } 52 53 if (gl == NULL) { 53 54 return NULL; 54 55 if (st->init) 55 } 56 57 if (st->init) { 56 58 st->init(); 59 } 57 60 58 61 return st; … … 64 67 int i; 65 68 storage_t *storage; 66 69 67 70 register_storage_backend(&storage_xml); 68 71 69 72 storage = storage_init_single(primary); 70 if (storage == NULL && storage->save == NULL) 73 if (storage == NULL && storage->save == NULL) { 71 74 return NULL; 75 } 72 76 73 77 ret = g_list_append(ret, storage); … … 75 79 for (i = 0; migrate && migrate[i]; i++) { 76 80 storage = storage_init_single(migrate[i]); 77 78 if (storage) 81 82 if (storage) { 79 83 ret = g_list_append(ret, storage); 84 } 80 85 } 81 86 … … 83 88 } 84 89 85 storage_status_t storage_check_pass 86 { 87 GList *gl; 88 90 storage_status_t storage_check_pass(const char *nick, const char *password) 91 { 92 GList *gl; 93 89 94 /* Loop until we don't get NO_SUCH_USER */ 90 95 … … 94 99 95 100 status = st->check_pass(nick, password); 96 if (status != STORAGE_NO_SUCH_USER) 101 if (status != STORAGE_NO_SUCH_USER) { 97 102 return status; 98 } 99 103 } 104 } 105 100 106 return STORAGE_NO_SUCH_USER; 101 107 } 102 108 103 storage_status_t storage_load 104 { 105 GList *gl; 106 107 if (irc && irc->status & USTATUS_IDENTIFIED) 109 storage_status_t storage_load(irc_t * irc, const char *password) 110 { 111 GList *gl; 112 113 if (irc && irc->status & USTATUS_IDENTIFIED) { 108 114 return STORAGE_OTHER_ERROR; 109 115 } 116 110 117 /* Loop until we don't get NO_SUCH_USER */ 111 118 for (gl = global.storage; gl; gl = gl->next) { … … 114 121 115 122 status = st->load(irc, password); 116 if (status == STORAGE_OK) 117 { 123 if (status == STORAGE_OK) { 118 124 GSList *l; 119 for( l = irc_plugins; l; l = l->next ) 120 { 125 for (l = irc_plugins; l; l = l->next) { 121 126 irc_plugin_t *p = l->data; 122 if( p->storage_load ) 123 p->storage_load( irc ); 127 if (p->storage_load) { 128 p->storage_load(irc); 129 } 124 130 } 125 131 return status; 126 132 } 127 128 if (status != STORAGE_NO_SUCH_USER) 133 134 if (status != STORAGE_NO_SUCH_USER) { 129 135 return status; 130 } 131 136 } 137 } 138 132 139 return STORAGE_NO_SUCH_USER; 133 140 } 134 141 135 storage_status_t storage_save 142 storage_status_t storage_save(irc_t *irc, char *password, int overwrite) 136 143 { 137 144 storage_status_t st; 138 145 GSList *l; 139 146 140 147 if (password != NULL) { 141 148 /* Should only use this in the "register" command. */ 142 if (irc->password || overwrite) 149 if (irc->password || overwrite) { 143 150 return STORAGE_OTHER_ERROR; 144 151 } 152 145 153 irc_setpass(irc, password); 146 154 } else if ((irc->status & USTATUS_IDENTIFIED) == 0) { 147 155 return STORAGE_NO_SUCH_USER; 148 156 } 149 150 st = ((storage_t *)global.storage->data)->save(irc, overwrite); 151 152 for( l = irc_plugins; l; l = l->next ) 153 { 157 158 st = ((storage_t *) global.storage->data)->save(irc, overwrite); 159 160 for (l = irc_plugins; l; l = l->next) { 154 161 irc_plugin_t *p = l->data; 155 if( p->storage_save ) 156 p->storage_save( irc ); 157 } 158 162 if (p->storage_save) { 163 p->storage_save(irc); 164 } 165 } 166 159 167 if (password != NULL) { 160 168 irc_setpass(irc, NULL); 161 169 } 162 170 163 171 return st; 164 172 } 165 173 166 storage_status_t storage_remove 174 storage_status_t storage_remove(const char *nick, const char *password) 167 175 { 168 176 GList *gl; … … 170 178 gboolean ok = FALSE; 171 179 GSList *l; 172 173 /* Remove this account from all storage backends. If this isn't 174 * done, the account will still be usable, it'd just be 180 181 /* Remove this account from all storage backends. If this isn't 182 * done, the account will still be usable, it'd just be 175 183 * loaded from a different backend. */ 176 184 for (gl = global.storage; gl; gl = gl->next) { … … 180 188 status = st->remove(nick, password); 181 189 ok |= status == STORAGE_OK; 182 if (status != STORAGE_NO_SUCH_USER && status != STORAGE_OK) 190 if (status != STORAGE_NO_SUCH_USER && status != STORAGE_OK) { 183 191 ret = status; 184 } 185 192 } 193 } 194 186 195 /* If at least one succeeded, remove plugin data. */ 187 if( ok ) 188 for( l = irc_plugins; l; l = l->next ) 189 { 196 if (ok) { 197 for (l = irc_plugins; l; l = l->next) { 190 198 irc_plugin_t *p = l->data; 191 if( p->storage_remove ) 192 p->storage_remove( nick ); 193 } 194 199 if (p->storage_remove) { 200 p->storage_remove(nick); 201 } 202 } 203 } 204 195 205 return ret; 196 206 }
Note: See TracChangeset
for help on using the changeset viewer.