s_persistency.c File Reference


Detailed Description

S-CSCF persistency operations.

Author:
Dragos Vingarzan vingarzan -at- fokus dot fraunhofer dot de
Database persistency implemented by Mario Ferreira (PT INOVACAO)
Author:
Mario Ferreira est-m-aferreira at ptinovacao.pt

Definition in file s_persistency.c.

#include "s_persistency.h"

Go to the source code of this file.

Functions

int s_dump (bin_data *x, char *location, char *prepend_fname, data_type_t dt)
 Dumps S-CSCF data to files or DB.
int bin_dump_to_db (bin_data *x, data_type_t dt)
 Dumps S-CSCF data to DB.
int bin_dump_registrar_to_table (bin_data *x, int snapshot_version, int step_version)
 Dumps S-CSCF registrar to DB.
int bin_dump_dialogs_to_table (bin_data *x, int snapshot_version, int step_version)
 Dumps S-CSCF dialogs to DB.
int bin_dump_auth_to_table (bin_data *x, int snapshot_version, int step_version)
 Dumps S-CSCF auth to DB.
int bin_bulk_dump_to_table (data_type_t dt, int snapshot_version, int step_version, bin_data *x)
 Dumps S-CSCF data to the snapshot table.
int bin_cache_dump_registrar_to_table (int snapshot_version, int step_version)
 Dumps S-CSCF registrar to the snapshot table.
int bin_cache_dump_dialogs_to_table (int snapshot_version, int step_version)
 Dumps S-CSCF dialogs to the snapshot table.
int bin_cache_dump_auth_to_table (int snapshot_version, int step_version)
 Dumps S-CSCF auth data to the snapshot table.
int delete_older_snapshots (char *table, char *node_id, data_type_t dt, int current_snapshot)
 Drops older auth/dialogs/registrar snapshots, keeping the 'bin_db_keep_count' most recent.
int s_load (bin_data *x, char *location, char *prepend_fname, data_type_t dt)
 Loads S-CSCF data from files or DB.
int bin_load_from_db (bin_data *x, data_type_t dt)
 Loads S-CSCF data from DB.
int bin_load_registrar_from_table (bin_data *x)
 Loads S-CSCF registrar from DB.
int bin_load_dialogs_from_table (bin_data *x)
 Loads S-CSCF dialogs from DB.
int bin_load_auth_from_table (bin_data *x)
 Loads S-CSCF auth data from DB.
int bin_bulk_load_from_table (data_type_t dt, bin_data *x)
 Loads S-CSCF data from the snapshot table.
int bin_cache_load_registrar_from_table ()
 Loads S-CSCF registrar from the snapshot table.
int bin_cache_load_dialogs_from_table ()
 Loads S-CSCF dialogs from the snapshot table.
int bin_cache_load_auth_from_table ()
 Loads S-CSCF auth data from the snapshot table.
int db_get_last_snapshot_version (char *table, char *node_id, data_type_t dt, int *version)
 Gets the version of the last snapshot dumped to db.
int set_versions (data_type_t dt, int snapshot_version, int step_version)
 Sets the values of the global variables registrar/dialogs/auth_snapshot_version and registrar/dialogs/auth_step_version.
int make_snapshot_authdata ()
 Creates a snapshots of the authorization data and then calls the dumping function.
int load_snapshot_authdata ()
 Loads the authorization data from the last snapshot.
void persistency_timer_authdata (unsigned int ticks, void *param)
 Timer callback for persistency dumps.
int make_snapshot_dialogs ()
 Creates a snapshots of the dialogs data and then calls the dumping function.
int load_snapshot_dialogs ()
 Loads the dialogs data from the last snapshot.
void persistency_timer_dialogs (unsigned int ticks, void *param)
 Timer callback for persistency dumps.
int make_snapshot_registrar ()
 Creates a snapshots of the registrar and then calls the dumping function.
int load_snapshot_registrar ()
 Loads the registrar data from the last snapshot.
void persistency_timer_registrar (unsigned int ticks, void *param)
 Timer callback for persistency dumps.

Variables

