comparison libfreeDiameter/messages.c @ 280:3019f6220122

Provide more useful debug information for non-ABNF-compliant messages
author Sebastien Decugis <sdecugis@nict.go.jp>
date Tue, 27 Apr 2010 10:44:43 +0900
parents 5df55136361b
children 2d3a799ad29c
comparison
equal deleted inserted replaced
279:a26655da5c14 280:3019f6220122
1870 /* Check that a list of AVPs is compliant with a given rule -- will be iterated on the list of rules */ 1870 /* Check that a list of AVPs is compliant with a given rule -- will be iterated on the list of rules */
1871 static int parserules_check_one_rule(void * data, struct dict_rule_data *rule) 1871 static int parserules_check_one_rule(void * data, struct dict_rule_data *rule)
1872 { 1872 {
1873 int count, first, last, min; 1873 int count, first, last, min;
1874 struct parserules_data * pr_data = data; 1874 struct parserules_data * pr_data = data;
1875 char * avp_name = "<unresolved name>";
1875 1876
1876 TRACE_ENTRY("%p %p", data, rule); 1877 TRACE_ENTRY("%p %p", data, rule);
1877 1878
1878 /* Get statistics of the AVP concerned by this rule in the parent instance */ 1879 /* Get statistics of the AVP concerned by this rule in the parent instance */
1879 parserules_stat_avps( rule->rule_avp, pr_data->sentinel, &count, &first, &last); 1880 parserules_stat_avps( rule->rule_avp, pr_data->sentinel, &count, &first, &last);
1880 1881
1881 if (TRACE_BOOL(ANNOYING)) 1882 if (TRACE_BOOL(INFO))
1882 { 1883 {
1883 struct dict_avp_data avpdata; 1884 struct dict_avp_data avpdata;
1884 int ret; 1885 int ret;
1885 ret = fd_dict_getval(rule->rule_avp, &avpdata); 1886 ret = fd_dict_getval(rule->rule_avp, &avpdata);
1887 if (ret == 0)
1888 avp_name = avpdata.avp_name;
1886 1889
1887 TRACE_DEBUG(ANNOYING, "Checking rule: p:%d(%d) m/M:%2d/%2d. Counted %d (first: %d, last:%d) of AVP '%s'", 1890 TRACE_DEBUG(ANNOYING, "Checking rule: p:%d(%d) m/M:%2d/%2d. Counted %d (first: %d, last:%d) of AVP '%s'",
1888 rule->rule_position, 1891 rule->rule_position,
1889 rule->rule_order, 1892 rule->rule_order,
1890 rule->rule_min, 1893 rule->rule_min,
1891 rule->rule_max, 1894 rule->rule_max,
1892 count, 1895 count,
1893 first, 1896 first,
1894 last, 1897 last,
1895 (ret == 0) ? avpdata.avp_name : "???" 1898 avp_name
1896 ); 1899 );
1897 } 1900 }
1898 1901
1899 /* Now check the rule is not conflicting */ 1902 /* Now check the rule is not conflicting */
1900 1903
1904 min = 0; 1907 min = 0;
1905 else 1908 else
1906 min = 1; 1909 min = 1;
1907 } 1910 }
1908 if (count < min) { 1911 if (count < min) {
1909 TRACE_DEBUG(INFO, "Conflicting rule: the number of occurences (%d) is < the rule min (%d).", count, min); 1912 TRACE_DEBUG(INFO, "Conflicting rule: the number of occurences (%d) is < the rule min (%d) for '%s'.", count, min, avp_name);
1910 if (pr_data->pei) { 1913 if (pr_data->pei) {
1911 pr_data->pei->pei_errcode = "DIAMETER_MISSING_AVP"; 1914 pr_data->pei->pei_errcode = "DIAMETER_MISSING_AVP";
1912 pr_data->pei->pei_avp = empty_avp(rule->rule_avp); 1915 pr_data->pei->pei_avp = empty_avp(rule->rule_avp);
1913 } 1916 }
1914 return EBADMSG; 1917 return EBADMSG;
1915 } 1918 }
1916 1919
1917 /* Check the "max" value */ 1920 /* Check the "max" value */
1918 if ((rule->rule_max != -1) && (count > rule->rule_max)) { 1921 if ((rule->rule_max != -1) && (count > rule->rule_max)) {
1919 TRACE_DEBUG(INFO, "Conflicting rule: the number of occurences (%d) is > the rule max (%d).", count, rule->rule_max); 1922 TRACE_DEBUG(INFO, "Conflicting rule: the number of occurences (%d) is > the rule max (%d) for '%s'.", count, rule->rule_max, avp_name);
1920 if (pr_data->pei) { 1923 if (pr_data->pei) {
1921 if (rule->rule_max == 0) 1924 if (rule->rule_max == 0)
1922 pr_data->pei->pei_errcode = "DIAMETER_AVP_NOT_ALLOWED"; 1925 pr_data->pei->pei_errcode = "DIAMETER_AVP_NOT_ALLOWED";
1923 else 1926 else
1924 pr_data->pei->pei_errcode = "DIAMETER_AVP_OCCURS_TOO_MANY_TIMES"; 1927 pr_data->pei->pei_errcode = "DIAMETER_AVP_OCCURS_TOO_MANY_TIMES";
1935 break; 1938 break;
1936 1939
1937 case RULE_FIXED_HEAD: 1940 case RULE_FIXED_HEAD:
1938 /* Since "0*1<fixed>" is a valid rule specifier, we only reject cases where the AVP appears *after* its fixed position */ 1941 /* Since "0*1<fixed>" is a valid rule specifier, we only reject cases where the AVP appears *after* its fixed position */
1939 if (first > rule->rule_order) { 1942 if (first > rule->rule_order) {
1940 TRACE_DEBUG(INFO, "Conflicting rule: the FIXED_HEAD AVP appears first in (%d) position, the rule requires (%d).", first, rule->rule_order); 1943 TRACE_DEBUG(INFO, "Conflicting rule: the FIXED_HEAD AVP appears first in (%d) position, the rule requires (%d) for '%s'.", first, rule->rule_order, avp_name);
1941 if (pr_data->pei) { 1944 if (pr_data->pei) {
1942 pr_data->pei->pei_errcode = "DIAMETER_MISSING_AVP"; 1945 pr_data->pei->pei_errcode = "DIAMETER_MISSING_AVP";
1943 pr_data->pei->pei_message = "AVP was not in its fixed position"; 1946 pr_data->pei->pei_message = "AVP was not in its fixed position";
1944 pr_data->pei->pei_avp = empty_avp(rule->rule_avp); 1947 pr_data->pei->pei_avp = empty_avp(rule->rule_avp);
1945 } 1948 }
1948 break; 1951 break;
1949 1952
1950 case RULE_FIXED_TAIL: 1953 case RULE_FIXED_TAIL:
1951 /* Since "0*1<fixed>" is a valid rule specifier, we only reject cases where the AVP appears *before* its fixed position */ 1954 /* Since "0*1<fixed>" is a valid rule specifier, we only reject cases where the AVP appears *before* its fixed position */
1952 if (last > rule->rule_order) { /* We have a ">" here because we count in reverse order (i.e. from the end) */ 1955 if (last > rule->rule_order) { /* We have a ">" here because we count in reverse order (i.e. from the end) */
1953 TRACE_DEBUG(INFO, "Conflicting rule: the FIXED_TAIL AVP appears last in (%d) position, the rule requires (%d).", last, rule->rule_order); 1956 TRACE_DEBUG(INFO, "Conflicting rule: the FIXED_TAIL AVP appears last in (%d) position, the rule requires (%d) for '%s'.", last, rule->rule_order, avp_name);
1954 if (pr_data->pei) { 1957 if (pr_data->pei) {
1955 pr_data->pei->pei_errcode = "DIAMETER_MISSING_AVP"; 1958 pr_data->pei->pei_errcode = "DIAMETER_MISSING_AVP";
1956 pr_data->pei->pei_message = "AVP was not in its fixed position"; 1959 pr_data->pei->pei_message = "AVP was not in its fixed position";
1957 pr_data->pei->pei_avp = empty_avp(rule->rule_avp); 1960 pr_data->pei->pei_avp = empty_avp(rule->rule_avp);
1958 } 1961 }
"Welcome to our mercurial repository"