build MESSAGE headers * * Add Content-Type, Contact and Date headers if they exist * expects - max buf len of the resulted body in body->len * - body->s MUST be allocated * return: 0 OK ; -1 error * */
| 190 | * return: 0 OK ; -1 error |
| 191 | * */ |
| 192 | int m_build_headers(str *buf, str ctype, str contact, time_t date) |
| 193 | { |
| 194 | char *p; |
| 195 | char strDate[48]; |
| 196 | int lenDate = 0; |
| 197 | |
| 198 | if(!buf || !buf->s || buf->len <= 0 || ctype.len < 0 || contact.len < 0 |
| 199 | || buf->len <= ctype.len+contact.len+14 /*Content-Type: */ |
| 200 | +CRLF_LEN+CONTACT_PREFIX_LEN+CONTACT_SUFFIX_LEN) |
| 201 | goto error; |
| 202 | |
| 203 | p = buf->s; |
| 204 | if(date > 0) |
| 205 | { |
| 206 | lenDate = timetToSipDateStr(date,strDate,48); |
| 207 | memcpy(p, strDate, lenDate); |
| 208 | p += lenDate; |
| 209 | } |
| 210 | if(ctype.len > 0) |
| 211 | { |
| 212 | memcpy(p, "Content-Type: ", 14); |
| 213 | p += 14; |
| 214 | memcpy(p, ctype.s, ctype.len); |
| 215 | p += ctype.len; |
| 216 | memcpy(p, CRLF, CRLF_LEN); |
| 217 | p += CRLF_LEN; |
| 218 | |
| 219 | } |
| 220 | if(contact.len > 0) |
| 221 | { |
| 222 | memcpy(p, CONTACT_PREFIX, CONTACT_PREFIX_LEN); |
| 223 | p += CONTACT_PREFIX_LEN; |
| 224 | memcpy(p, contact.s, contact.len); |
| 225 | p += contact.len; |
| 226 | memcpy(p, CONTACT_SUFFIX, CONTACT_SUFFIX_LEN); |
| 227 | p += CONTACT_SUFFIX_LEN; |
| 228 | } |
| 229 | buf->len = p - buf->s; |
| 230 | return 0; |
| 231 | error: |
| 232 | return -1; |
| 233 | } |
| 234 | |
| 235 | /** build MESSAGE body --- add incoming time and 'from' |
| 236 | * |
no test coverage detected