persistency_mode_t scscf_persistency_mode
 the type of persistency
char * scscf_persistency_location
 where to dump the persistency data
auth_hash_slot_tauth_data
 Authentication vector hash table.
int auth_data_hash_size
 authentication vector hash table size
int r_hash_size
 Size of S-CSCF registrar hash table.
r_hash_slotregistrar
 The S-CSCF registrar.
int s_dialogs_hash_size
 size of the dialog hash table
s_dialog_hash_slots_dialogs
 the hash table
db_con_t * scscf_db
 Database connection handle.
db_func_t scscf_dbf
 Structure with pointers to db functions.
int * auth_snapshot_version
 the version of the next auth snapshot on the db
int * auth_step_version
 the step version within the current auth snapshot version
int * dialogs_snapshot_version
 the version of the next dialogs snapshot on the db
int * dialogs_step_version
 the step version within the current dialogs snapshot version
int * registrar_snapshot_version
 the version of the next registrar snapshot on the db
int * registrar_step_version
 the step version within the current registrar snapshot version
gen_lock_t * db_lock
 lock for db access
char * scscf_name
 name of the S-CSCF
int bin_db_keep_count = 1
 how many old snapshots to keep


Function Documentation

int s_dump ( bin_data x,
char *  location,
char *  prepend_fname,
data_type_t  dt 
)

Dumps S-CSCF data to files or DB.

Parameters:
x - binary data to dump. Empty if scscf_persistency_mode==WITH_DATABASE_CACHE. In this case, each hashtable element is serialized and dumped to DB separately.
location -
prepend_fname -
dt - dump registrar, dialogs or auth
Returns:
1 on success or 0 on failure

Definition at line 369 of file s_persistency.c.

References bin_dump_to_db(), bin_dump_to_file(), M_NAME, NO_PERSISTENCY, NULL, scscf_persistency_mode, WITH_DATABASE_BULK, WITH_DATABASE_CACHE, and WITH_FILES.

Referenced by make_snapshot_authdata(), make_snapshot_dialogs(), and make_snapshot_registrar().

00369                                                                             {
00370     
00371     switch (scscf_persistency_mode){
00372         case NO_PERSISTENCY:
00373             LOG(L_ERR,"ERR:"M_NAME":s_dump: Snapshot done but persistency was disabled...\n");
00374             return 0;
00375         case WITH_FILES:
00376             return bin_dump_to_file(x,location,prepend_fname);
00377         case WITH_DATABASE_BULK:
00378             return bin_dump_to_db(x, dt);
00379         case WITH_DATABASE_CACHE:
00380             return bin_dump_to_db(NULL, dt);//ignore x, x is empty
00381         default:
00382             LOG(L_ERR,"ERR:"M_NAME":s_dump: Snapshot done but no such mode %d\n",scscf_persistency_mode);
00383             return 0;
00384     }
00385 }

int bin_dump_to_db ( bin_data x,
data_type_t  dt 
)

Dumps S-CSCF data to DB.

Parameters:
x - binary data to dump. NULL if scscf_persistency_mode==WITH_DATABASE_CACHE. In this case, each hashtable element is serialized and dumped to DB separately.
dt - dump registrar, dialogs or auth
Returns:
1 on success or 0 on failure

int bin_dump_registrar_to_table ( bin_data x,
int  snapshot_version,
int  step_version 
)

Dumps S-CSCF registrar to DB.

Parameters:
x - binary data to dump. NULL if scscf_persistency_mode==WITH_DATABASE_CACHE. In this case, each hashtable element is serialized and dumped to DB separately.
snapshot_version - version of the current snapshot
step_version - the step in the current snapshot
Returns:
1 on success or 0 on failure

int bin_dump_dialogs_to_table ( bin_data x,
int  snapshot_version,
int  step_version 
)

Dumps S-CSCF dialogs to DB.

Parameters:
x - binary data to dump. NULL if scscf_persistency_mode==WITH_DATABASE_CACHE. In this case, each hashtable element is serialized and dumped to DB separately.
snapshot_version - version of the current snapshot
step_version - the step in the current snapshot
Returns:
1 on success or 0 on failure

