Beispiel #1
0
static void
add_from_skb(struct tcp_stream * a_tcp, struct half_stream * rcv,
	     struct half_stream * snd,
	     u_char *data, int datalen,
	     u_int this_seq, char fin, char urg, u_int urg_ptr)
{
  u_int lost = EXP_SEQ - this_seq;
  int to_copy, to_copy2;
  
  if (urg && after(urg_ptr, EXP_SEQ - 1) &&
      (!rcv->urg_seen || after(urg_ptr, rcv->urg_ptr))) {
    rcv->urg_ptr = urg_ptr;
    rcv->urg_seen = 1;
  }
  if (after(rcv->urg_ptr + 1, this_seq + lost) &&
      before(rcv->urg_ptr, this_seq + datalen)) {
    to_copy = rcv->urg_ptr - (this_seq + lost);
    if (to_copy > 0) {
      if (rcv->collect) {
	add2buf(rcv, data + lost, to_copy);
	notify(a_tcp, rcv);
      }
      else {
	rcv->count += to_copy;
	rcv->offset = rcv->count; /* clear the buffer */
      }
    }
    rcv->urgdata = data[rcv->urg_ptr - this_seq];
    rcv->count_new_urg = 1;
    notify(a_tcp, rcv);
    rcv->count_new_urg = 0;
    rcv->urg_count++;
    to_copy2 = this_seq + datalen - rcv->urg_ptr - 1;
    if (to_copy2 > 0) {
      if (rcv->collect) {
	add2buf(rcv, data + lost + to_copy + 1, to_copy2);
	notify(a_tcp, rcv);
      }
      else {
	rcv->count += to_copy2;
	rcv->offset = rcv->count; /* clear the buffer */
      }
    }
  }
  else {
    if (datalen - lost > 0) {
      if (rcv->collect) {
	add2buf(rcv, data + lost, datalen - lost);
	notify(a_tcp, rcv);
      }
      else {
	rcv->count += datalen - lost;
	rcv->offset = rcv->count; /* clear the buffer */
      }
    }
  }
  if (fin)
    snd->state = FIN_SENT;
}
Beispiel #2
0
static inline char* append2buf( char *buf, int len, struct sip_msg *req, 
				struct append_elem *elem)
{
	pv_value_t value;
	char *end;

	end = buf+len;

	while (elem)
	{
		/* get the value */
		if (pv_get_spec_value(req, &elem->spec, &value)!=0)
		{
			LM_ERR("failed to get '%.*s'\n", elem->name.len,elem->name.s);
		}

		/* empty element? */
		if ( !(value.flags&PV_VAL_NULL) ) {
			/* write the value into the buffer */
			buf = add2buf( buf, end, &elem->name, &value.rs);
			if (!buf)
			{
				LM_ERR("overflow -> append exceeded %d len\n",len);
				return 0;
			}
		}

		elem = elem->next;
	}

