TESTED */
| 65 | |
| 66 | /* TESTED */ |
| 67 | int |
| 68 | patch_content_length (struct sip_msg *msg, unsigned int newValue) |
| 69 | { |
| 70 | |
| 71 | struct hdr_field *contentLength; |
| 72 | char *s, pos[11]; |
| 73 | int len; |
| 74 | |
| 75 | contentLength = msg->content_length; |
| 76 | if (contentLength == NULL) /* maybe not yet parsed */ |
| 77 | { |
| 78 | if (parse_headers (msg, HDR_CONTENTLENGTH_F, 0) == -1) |
| 79 | { |
| 80 | LM_ERR("parse headers on Content-Length failed\n"); |
| 81 | return -1; |
| 82 | } |
| 83 | contentLength = msg->content_length; |
| 84 | if (contentLength == NULL) |
| 85 | { |
| 86 | LM_ERR("failed to parse headers on Content-Length " |
| 87 | "succeeded but msg->content_length is still NULL\n"); |
| 88 | return -2; |
| 89 | } |
| 90 | } |
| 91 | /* perhaps dangerous because buffer is static ? */ |
| 92 | //pos = int2str(newValue,&len); |
| 93 | len = snprintf ((char *) pos, 10, "%u", newValue); |
| 94 | s = pkg_malloc (len); |
| 95 | if (s == NULL) |
| 96 | { |
| 97 | LM_ERR("unable to allocate %d bytes in pkg mem\n", len); |
| 98 | return -3; |
| 99 | } |
| 100 | memcpy (s, pos, len); |
| 101 | /* perhaps we made it and no one called int2str,might use sprintf */ |
| 102 | if (patch |
| 103 | (msg, contentLength->body.s, contentLength->body.len, s, len) < 0) |
| 104 | { |
| 105 | pkg_free (s); |
| 106 | LM_ERR("lumping failed\n"); |
| 107 | return -4; |
| 108 | } |
| 109 | |
| 110 | LM_DBG ("succeeded in altering Content-Length to new value %u\n",newValue); |
| 111 | |
| 112 | return 0; |
| 113 | |
| 114 | } |
no test coverage detected