int bin_dump_auth_to_table ( bin_data x,
int  snapshot_version,
int  step_version 
)

Dumps S-CSCF auth to DB.

Parameters:
x - binary data to dump. NULL if scscf_persistency_mode==WITH_DATABASE_CACHE. In this case, each hashtable element is serialized and dumped to DB separately.
snapshot_version - version of the current snapshot
step_version - the step in the current snapshot
Returns:
1 on success or 0 on failure

Definition at line 462 of file s_persistency.c.

References bin_bulk_dump_to_table(), bin_cache_dump_auth_to_table(), and S_AUTH.

00462                                                                                {
00463     
00464     if(x){//whole hashtable serialized to x
00465         return bin_bulk_dump_to_table(S_AUTH, snapshot_version, step_version, x);
00466     }
00467     else{//serialize and dump each hashtable element separately
00468         return bin_cache_dump_auth_to_table(snapshot_version, step_version);
00469     }
00470 }

int bin_bulk_dump_to_table ( data_type_t  dt,
int  snapshot_version,
int  step_version,
bin_data x 
)

Dumps S-CSCF data to the snapshot table.

Parameters:
dt - dump registrar, dialogs or auth
snapshot_version - version of the current snapshot
step_version - the step in the current snapshot
x - binary data to dump (the whole hashtable).
Returns:
1 on success or 0 on failure

int bin_cache_dump_registrar_to_table ( int  snapshot_version,
int  step_version 
)

Dumps S-CSCF registrar to the snapshot table.

Each r_public is serialized and dumped to one row of the table.

Parameters:
snapshot_version - version of the current snapshot
step_version - the step in the current snapshot
Returns:
1 on success or 0 on failure

int bin_cache_dump_dialogs_to_table ( int  snapshot_version,
int  step_version 
)

Dumps S-CSCF dialogs to the snapshot table.

Each dialog is serialized and dumped to one row of the table.

Parameters:
snapshot_version - version of the current snapshot
step_version - the step in the current snapshot
Returns:
1 on success or 0 on failure

int bin_cache_dump_auth_to_table ( int  snapshot_version,
int  step_version 
)

Dumps S-CSCF auth data to the snapshot table.

Each auth hashtable element is serialized and dumped to one row of the table.

Parameters:
snapshot_version - version of the current snapshot
step_version - the step in the current snapshot
Returns:
1 on success or 0 on failure

Definition at line 761 of file s_persistency.c.

References auth_data, auth_data_hash_size, auth_data_lock(), auth_data_unlock(), bin_alloc(), bin_encode_auth_userdata(), bin_free(), db_lock, delete_older_snapshots(), auth_hash_slot_t::head, _bin_data::len, M_NAME, _auth_userdata::next, _auth_userdata::private_identity, _auth_userdata::public_identity, _bin_data::s, S_AUTH, scscf_db, scscf_dbf, and scscf_name.

Referenced by bin_dump_auth_to_table().

