Changeset 778:003df4a9ade2 in freeDiameter
- Timestamp:
- Jan 22, 2012, 12:11:34 AM (12 years ago)
- Branch:
- default
- Phase:
- public
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
include/freeDiameter/libfdproto.h
r769 r778 851 851 int fd_dict_getlistof(int criteria, void * parent, struct fd_list ** sentinel); 852 852 853 /* Function to remove an entry from the dictionary. 854 This cannot be used if the object has children (for example a vendor with vendor-specific AVPs). 855 In such case, the children must be removed first. */ 856 int fd_dict_delete(struct dict_object * obj); 853 857 854 858 /* … … 1860 1864 void fd_sess_dump_hdl(int level, struct session_handler * handler); 1861 1865 1866 /* For statistics / monitoring: get the number of struct session in memory */ 1867 int fd_sess_getcount(uint32_t *cnt); 1868 1862 1869 /*============================================================*/ 1863 1870 /* ROUTING */ -
libfdproto/dictionary.c
r770 r778 1812 1812 } 1813 1813 1814 1815 int fd_dict_delete(struct dict_object * obj) 1816 { 1817 int i; 1818 struct dictionary * dict; 1819 int ret=0; 1820 1821 /* check params */ 1822 CHECK_PARAMS( verify_object(obj) && obj->dico); 1823 dict = obj->dico; 1824 1825 /* Lock the dictionary for change */ 1826 CHECK_POSIX( pthread_rwlock_wrlock(&dict->dict_lock) ); 1827 1828 /* check the object is not sentinel for another list */ 1829 for (i=0; i<NB_LISTS_PER_OBJ; i++) { 1830 if (!_OBINFO(obj).haslist[i] && !(FD_IS_LIST_EMPTY(&obj->list[i]))) { 1831 /* There are children, this is not good */ 1832 ret = EINVAL; 1833 TRACE_DEBUG (FULL, "Cannot delete object, list %d not empty:", i); 1834 #if 0 1835 dump_list(&obj->list[i], 0,0,0); 1836 #endif 1837 break; 1838 } 1839 } 1840 1841 /* ok, now destroy the object */ 1842 if (!ret) 1843 destroy_object(obj); 1844 1845 /* Unlock */ 1846 CHECK_POSIX( pthread_rwlock_unlock(&dict->dict_lock) ); 1847 1848 return ret; 1849 } 1850 1851 1814 1852 int fd_dict_search ( struct dictionary * dict, enum dict_object_type type, int criteria, void * what, struct dict_object **result, int retval ) 1815 1853 { -
libfdproto/sessions.c
r740 r778 115 115 #define H_LOCK( _hash ) (&(sess_hash[H_MASK(_hash)].lock )) 116 116 117 static uint32_t sess_cnt = 0; /* counts all active session (that are in the expiry list) */ 118 117 119 /* The following are used to generate sid values that are eternaly unique */ 118 120 static uint32_t sid_h; /* initialized to the current time in fd_sess_init */ … … 485 487 } 486 488 fd_list_insert_after( li, &sess->expire ); 489 sess_cnt++; 487 490 488 491 /* We added a new expiring element, we must signal */ … … 612 615 /* Unlink from the expiry list */ 613 616 CHECK_POSIX_DO( pthread_mutex_lock( &exp_lock ), { ASSERT(0); /* otherwise cleanup handler is not pop'd */ } ); 614 fd_list_unlink( &sess->expire ); /* no need to signal the condition here */ 617 if (!FD_IS_LIST_EMPTY(&sess->expire)) { 618 sess_cnt--; 619 fd_list_unlink( &sess->expire ); /* no need to signal the condition here */ 620 } 615 621 CHECK_POSIX_DO( pthread_mutex_unlock( &exp_lock ), { ASSERT(0); /* otherwise cleanup handler is not pop'd */ } ); 616 622 … … 890 896 fd_log_debug("\t %*s -- end of handler @%p --\n", level, "", handler); 891 897 } 898 899 int fd_sess_getcount(uint32_t *cnt) 900 { 901 CHECK_PARAMS(cnt); 902 CHECK_POSIX( pthread_mutex_lock( &exp_lock ) ); 903 *cnt = sess_cnt; 904 CHECK_POSIX( pthread_mutex_unlock( &exp_lock ) ); 905 return 0; 906 } -
tests/testdict.c
r770 r778 166 166 } 167 167 168 /* Test delete function */ 169 { 170 struct fd_list * li = NULL; 171 struct fd_list * sentinel = NULL; 172 struct dict_object * obj=NULL; 173 vendor_id_t vid = 0; 174 int count = 0, cntbkp; 175 176 CHECK( 0, fd_dict_search(fd_g_config->cnf_dict, DICT_VENDOR, VENDOR_BY_ID, &vid, &obj, ENOENT) ); 177 178 CHECK( EINVAL, fd_dict_delete(obj) ); 179 180 181 CHECK( 0, fd_dict_getlistof(AVP_BY_NAME, obj, &sentinel)); 182 obj = NULL; 183 184 for (li = sentinel->next; li != sentinel; li = li->next) { 185 struct dict_avp_data data; 186 CHECK( 0, fd_dict_getval(li->o, &data) ); 187 count++; 188 if (data.avp_basetype != AVP_TYPE_GROUPED) 189 obj = li->o; 190 } 191 192 CHECK(1, obj ? 1 : 0 ); 193 #if 1 194 fd_dict_dump_object(obj); 195 #endif 196 CHECK( 0, fd_dict_delete(obj) ); 197 cntbkp = count; 198 count = 0; 199 for (li = sentinel->next; li != sentinel; li = li->next) { 200 count++; 201 } 202 CHECK( 1, cntbkp - count ); 203 204 } 205 168 206 /* That's all for the tests yet */ 169 207 PASSTEST(); -
tests/testsess.c
r740 r778 174 174 CHECK( 0, fd_sess_destroy( &sess1 ) ); 175 175 } 176 177 /* Test fd_sess_getcount */ 178 { 179 uint32_t cnt; 180 CHECK( 0, fd_sess_new( &sess1, TEST_DIAM_ID, CONSTSTRLEN(TEST_DIAM_ID), NULL, 0 ) ); 181 CHECK( 0, fd_sess_new( &sess2, TEST_DIAM_ID, CONSTSTRLEN(TEST_DIAM_ID), NULL, 0 ) ); 182 CHECK( 0, fd_sess_getcount(&cnt)); 183 CHECK( 2, cnt); 184 CHECK( 0, fd_sess_destroy( &sess2 ) ); 185 CHECK( 0, fd_sess_getcount(&cnt)); 186 CHECK( 1, cnt); 187 CHECK( 0, fd_sess_destroy( &sess1 ) ); 188 CHECK( 0, fd_sess_getcount(&cnt)); 189 CHECK( 0, cnt); 190 191 } 176 192 177 193 /* Test fd_sess_fromsid */
Note: See TracChangeset
for help on using the changeset viewer.