rem: static char *get_hfblock(str *uri, struct hdr_field *hf, int *l)
add: static char *get_hfblock(str *uri, struct hdr_field *hf, int *l, int proto)
context: static char *get_hfblock(str *uri, struct hdr_field *hf, int *l) {	struct str_list sl, *last, *new, *i, *foo;	int hf_avail, frag_len, total_len;	char *begin, *needle, *dst, *ret, *d;	str *sock_name, *portname;	union sockaddr_union to_su;	struct socket_info* send_sock;	ret=0; /* pesimist: assume failure */	total_len=0;	last=&sl;	last->next=0;	portname=sock_name=0;	for (; hf; hf=hf->next) {		if (skip_hf(hf)) continue;		begin=needle=hf->name.s; 		hf_avail=hf->len;		/* substitution loop */		while(hf_avail) {			d=memchr(needle, SUBST_CHAR, hf_avail);			if (!d || d+1>=needle+hf_avail) { /* nothing to substitute */				new=new_str(begin, hf_avail, &last, &total_len); 				if (!new) goto error;				break;			} else {				frag_len=d-begin;				d++; /* d not at the second substitution char */				switch(*d) {					case SUBST_CHAR:	/* double SUBST_CHAR: IP */						/* string before substitute */						new=new_str(begin, frag_len, &last, &total_len); 						if (!new) goto error;						/* substitute */						if (!sock_name) {							send_sock=uri2sock( uri, &to_su );							if (!send_sock) {								LOG(L_ERR, "ERROR: get_hf_block: send_sock failed\n");								goto error;							}							sock_name=&send_sock->address_str;							portname=&send_sock->port_no_str;						}						new=new_str(sock_name->s, sock_name->len,								&last, &total_len );						if (!new) goto error;						new=new_str(portname->s, portname->len,								&last, &total_len );						if (!new) goto error;						/* keep going ... */						begin=needle=d+1;hf_avail-=frag_len+2;						continue;					default:						/* no valid substitution char -- keep going */						hf_avail-=frag_len+1;						needle=d;				}			} /* possible substitute */		} /* substitution loop */		/* proceed to next header */		/* new=new_str(CRLF, CRLF_LEN, &last, &total_len );		if (!new) goto error; */		DBG("DEBUG: get_hf_block: one more hf processed\n");	} /* header loop */	/* construct a single header block now */	ret=pkg_malloc(total_len);	if (!ret) {		LOG(L_ERR, "ERROR: get_hf_block no pkg mem for hf block\n");		goto error;	}	i=sl.next;	dst=ret;	while(i) {		foo=i;		i=i->next;		memcpy(dst, foo->s.s, foo->s.len);		dst+=foo->s.len;		pkg_free(foo);	}	*l=total_len;	return ret;error:	i=sl.next;	while(i) {		foo=i;		i=i->next;		pkg_free(foo);	}	*l=0;	return 0;}