00761                                                                         {
00762     bin_data x;
00763     auth_userdata *aud;
00764     int i;
00765     int len;
00766     
00767     //lock
00768     lock_get(db_lock);
00769 
00770     if (scscf_dbf.use_table(scscf_db, "snapshot") < 0) {
00771         LOG(L_ERR, "ERR:"M_NAME":bin_cache_dump_auth_to_table(): Error in use_table\n");
00772         goto error;
00773     }
00774     
00775     for(i=0;i<auth_data_hash_size;i++){
00776         auth_data_lock(i);
00777         aud = auth_data[i].head;
00778         while(aud){
00779             if (!bin_alloc(&x,128)){
00780                 auth_data_unlock(i);
00781                 goto error;
00782             }
00783             if (!bin_encode_auth_userdata(&x,aud)){
00784                 auth_data_unlock(i);
00785                 goto error;
00786             }
00787             
00788             db_key_t keys[7];
00789             db_val_t vals[7];
00790             
00791             /* id auto incremented */
00792             keys[0] = "node_id";
00793             keys[1] = "data_type";
00794             keys[2] = "snapshot_version";
00795             keys[3] = "step_version";
00796             keys[4] = "record_id_1"; /* private */
00797             keys[5] = "record_id_2"; /* public */
00798             /* record_id_3/4=NULL*/
00799             keys[6] = "data";
00800             
00801             vals[0].type = DB_STR;
00802             vals[0].nul = 0;
00803             vals[0].val.str_val.s=scscf_name;
00804             len = strlen(scscf_name);
00805             vals[0].val.str_val.len=MIN(len, 64);
00806 
00807             vals[1].type = DB_INT;
00808             vals[1].nul = 0;
00809             vals[1].val.int_val=S_AUTH;
00810 
00811             vals[2].type = DB_INT;
00812             vals[2].nul = 0;
00813             vals[2].val.int_val=snapshot_version;
00814     
00815             vals[3].type = DB_INT;
00816             vals[3].nul = 0;
00817             vals[3].val.int_val=step_version;
00818     
00819             vals[4].type = DB_STR;
00820             vals[4].nul = 0;
00821             vals[4].val.str_val.s=aud->private_identity.s;
00822             vals[4].val.str_val.len=MIN(aud->private_identity.len, 256);
00823             
00824             vals[5].type = DB_STR;
00825             vals[5].nul = 0;
00826             vals[5].val.str_val.s=aud->public_identity.s;
00827             vals[5].val.str_val.len=MIN(aud->public_identity.len, 256);
00828     
00829             vals[6].type = DB_BLOB;
00830             vals[6].nul = 0;
00831             str data={x.s, x.len};
00832             vals[6].val.blob_val = data;
00833             
00834             if (scscf_dbf.insert(scscf_db, keys, vals, 7) < 0) {
00835                 LOG(L_ERR, "ERR:"M_NAME":bin_cache_dump_auth_to_table(): Error while inserting on snapshot table\n");
00836                 auth_data_unlock(i);
00837                 goto error;
00838             }
00839             bin_free(&x);
00840             
00841             aud = aud->next;
00842         }
00843         auth_data_unlock(i);
00844     }   
00845     
00846     //delete older snapshots
00847     if (delete_older_snapshots("snapshot", scscf_name, S_AUTH, snapshot_version)!=1){
00848         LOG(L_ERR, "ERR:"M_NAME":bin_cache_dump_auth_to_table(): Error while deleting older snapshots from snapshot table\n");
00849         goto error;
00850     }
00851     
00852     //unlock
00853     lock_release(db_lock);
00854     
00855     return 1;
00856 
00857 error:
00858     lock_release(db_lock);//unlock
00859     return 0;
00860 }

int delete_older_snapshots ( char *  table,
char *  node_id,
data_type_t  dt,
int  current_snapshot 
)

Drops older auth/dialogs/registrar snapshots, keeping the 'bin_db_keep_count' most recent.

Parameters:
table - where to drop.
node_id - cscf id
dt - which data to drop
current_snapshot_version - version of the current snapshot
Returns:
1 on success or 0 on failure

int s_load ( bin_data x,
char *  location,
char *  prepend_fname,
data_type_t  dt 
)

Loads S-CSCF data from files or DB.

Parameters:
x - destination of the loaded data. Empty if scscf_persistency_mode==WITH_DATABASE_CACHE. In this case, each row of the table is loaded and placed on the hashtable now, instead of to be passed to load_snapshot_...() function, which does this work when the whole hashtable was dumped to only one row of the table.
location -
prepend_fname -
dt - load registrar, dialogs or auth
Returns:
1 on success or 0 on failure

Definition at line 928 of file s_persistency.c.

References bin_load_from_db(), bin_load_from_file(), M_NAME, NO_PERSISTENCY, NULL, scscf_persistency_mode, WITH_DATABASE_BULK, WITH_DATABASE_CACHE, and WITH_FILES.

Referenced by load_snapshot_authdata(), load_snapshot_dialogs(), and load_snapshot_registrar().

