comparison libfdproto/dictionary.c @ 769:99136ec7d9d4

Fixed fd_dict_getlistof function, added a simple test
author Sebastien Decugis <sdecugis@nict.go.jp>
date Tue, 25 Oct 2011 21:48:52 +0200
parents f53e5b5fdfd3
children 27fef2ca2cf6
comparison
equal deleted inserted replaced
768:a5a82d50c25e 769:99136ec7d9d4
1838 1838
1839 /* Function to retrieve list of objects in the dictionary. Use with care (read only). 1839 /* Function to retrieve list of objects in the dictionary. Use with care (read only).
1840 1840
1841 All returned list must be accessed like this: 1841 All returned list must be accessed like this:
1842 1842
1843 for (li = sentinel->next; li=li->next; li != sentinel) { 1843 for (li = sentinel->next; li != sentinel; li=li->next) {
1844 struct dict_object * obj = li->o; 1844 struct dict_object * obj = li->o;
1845 ... 1845 ...
1846 } 1846 }
1847 1847
1848 The following criteria are allowed, with corresponding parent. 1848 The following criteria are allowed, with corresponding parent.
1851 VENDOR_BY_ID : (parent = dictionary) returns list of vendors ordered by ID 1851 VENDOR_BY_ID : (parent = dictionary) returns list of vendors ordered by ID
1852 APPLICATION_BY_ID : (parent = dictionary) returns list of applications ordered by ID 1852 APPLICATION_BY_ID : (parent = dictionary) returns list of applications ordered by ID
1853 ** for these two lists, the Vendor with id 0 and applciation with id 0 are excluded. 1853 ** for these two lists, the Vendor with id 0 and applciation with id 0 are excluded.
1854 You must resolve them separatly with dict_search. 1854 You must resolve them separatly with dict_search.
1855 1855
1856 TYPE_BY_NAME : (parent = dictionary) returns list of types ordered by name 1856 TYPE_BY_NAME : (parent = dictionary) returns list of types ordered by name (osstring order)
1857 ENUMVAL_BY_NAME : (parent = type object) return list of constants for this type ordered by name 1857 ENUMVAL_BY_NAME : (parent = type object) return list of constants for this type ordered by name (osstring order)
1858 ENUMVAL_BY_VALUE : (parent = type object) return list of constants for this type ordered by values 1858 ENUMVAL_BY_VALUE : (parent = type object) return list of constants for this type ordered by values
1859 AVP_BY_NAME : (parent = vendor object) return list of AVP for this vendor ordered by name 1859 AVP_BY_NAME : (parent = vendor object) return list of AVP for this vendor ordered by name (osstring order)
1860 AVP_BY_CODE : (parent = vendor object) return list of AVP for this vendor ordered by code 1860 AVP_BY_CODE : (parent = vendor object) return list of AVP for this vendor ordered by code
1861 CMD_BY_NAME : (parent = dictionary) returns list of commands ordered by name 1861 CMD_BY_NAME : (parent = dictionary) returns list of commands ordered by name (osstring order)
1862 CMD_BY_CODE_R : (parent = dictionary) returns list of commands ordered by code 1862 CMD_BY_CODE_R : (parent = dictionary) returns list of commands ordered by code
1863 RULE_BY_AVP_AND_PARENT: (parent = command or grouped AVP object) return list of rules for this object ordered by AVP vendor/code 1863 RULE_BY_AVP_AND_PARENT: (parent = command or grouped AVP object) return list of rules for this object ordered by AVP vendor/code
1864 1864
1865 All other criteria are rejected. 1865 All other criteria are rejected.
1866 */ 1866 */
1867 int fd_dict_getlistof(int criteria, void * parent, struct fd_list * sentinel) 1867 int fd_dict_getlistof(int criteria, void * parent, struct fd_list ** sentinel)
1868 { 1868 {
1869 struct dictionary * dict = parent; 1869 struct dictionary * dict = parent;
1870 struct dict_object * obj_parent = parent; 1870 struct dict_object * obj_parent = parent;
1871 1871
1872 TRACE_ENTRY("%i %p %p", criteria, parent, sentinel); 1872 TRACE_ENTRY("%i %p %p", criteria, parent, sentinel);
1874 CHECK_PARAMS(sentinel && parent); 1874 CHECK_PARAMS(sentinel && parent);
1875 1875
1876 switch(criteria) { 1876 switch(criteria) {
1877 case VENDOR_BY_ID: /* parent must be the dictionary */ 1877 case VENDOR_BY_ID: /* parent must be the dictionary */
1878 CHECK_PARAMS(dict->dict_eyec == DICT_EYECATCHER); 1878 CHECK_PARAMS(dict->dict_eyec == DICT_EYECATCHER);
1879 sentinel = &dict->dict_vendors.list[0]; 1879 *sentinel = &dict->dict_vendors.list[0];
1880 break; 1880 break;
1881 1881
1882 case APPLICATION_BY_ID: /* parent must be the dictionary */ 1882 case APPLICATION_BY_ID: /* parent must be the dictionary */
1883 CHECK_PARAMS(dict->dict_eyec == DICT_EYECATCHER); 1883 CHECK_PARAMS(dict->dict_eyec == DICT_EYECATCHER);
1884 sentinel = &dict->dict_applications.list[0]; 1884 *sentinel = &dict->dict_applications.list[0];
1885 break; 1885 break;
1886 1886
1887 case TYPE_BY_NAME: /* parent must be the dictionary */ 1887 case TYPE_BY_NAME: /* parent must be the dictionary */
1888 CHECK_PARAMS(dict->dict_eyec == DICT_EYECATCHER); 1888 CHECK_PARAMS(dict->dict_eyec == DICT_EYECATCHER);
1889 sentinel = &dict->dict_types; 1889 *sentinel = &dict->dict_types;
1890 break; 1890 break;
1891 1891
1892 case ENUMVAL_BY_NAME: /* parent must be a type object */ 1892 case ENUMVAL_BY_NAME: /* parent must be a type object */
1893 CHECK_PARAMS(verify_object(obj_parent) && (obj_parent->type == DICT_TYPE)); 1893 CHECK_PARAMS(verify_object(obj_parent) && (obj_parent->type == DICT_TYPE));
1894 sentinel = &obj_parent->list[1]; 1894 *sentinel = &obj_parent->list[1];
1895 break; 1895 break;
1896 1896
1897 case ENUMVAL_BY_VALUE: /* parent must be a type object */ 1897 case ENUMVAL_BY_VALUE: /* parent must be a type object */
1898 CHECK_PARAMS(verify_object(obj_parent) && (obj_parent->type == DICT_TYPE)); 1898 CHECK_PARAMS(verify_object(obj_parent) && (obj_parent->type == DICT_TYPE));
1899 sentinel = &obj_parent->list[2]; 1899 *sentinel = &obj_parent->list[2];
1900 break; 1900 break;
1901 1901
1902 case AVP_BY_NAME: /* parent must be a AVP object */ 1902 case AVP_BY_NAME: /* parent must be a VENDOR object */
1903 CHECK_PARAMS(verify_object(obj_parent) && (obj_parent->type == DICT_AVP)); 1903 CHECK_PARAMS(verify_object(obj_parent) && (obj_parent->type == DICT_VENDOR));
1904 sentinel = &obj_parent->list[2]; 1904 *sentinel = &obj_parent->list[2];
1905 break; 1905 break;
1906 1906
1907 case AVP_BY_CODE: /* parent must be a AVP object */ 1907 case AVP_BY_CODE: /* parent must be a VENDOR object */
1908 CHECK_PARAMS(verify_object(obj_parent) && (obj_parent->type == DICT_AVP)); 1908 CHECK_PARAMS(verify_object(obj_parent) && (obj_parent->type == DICT_VENDOR));
1909 sentinel = &obj_parent->list[1]; 1909 *sentinel = &obj_parent->list[1];
1910 break; 1910 break;
1911 1911
1912 case CMD_BY_NAME: /* parent must be the dictionary */ 1912 case CMD_BY_NAME: /* parent must be the dictionary */
1913 CHECK_PARAMS(dict->dict_eyec == DICT_EYECATCHER); 1913 CHECK_PARAMS(dict->dict_eyec == DICT_EYECATCHER);
1914 sentinel = &dict->dict_cmd_name; 1914 *sentinel = &dict->dict_cmd_name;
1915 break; 1915 break;
1916 1916
1917 case CMD_BY_CODE_R: /* parent must be the dictionary */ 1917 case CMD_BY_CODE_R: /* parent must be the dictionary */
1918 CHECK_PARAMS(dict->dict_eyec == DICT_EYECATCHER); 1918 CHECK_PARAMS(dict->dict_eyec == DICT_EYECATCHER);
1919 sentinel = &dict->dict_cmd_code; 1919 *sentinel = &dict->dict_cmd_code;
1920 break; 1920 break;
1921 1921
1922 case RULE_BY_AVP_AND_PARENT: /* parent must be command or grouped AVP */ 1922 case RULE_BY_AVP_AND_PARENT: /* parent must be command or grouped AVP */
1923 CHECK_PARAMS(verify_object(obj_parent)); 1923 CHECK_PARAMS(verify_object(obj_parent));
1924 CHECK_PARAMS( (obj_parent->type == DICT_COMMAND) || 1924 CHECK_PARAMS( (obj_parent->type == DICT_COMMAND) ||
1925 ((obj_parent->type == DICT_AVP) 1925 ((obj_parent->type == DICT_AVP)
1926 && (obj_parent->data.avp.avp_basetype == AVP_TYPE_GROUPED)) ); 1926 && (obj_parent->data.avp.avp_basetype == AVP_TYPE_GROUPED)) );
1927 sentinel = &obj_parent->list[2]; 1927 *sentinel = &obj_parent->list[2];
1928 break; 1928 break;
1929 1929
1930 default: 1930 default:
1931 CHECK_PARAMS(0); 1931 CHECK_PARAMS(0);
1932 } 1932 }
"Welcome to our mercurial repository"