Mercurial > hg > freeDiameter
comparison libfdproto/messages.c @ 1300:3f1e79e1273e
Added new callbacks in the derived types definitions to improve value checks during message parsing. Thanks Ranjith for the suggestion.
author | Sebastien Decugis <sdecugis@freediameter.net> |
---|---|
date | Sun, 30 Aug 2015 01:11:55 +0800 |
parents | 0f215b0dda5e |
children | 84a3c9c4b834 |
comparison
equal
deleted
inserted
replaced
1299:035f489b845b | 1300:3f1e79e1273e |
---|---|
2034 | 2034 |
2035 /* Process an AVP. If we are not in recheck, the avp_source must be set. */ | 2035 /* Process an AVP. If we are not in recheck, the avp_source must be set. */ |
2036 static int parsedict_do_avp(struct dictionary * dict, struct avp * avp, int mandatory, struct fd_pei *error_info) | 2036 static int parsedict_do_avp(struct dictionary * dict, struct avp * avp, int mandatory, struct fd_pei *error_info) |
2037 { | 2037 { |
2038 struct dict_avp_data dictdata; | 2038 struct dict_avp_data dictdata; |
2039 struct dict_type_data derivedtypedata; | |
2040 struct dict_object * avp_derived_type = NULL; | |
2039 uint8_t * source; | 2041 uint8_t * source; |
2040 | 2042 |
2041 TRACE_ENTRY("%p %p %d %p", dict, avp, mandatory, error_info); | 2043 TRACE_ENTRY("%p %p %d %p", dict, avp, mandatory, error_info); |
2042 | 2044 |
2043 /* First check we received an AVP as input */ | 2045 /* First check we received an AVP as input */ |
2214 memcpy(&__stor, source, sizeof(__stor)); | 2216 memcpy(&__stor, source, sizeof(__stor)); |
2215 avp->avp_storage.u64 = (uint64_t)ntohll(__stor); | 2217 avp->avp_storage.u64 = (uint64_t)ntohll(__stor); |
2216 } | 2218 } |
2217 break; | 2219 break; |
2218 | 2220 |
2221 } | |
2222 | |
2223 /* Is there a derived type check function ? */ | |
2224 CHECK_FCT ( fd_dict_search ( dict, DICT_TYPE, TYPE_OF_AVP, avp->avp_model, &avp_derived_type, 0) ); | |
2225 if (avp_derived_type) { | |
2226 CHECK_FCT( fd_dict_getval(avp_derived_type, &derivedtypedata) ); | |
2227 if (derivedtypedata.type_check != NULL) { | |
2228 char * err; | |
2229 int ret = (*derivedtypedata.type_check)( derivedtypedata.type_check_param, &avp->avp_storage, &err ); | |
2230 | |
2231 if (ret != 0) { | |
2232 TRACE_DEBUG(INFO, "The AVP failed to pass the dictionary validation"); | |
2233 if (error_info) { | |
2234 error_info->pei_errcode = "DIAMETER_INVALID_AVP_VALUE"; | |
2235 error_info->pei_avp = avp; | |
2236 strncpy(error_message, err, sizeof(error_message)); | |
2237 error_info->pei_message = error_message; | |
2238 } else { | |
2239 char * buf = NULL; | |
2240 size_t buflen; | |
2241 CHECK_MALLOC(fd_msg_dump_treeview(&buf, &buflen, NULL, avp, NULL, 0, 0)); | |
2242 LOG_E("Invalid AVP: %s", buf); | |
2243 free(buf); | |
2244 } | |
2245 return ret; /* should we just return EBADMSG? */ | |
2246 } | |
2247 } | |
2219 } | 2248 } |
2220 | 2249 |
2221 /* The value is now set, so set the data pointer and return 0 */ | 2250 /* The value is now set, so set the data pointer and return 0 */ |
2222 avp->avp_public.avp_value = &avp->avp_storage; | 2251 avp->avp_public.avp_value = &avp->avp_storage; |
2223 return 0; | 2252 return 0; |