00928                                                                             {
00929     switch (scscf_persistency_mode){
00930         case NO_PERSISTENCY:
00931             LOG(L_ERR,"ERR:"M_NAME":s_load: Persistency support was disabled\n");
00932             return 0;
00933         case WITH_FILES:
00934             return bin_load_from_file(x,location,prepend_fname);        
00935         case WITH_DATABASE_BULK:
00936             return bin_load_from_db(x, dt);
00937         case WITH_DATABASE_CACHE:
00938             return bin_load_from_db(NULL, dt); //ignore x, x is empty
00939         default:
00940             LOG(L_ERR,"ERR:"M_NAME":s_load: Can't resume because no such mode %d\n",scscf_persistency_mode);
00941             return 0;
00942     }
00943 }

int bin_load_from_db ( bin_data x,
data_type_t  dt 
)

Loads S-CSCF data from DB.

Parameters:
x - Destination of the data.
dt - load registrar, dialogs or auth
Returns:
1 on success or 0 on failure

int bin_load_registrar_from_table ( bin_data x  ) 

Loads S-CSCF registrar from DB.

Parameters:
x - Destination of the data
Returns:
1 on success or 0 on failure

int bin_load_dialogs_from_table ( bin_data x  ) 

Loads S-CSCF dialogs from DB.

Parameters:
x - Destination of the data
Returns:
1 on success or 0 on failure

int bin_load_auth_from_table ( bin_data x  ) 

Loads S-CSCF auth data from DB.

Parameters:
x - Destination of the data
Returns:
1 on success or 0 on failure

Definition at line 998 of file s_persistency.c.

References bin_bulk_load_from_table(), bin_cache_load_auth_from_table(), and S_AUTH.

00998                                          {
00999     if(x){//whole hashtable dumped to db
01000         return bin_bulk_load_from_table(S_AUTH, x);
01001     }
01002     else{//each hashtable element dumped to DB separately
01003         return bin_cache_load_auth_from_table();
01004     }
01005 }

int bin_bulk_load_from_table ( data_type_t  dt,
bin_data x 
)

Loads S-CSCF data from the snapshot table.

Parameters:
dt - load registrar, dialogs or auth
x - where to load
Returns:
1 on success or 0 on failure

int bin_cache_load_registrar_from_table (  ) 

Loads S-CSCF registrar from the snapshot table.

Each r_public is placed on the registrar hastable here.

Returns:
1 on success or 0 on failure

int bin_cache_load_dialogs_from_table (  ) 

Loads S-CSCF dialogs from the snapshot table.

Each dialog is placed on the dialogs hastable here.

Returns:
1 on success or 0 on failure

int bin_cache_load_auth_from_table (  ) 

Loads S-CSCF auth data from the snapshot table.

Each auth_userdata is placed on the auth_data hastable here.

Returns:
1 on success or 0 on failure

Definition at line 1320 of file s_persistency.c.

References auth_data, auth_data_lock(), auth_data_unlock(), bin_alloc(), bin_decode_auth_userdata(), bin_free(), db_get_last_snapshot_version(), db_lock, _auth_userdata::hash, auth_hash_slot_t::head, _bin_data::len, M_NAME, _bin_data::max, _auth_userdata::next, NULL, _auth_userdata::prev, _auth_userdata::private_identity, _bin_data::s, S_AUTH, scscf_db, scscf_dbf, scscf_name, set_versions(), and auth_hash_slot_t::tail.

Referenced by bin_load_auth_from_table().

