+#ifdef USE_DNS_FAILOVER
+/* Similar to print_uac_request(), but this function uses the outgoing message buffer of
+ the failed branch to construt the new message in case of DNS failover.
+
+ WARNING: only the first VIA header is replaced in the buffer, the rest
+ of the message is untuched, thus, the send socket is corrected only in the VIA HF.
+*/
+static char *print_uac_request_from_buf( struct cell *t, struct sip_msg *i_req,
+ int branch, str *uri, unsigned int *len, struct dest_info* dst,
+ char *buf, short buf_len)
+{
+ char *shbuf;
+ str branch_str;
+ char *via, *old_via_begin, *old_via_end;
+ unsigned int via_len;
+
+ shbuf=0;
+
+ /* ... we calculate branch ... */
+ if (!t_calc_branch(t, branch, i_req->add_to_branch_s,
+ &i_req->add_to_branch_len ))
+ {
+ LOG(L_ERR, "ERROR: print_uac_request_from_buf: branch computation failed\n");
+ goto error00;
+ }
+ branch_str.s = i_req->add_to_branch_s;
+ branch_str.len = i_req->add_to_branch_len;
+
+ /* find the beginning of the first via header in the buffer */
+ old_via_begin = lw_find_via(buf, buf+buf_len);
+ if (!old_via_begin) {
+ LOG(L_ERR, "ERROR: print_uac_request_from_buf: beginning of via header not found\n");
+ goto error00;
+ }
+ /* find the end of the first via header in the buffer */
+ old_via_end = lw_next_line(old_via_begin, buf+buf_len);
+ if (!old_via_end) {
+ LOG(L_ERR, "ERROR: print_uac_request_from_buf: end of via header not found\n");
+ goto error00;
+ }
+
+ /* create the new VIA HF */
+ via = create_via_hf(&via_len, i_req, dst, &branch_str);
+ if (!via) {
+ LOG(L_ERR, "ERROR: print_uac_request_from_buf: via building failed\n");
+ goto error00;
+ }
+
+ /* allocate memory for the new buffer */
+ *len = buf_len + via_len - (old_via_end - old_via_begin);
+ shbuf=(char *)shm_malloc(*len);
+ if (!shbuf) {
+ ser_error=E_OUT_OF_MEM;
+ LOG(L_ERR, "ERROR: print_uac_request_from_buf: no shmem\n");
+ goto error01;
+ }
+
+ /* construct the new buffer */
+ memcpy(shbuf, buf, old_via_begin-buf);
+ memcpy(shbuf+(old_via_begin-buf), via, via_len);
+ memcpy(shbuf+(old_via_begin-buf)+via_len, old_via_end, (buf+buf_len)-old_via_end);
+
+#ifdef DBG_MSG_QA
+ if (shbuf[*len-1]==0) {
+ LOG(L_ERR, "ERROR: print_uac_request_from_buf: sanity check failed\n");
+ abort();
+ }
+#endif
+
+error01:
+ pkg_free(via);
+error00:
+ return shbuf;
+}
+#endif
+