| 350 | static unsigned char *rdata_buf=NULL; |
| 351 | static int rdata_buf_len=0; |
| 352 | static char* serialize_dns_rdata(struct rdata *head,int buf_len,int *len,int do_encoding) |
| 353 | { |
| 354 | unsigned char *p; |
| 355 | struct rdata *it; |
| 356 | int needed_len; |
| 357 | int entry_len,base64_len=0; |
| 358 | struct cname_rdata *cname_rd; |
| 359 | struct srv_rdata *srv_rd; |
| 360 | struct naptr_rdata *naptr_rd; |
| 361 | struct ebl_rdata *ebl_rd; |
| 362 | struct txt_rdata *txt_rd; |
| 363 | |
| 364 | if (do_encoding) { |
| 365 | base64_len = calc_base64_encode_len(buf_len); |
| 366 | needed_len = buf_len + base64_len; |
| 367 | } else { |
| 368 | needed_len = buf_len; |
| 369 | } |
| 370 | |
| 371 | if (rdata_buf == NULL || needed_len > rdata_buf_len) { |
| 372 | rdata_buf = pkg_realloc(rdata_buf,needed_len); |
| 373 | if (rdata_buf == NULL) { |
| 374 | LM_ERR("No more pkg\n"); |
| 375 | return NULL; |
| 376 | } |
| 377 | rdata_buf_len = needed_len; |
| 378 | } |
| 379 | |
| 380 | p = rdata_buf; |
| 381 | |
| 382 | for (it=head;it;it=it->next) { |
| 383 | /* copy non-pointer fields of the struct */ |
| 384 | memcpy(p,it,rdata_struct_len); |
| 385 | p+=rdata_struct_len; |
| 386 | |
| 387 | switch (it->type) { |
| 388 | case T_A: |
| 389 | /* copy all 4 bytes */ |
| 390 | memcpy(p,it->rdata,sizeof(struct a_rdata)); |
| 391 | p+=sizeof(struct a_rdata); |
| 392 | break; |
| 393 | case T_AAAA: |
| 394 | /* copy all 16 bytes */ |
| 395 | memcpy(p,it->rdata,sizeof(struct aaaa_rdata)); |
| 396 | p+=sizeof(struct aaaa_rdata); |
| 397 | break; |
| 398 | case T_CNAME: |
| 399 | cname_rd=(struct cname_rdata *)it->rdata; |
| 400 | entry_len=strlen(cname_rd->name); |
| 401 | /* copy len of alias */ |
| 402 | memcpy(p,&entry_len,sizeof(int)); |
| 403 | p+=sizeof(int); |
| 404 | /* copy alias */ |
| 405 | memcpy(p,cname_rd->name,entry_len+1); |
| 406 | p+=entry_len+1; |
| 407 | break; |
| 408 | case T_NAPTR: |
| 409 | /* copy priority, etc */ |
no test coverage detected