01320                                     {
01321     int snapshot_version;
01322     int r, len, i=0;
01323     bin_data x;
01324     auth_userdata *aud;
01325     
01326     //lock
01327     lock_get(db_lock);
01328     
01329     if((r=db_get_last_snapshot_version("snapshot", scscf_name, S_AUTH, &snapshot_version))==0){
01330         LOG(L_ERR,"ERR:"M_NAME":bin_cache_load_auth_from_table: Error while getting snapshot version\n");
01331         goto error;
01332     }
01333     else if(r==-1){//empty table, nothing to load
01334             LOG(L_INFO,"INFO:"M_NAME":bin_cache_load_auth_from_table: snapshot table empty\n");
01335             lock_release(db_lock);//unlock
01336             return 1;
01337         }
01338         
01339     //set snapshot/step versions
01340     set_versions(S_AUTH, snapshot_version+1, 0);
01341         
01342     db_key_t keys[3];
01343     db_val_t vals[3];
01344     db_op_t ops[3];
01345     db_key_t result_cols[1];
01346     
01347     db_res_t *res = NULL;
01348     
01349     keys[0] = "node_id";
01350     keys[1] = "data_type";
01351     keys[2] = "snapshot_version";
01352     
01353     ops[0] = OP_EQ;
01354     ops[1] = OP_EQ;
01355     ops[2] = OP_EQ;
01356 
01357     vals[0].type = DB_STR;
01358     vals[0].nul = 0;
01359     vals[0].val.str_val.s = scscf_name;
01360     len = strlen(scscf_name);
01361     vals[0].val.str_val.len = MIN(len, 256);
01362     
01363     vals[1].type = DB_INT;
01364     vals[1].nul = 0;
01365     vals[1].val.int_val = S_AUTH;
01366 
01367     vals[2].type = DB_INT;
01368     vals[2].nul = 0;
01369     vals[2].val.int_val = snapshot_version;
01370     
01371     result_cols[0]="data";
01372     
01373     if (scscf_dbf.use_table(scscf_db, "snapshot") < 0) {
01374         LOG(L_ERR, "ERR:"M_NAME":bin_cache_load_auth_from_table(): Error in use_table\n");
01375         goto error;
01376     }
01377     
01378     if (scscf_dbf.query(scscf_db, keys, ops, vals, result_cols, 3, 1, 0, &res) < 0) {
01379         LOG(L_ERR, "ERR:"M_NAME":bin_cache_load_auth_from_table(): Error while querying snapshot table\n");
01380         goto error;
01381     }
01382     
01383     if (!res) goto error;
01384     
01385     for(i=0;i<res->n;i++){
01386         db_row_t *row = &res->rows[i];
01387         db_val_t *row_vals = ROW_VALUES(row);
01388         
01389         len = row_vals[0].val.blob_val.len;
01390         bin_alloc(&x,len);
01391         memcpy(x.s, row_vals[0].val.blob_val.s, len);
01392         x.len=len;
01393         x.max=0;
01394         aud = bin_decode_auth_userdata(&x);
01395         if (!aud){
01396             scscf_dbf.free_result(scscf_db, res);
01397             goto error;
01398         };
01399         LOG(L_INFO,"INFO:"M_NAME":bin_cache_load_auth_from_table(): Loaded auth_userdata for <%.*s>\n",aud->private_identity.len,aud->private_identity.s);
01400         auth_data_lock(aud->hash);
01401         aud->prev = auth_data[aud->hash].tail;
01402         aud->next = 0;
01403         if (auth_data[aud->hash].tail) auth_data[aud->hash].tail->next = aud;
01404         auth_data[aud->hash].tail = aud;
01405         if (!auth_data[aud->hash].head) auth_data[aud->hash].head = aud;
01406         auth_data_unlock(aud->hash);
01407         bin_free(&x);
01408     }
01409     
01410     scscf_dbf.free_result(scscf_db, res);
01411     lock_release(db_lock);//unlock
01412     return 1;
01413     
01414 error:
01415     lock_release(db_lock);//unlock
01416     return 0;
01417 }

int db_get_last_snapshot_version ( char *  table,
char *  node_id,
data_type_t  dt,
int *  version 
)

Gets the version of the last snapshot dumped to db.

Used to load information from db on startup.

Parameters:
table - the table to query
node_id - cscf id
dt - registrar, dialogs or auth
version - where to load
Returns:
1 on success, -1 if empty table, 0 on error

int set_versions ( data_type_t  dt,
int  snapshot_version,
int  step_version 
)

Sets the values of the global variables registrar/dialogs/auth_snapshot_version and registrar/dialogs/auth_step_version.

Parameters:
dt - auth, dialogs or registrar
snapshot_version - it must continue from the last snapshot version + 1
step_version - it must continue from the last step version + 1
Returns:
1 on success, 0 on error

