43 if (attribute != NULL) { |
43 if (attribute != NULL) { |
44 attribute->name = strdup(name); |
44 attribute->name = strdup(name); |
45 if (attribute->name == NULL) { |
45 if (attribute->name == NULL) { |
46 free(attribute); |
46 free(attribute); |
47 } else { |
47 } else { |
48 attribute->value = strdup(value); |
48 char *begin = value; |
|
49 char *end; |
|
50 |
|
51 /* skip any leading white space */ |
|
52 while (isspace(*begin)) { |
|
53 begin++; |
|
54 } |
|
55 |
|
56 /* skip any trailing white space */ |
|
57 end = &begin[strlen(begin)]; |
|
58 while (end > begin && isspace(end[-1])) { |
|
59 end--; |
|
60 } |
|
61 |
|
62 if (begin == end) { |
|
63 /* no value so skip this attribute */ |
|
64 free(attribute->name); |
|
65 free(attribute); |
|
66 return; |
|
67 } |
|
68 |
|
69 size_t value_len = (size_t)(end - begin); |
|
70 attribute->value = malloc(value_len + 1); |
49 if (attribute->value == NULL) { |
71 if (attribute->value == NULL) { |
50 free(attribute->name); |
72 free(attribute->name); |
51 free(attribute); |
73 free(attribute); |
52 } else { |
74 } else { |
|
75 /* save the value without leading or trailing whitespace */ |
|
76 strncpy(attribute->value, begin, value_len); |
|
77 attribute->value[value_len] = NULL; |
53 attribute->next = NULL; |
78 attribute->next = NULL; |
54 if (context->head == NULL) { |
79 if (context->head == NULL) { |
55 context->head = attribute; |
80 context->head = attribute; |
56 } else { |
81 } else { |
57 context->tail->next = attribute; |
82 context->tail->next = attribute; |