	return buf;
}
Beispiel #3
0
void
add_from_skb(struct tcp_stream * a_tcp, struct half_stream * rcv,
	     struct half_stream * snd,
	     u_char *data, u_int datalen,
	     u_int this_seq, char fin, char urg, u_int urg_ptr)
{
  u_int lost = abs(EXP_SEQ + a_tcp->totallost - this_seq);
  int mylost =  this_seq - EXP_SEQ -a_tcp->totallost;

  if(mylost > 0){
    a_tcp->totallost += mylost;
    lost = 0;
  }  
/*
  else if(mylost < 0){
    if(datalen <= lost)
        return;
 
  }
*/
  lost = 0;
  

  if(before_seq == this_seq){
     return;
  }
     
  before_seq = this_seq;
  before_len = datalen;

  int to_copy, to_copy2;
  
  if (urg && after(urg_ptr, EXP_SEQ - 1) &&
      (!rcv->urg_seen || after(urg_ptr, rcv->urg_ptr))) {
    rcv->urg_ptr = urg_ptr;
    rcv->urg_seen = 1;
  }
  if (after(rcv->urg_ptr + 1, this_seq + lost) && //if 2
      before(rcv->urg_ptr, this_seq + datalen)) {
    to_copy = rcv->urg_ptr - (this_seq + lost);
    if (to_copy > 0) {  //if 1
      if (rcv->collect) {
	add2buf(rcv, data + lost, to_copy);
	notify(a_tcp, rcv);
      }
      else {
	rcv->count += to_copy;
	rcv->offset = rcv->count; // clear the buffer 
      }
    }//if 1
    rcv->urgdata = data[rcv->urg_ptr - this_seq];
    rcv->count_new_urg = 1;
    notify(a_tcp, rcv);
    rcv->count_new_urg = 0;
    rcv->urg_count++;
    to_copy2 = this_seq + datalen - rcv->urg_ptr - 1;
    if (to_copy2 > 0) {// if 4
      if (rcv->collect) {
	add2buf(rcv, data + lost + to_copy + 1, to_copy2);
	notify(a_tcp, rcv);
      }
      else {
	rcv->count += to_copy2;
	rcv->offset = rcv->count; // clear the buffer 
      }
    }// if 4
  }// if 2
  else {
    if (datalen -lost > 0) {
      if (rcv->collect) {
	add2buf(rcv, data + lost, datalen - lost);
	notify(a_tcp, rcv);
      }
      else {
	rcv->count += datalen - lost;
	rcv->offset = rcv->count; // clear the buffer 
      }
    }
  }//else 2
  if (fin)
    snd->state = FIN_SENT;
}
Beispiel #4
0
static inline char* append2buf( char *buf, int len, struct sip_msg *req, 
				struct hdr_avp *ha)
{
	struct hdr_field *hdr;
	struct usr_avp   *avp;
	int_str          avp_val;
	int_str          avp_name;
	char  *end;
	str   foo;
	int   msg_parsed;

	end = buf+len;
	msg_parsed = 0;

	while(ha) {
		if (ha->type==ELEM_IS_AVP) {
			/* search for the AVP */
			if (ha->sval.s) {
				avp_name.s=ha->sval;
				avp = search_first_avp( AVP_NAME_STR, avp_name, &avp_val, 0);
				DBG("AVP <%.*s>: %p\n",avp_name.s.len, avp_name.s.s, avp);
			} else {
				avp_name.n=ha->ival;
				avp = search_first_avp( 0, avp_name, &avp_val, 0);
				DBG("AVP <%i>: %p\n",avp_name.n,avp);
			}
			if (avp) {
				if (avp->flags&AVP_VAL_STR) {
					buf=add2buf( buf, end, ha->title.s, ha->title.len,
						avp_val.s.s , avp_val.s.len);
					if (!buf)
						goto overflow_err;
				} else {
					foo.s=int2str( (unsigned long)avp_val.n, &foo.len);
					buf=add2buf( buf, end, ha->title.s, ha->title.len,
						foo.s , foo.len);
					if (!buf)
						goto overflow_err;
				}
			}
		} else if (ha->type==ELEM_IS_HDR) {
			/* parse the HDRs */
			if (!msg_parsed) {
				if (parse_headers( req, HDR_EOH_F, 0)!=0) {
					LOG(L_ERR,"ERROR:tm:append2buf: parsing hdrs failed\n");
					goto error;
				}
				msg_parsed = 1;
			}
			/* search the HDR */
			if (ha->ival==HDR_OTHER_T) {
				for(hdr=req->headers;hdr;hdr=hdr->next)
					if (ha->sval.len==hdr->name.len &&
					strncasecmp( ha->sval.s, hdr->name.s, hdr->name.len)==0)
						break;
			} else {
				for(hdr=req->headers;hdr;hdr=hdr->next)
					if (ha->ival==hdr->type)
						break;
			}
			if (hdr) {
				trim_len( foo.len, foo.s, hdr->body);
				buf=add2buf( buf, end, ha->title.s, ha->title.len,
					foo.s , foo.len);
				if (!buf)
					goto overflow_err;
			}
		} else {
			LOG(L_ERR,"BUG:tm:append2buf: unknown element type %d\n",
				ha->type);
			goto error;
		}

		ha = ha->next;
	}

	return buf;
overflow_err:
	LOG(L_ERR,"ERROR:tm:append2buf: overflow -> append exceeded %d len\n",len);
error:
	return 0;
}