int make_snapshot_authdata (  ) 

Creates a snapshots of the authorization data and then calls the dumping function.

Returns:
1 on success or 0 on failure

Definition at line 112 of file s_persistency.c.

References auth_data, auth_data_hash_size, auth_data_lock(), auth_data_unlock(), bin_alloc(), bin_encode_auth_userdata(), bin_free(), auth_hash_slot_t::head, _auth_userdata::next, S_AUTH, s_dump(), scscf_persistency_location, scscf_persistency_mode, and WITH_DATABASE_CACHE.

Referenced by mod_destroy(), and persistency_timer_authdata().

00113 {
00114     bin_data x;
00115     auth_userdata *aud;
00116     int i;
00117     
00118     /*In WITH_DATABASE_CACHE mode, serialize each hashtable element separately */
00119     if(scscf_persistency_mode!=WITH_DATABASE_CACHE){    
00120         if (!bin_alloc(&x,256)) goto error;
00121         for(i=0;i<auth_data_hash_size;i++){
00122             auth_data_lock(i);
00123             aud = auth_data[i].head;
00124             while(aud){
00125                 if (!bin_encode_auth_userdata(&x,aud)) goto error;
00126                 aud = aud->next;
00127             }
00128             auth_data_unlock(i);
00129         }
00130         //bin_print(&x);
00131     }
00132     i=s_dump(&x,scscf_persistency_location,"authdata", S_AUTH);
00133     //i = bin_dump(&x,scscf_persistency_mode,scscf_persistency_location,"authdata");        
00134     if(scscf_persistency_mode!=WITH_DATABASE_CACHE){
00135         bin_free(&x);
00136     }
00137     return i;
00138 error:
00139     return 0;
00140 }

int load_snapshot_authdata (  ) 

Loads the authorization data from the last snapshot.

Returns:
1 on success or 0 on failure

Definition at line 147 of file s_persistency.c.

References auth_data, auth_data_lock(), auth_data_unlock(), bin_decode_auth_userdata(), bin_free(), _auth_userdata::hash, auth_hash_slot_t::head, _bin_data::len, M_NAME, _bin_data::max, _auth_userdata::next, _auth_userdata::prev, _auth_userdata::private_identity, S_AUTH, s_load(), scscf_persistency_location, scscf_persistency_mode, auth_hash_slot_t::tail, and WITH_DATABASE_CACHE.

Referenced by mod_init().

00148 {
00149     bin_data x;
00150     auth_userdata *aud;
00151     if (!s_load(&x,scscf_persistency_location,"authdata", S_AUTH)) goto error;
00152     //if (!bin_load(&x,scscf_persistency_mode,scscf_persistency_location,"authdata")) goto error;
00153     
00154     if(scscf_persistency_mode!=WITH_DATABASE_CACHE){
00155         //bin_print(&x);
00156         x.max=0;
00157         LOG(L_INFO,"INFO:"M_NAME":load_snapshot_auth: max %d len %d\n",x.max,x.len);
00158         while(x.max<x.len){
00159             aud = bin_decode_auth_userdata(&x);     
00160             if (!aud) return 0;
00161             LOG(L_INFO,"INFO:"M_NAME":load_snapshot_auth: Loaded auth_userdata for <%.*s>\n",aud->private_identity.len,aud->private_identity.s);
00162             auth_data_lock(aud->hash);
00163             aud->prev = auth_data[aud->hash].tail;
00164             aud->next = 0;
00165             if (auth_data[aud->hash].tail) auth_data[aud->hash].tail->next = aud;
00166             auth_data[aud->hash].tail = aud;
00167             if (!auth_data[aud->hash].head) auth_data[aud->hash].head = aud;
00168             auth_data_unlock(aud->hash);
00169         }
00170         bin_free(&x);
00171     }
00172     return 1;
00173 error:
00174     return 0;
00175 }

void persistency_timer_authdata ( unsigned int  ticks,
void *  param 
)

Timer callback for persistency dumps.

Parameters:
ticks - what's the time
param - a given parameter to be called with

