| 555 | } |
| 556 | |
| 557 | int parse_attr_def(char *line, FILE *fp) |
| 558 | { |
| 559 | struct dm_avp_def avps[128]; |
| 560 | int avp_count = 0; |
| 561 | unsigned int vendor_id = -1; |
| 562 | size_t buflen = strlen(line); |
| 563 | int i, len = buflen, attr_len = strlen("ATTRIBUTE"), name_len, avp_code; |
| 564 | char *name, *nt_name = NULL, *newp, *p = line, *end = p + len; |
| 565 | enum dict_avp_basetype avp_type; |
| 566 | enum dict_avp_enc_type enc_type = AVP_ENC_TYPE_NONE; |
| 567 | |
| 568 | if (len < attr_len || strncasecmp(p, "ATTRIBUTE", attr_len)) |
| 569 | return 1; |
| 570 | |
| 571 | p += attr_len; |
| 572 | len -= attr_len; |
| 573 | |
| 574 | while (isspace(*p)) { p++; len--; } |
| 575 | if (p >= end) |
| 576 | goto error; |
| 577 | |
| 578 | name = p; name_len = 0; |
| 579 | while (!isspace(*p)) { p++; len--; name_len++; } |
| 580 | if (p >= end) |
| 581 | goto error; |
| 582 | |
| 583 | nt_name = malloc(name_len + 1); |
| 584 | if (!nt_name) { |
| 585 | LOG_ERROR("Malloc failed\n"); |
| 586 | return -1; |
| 587 | } |
| 588 | memcpy(nt_name, name, name_len); |
| 589 | nt_name[name_len] = '\0'; |
| 590 | |
| 591 | while (isspace(*p)) { p++; len--; } |
| 592 | if (p >= end) |
| 593 | goto error; |
| 594 | |
| 595 | avp_code = strtol(p, &newp, 10); |
| 596 | if (avp_code == 0) |
| 597 | goto error; |
| 598 | |
| 599 | len -= newp - p; |
| 600 | p = newp; |
| 601 | |
| 602 | while (isspace(*p)) { p++; len--; } |
| 603 | |
| 604 | if (p >= end) { |
| 605 | avp_type = AVP_TYPE_OCTETSTRING; |
| 606 | } else { |
| 607 | if ((len >= strlen("ip") && !strncasecmp(p, STR_L("ip")))) { |
| 608 | avp_type = AVP_TYPE_OCTETSTRING; |
| 609 | enc_type = AVP_ENC_TYPE_IP; |
| 610 | } else if ((len >= strlen("hex") && !strncasecmp(p, STR_L("hex"))) |
| 611 | || (len >= strlen("hexstring") && !strncasecmp(p, STR_L("hexstring")))) { |
| 612 | avp_type = AVP_TYPE_OCTETSTRING; |
| 613 | enc_type = AVP_ENC_TYPE_HEX; |
| 614 | } else if (len >= strlen("time") && !strncasecmp(p, STR_L("time"))) { |
no test coverage detected