| 793 | } |
| 794 | |
| 795 | static int w_send(struct sip_msg *msg, struct proxy_l *dest, str *headers) |
| 796 | { |
| 797 | int ret; |
| 798 | union sockaddr_union* to; |
| 799 | struct proxy_l* p; |
| 800 | int len; |
| 801 | char* tmp; |
| 802 | |
| 803 | to=(union sockaddr_union*) |
| 804 | pkg_malloc(sizeof(union sockaddr_union)); |
| 805 | if (to==0){ |
| 806 | LM_ERR("memory allocation failure\n"); |
| 807 | return E_OUT_OF_MEM; |
| 808 | } |
| 809 | if (0==(p=clone_proxy(dest))) { |
| 810 | LM_ERR("failed to clone proxy, dropping packet\n"); |
| 811 | return E_OUT_OF_MEM; |
| 812 | } |
| 813 | ret=hostent2su(to, &p->host, p->addr_idx, |
| 814 | (p->port)?p->port:SIP_PORT ); |
| 815 | if (ret==0){ |
| 816 | if (headers) { |
| 817 | /* build new msg */ |
| 818 | tmp = pkg_malloc(msg->len + headers->len); |
| 819 | if (!tmp) { |
| 820 | LM_ERR("memory allocation failure\n"); |
| 821 | return E_OUT_OF_MEM; |
| 822 | } |
| 823 | LM_DBG("searching for first line %d\n", |
| 824 | msg->first_line.len); |
| 825 | /* search first line of previous msg */ |
| 826 | /* copy headers */ |
| 827 | len = msg->first_line.len; |
| 828 | memcpy(tmp, msg->buf, len); |
| 829 | memcpy(tmp + len, headers->s, headers->len); |
| 830 | memcpy(tmp + len + headers->len, |
| 831 | msg->buf + len, msg->len - len); |
| 832 | ret = msg_send(0/*send_sock*/, p->proto, to, 0/*id*/, |
| 833 | tmp, msg->len + headers->len, msg); |
| 834 | pkg_free(tmp); |
| 835 | } else { |
| 836 | ret = msg_send(0/*send_sock*/, p->proto, to, 0/*id*/, |
| 837 | msg->buf, msg->len, msg); |
| 838 | } |
| 839 | if (ret!=0 && p->host.h_addr_list[p->addr_idx+1]) |
| 840 | p->addr_idx++; |
| 841 | } |
| 842 | |
| 843 | free_proxy(p); /* frees only p content, not p itself */ |
| 844 | pkg_free(p); |
| 845 | pkg_free(to); |
| 846 | |
| 847 | if (ret==0) |
| 848 | ret=1; |
| 849 | return ret; |
| 850 | } |
| 851 | |
| 852 | static int w_setflag(struct sip_msg *msg, void *flag) |
nothing calls this directly
no test coverage detected