Definition at line 182 of file s_persistency.c.

References auth_snapshot_version, and make_snapshot_authdata().

Referenced by mod_init().

00183 {
00184     make_snapshot_authdata();
00185     
00186     if (auth_snapshot_version) (*auth_snapshot_version)++;  
00187 }

int make_snapshot_dialogs (  ) 

Creates a snapshots of the dialogs data and then calls the dumping function.

Returns:
1 on success or 0 on failure

Definition at line 195 of file s_persistency.c.

References bin_alloc(), bin_encode_p_dialog(), bin_encode_s_dialog(), bin_free(), d_lock(), d_unlock(), p_dialog_hash_slot::head, s_dialog_hash_slot::head, _p_dialog::next, _s_dialog::next, p_dialogs, P_DIALOGS, p_dialogs_hash_size, p_dump(), pcscf_persistency_location, pcscf_persistency_mode, S_DIALOGS, s_dialogs, s_dialogs_hash_size, s_dump(), scscf_persistency_location, scscf_persistency_mode, and WITH_DATABASE_CACHE.

00196 {
00197     bin_data x;
00198     s_dialog *d;
00199     int i;  
00200     
00201     /*In WITH_DATABASE_CACHE mode, serialize each hashtable element separately */
00202     if(scscf_persistency_mode!=WITH_DATABASE_CACHE){
00203         if (!bin_alloc(&x,256)) goto error;     
00204         for(i=0;i<s_dialogs_hash_size;i++){
00205             d_lock(i);
00206             d = s_dialogs[i].head;
00207             while(d){
00208                 if (!bin_encode_s_dialog(&x,d)) goto error;
00209                 d = d->next;
00210             }
00211             d_unlock(i);
00212         }
00213         //bin_print(&x);
00214     }
00215     i=s_dump(&x,scscf_persistency_location,"sdialogs",S_DIALOGS);
00216     //i = bin_dump(&x,scscf_persistency_mode,scscf_persistency_location,"sdialogs");        
00217     if(scscf_persistency_mode!=WITH_DATABASE_CACHE){
00218         bin_free(&x);
00219     }
00220     return i;
00221 error:
00222     return 0;
00223 }  

int load_snapshot_dialogs (  ) 

Loads the dialogs data from the last snapshot.

Returns:
1 on success or 0 on failure

Definition at line 229 of file s_persistency.c.

References _s_dialog::aor, bin_decode_p_dialog(), bin_decode_s_dialog(), bin_free(), d_lock(), d_unlock(), _p_dialog::hash, _s_dialog::hash, p_dialog_hash_slot::head, s_dialog_hash_slot::head, _p_dialog::host, _bin_data::len, M_NAME, _bin_data::max, _p_dialog::next, _s_dialog::next, P_DIALOGS, p_dialogs, p_load(), pcscf_persistency_location, pcscf_persistency_mode, _p_dialog::prev, _s_dialog::prev, s_dialogs, S_DIALOGS, s_load(), scscf_persistency_location, scscf_persistency_mode, p_dialog_hash_slot::tail, s_dialog_hash_slot::tail, and WITH_DATABASE_CACHE.

00230 {
00231     bin_data x;
00232     s_dialog *d;
00233     if (!s_load(&x,scscf_persistency_location,"sdialogs",S_DIALOGS)) goto error;
00234     //if (!bin_load(&x,scscf_persistency_mode,scscf_persistency_location,"sdialogs")) goto error;
00235     
00236     if(scscf_persistency_mode!=WITH_DATABASE_CACHE){
00237         //bin_print(&x);
00238         x.max=0;
00239         LOG(L_INFO,"INFO:"M_NAME":load_snapshot_dlg: max %d len %d\n",x.max,x.len);
00240         while(x.max<x.len){
00241             d = bin_decode_s_dialog(&x);
00242             if (!d) return 0;
00243             LOG(L_INFO,"INFO:"M_NAME":load_snapshot_dlg: Loaded s_dialog for <%.*s>\n",d->aor.len,d->aor.s);
00244             d_lock(d->hash);
00245             d->