00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "inval-agent.h"
00023 #include "ip.h"
00024 #include "http.h"
00025
00026
00027 int hdr_inval::offset_;
00028 static class HttpInvalHeaderClass : public PacketHeaderClass {
00029 public:
00030 HttpInvalHeaderClass() : PacketHeaderClass("PacketHeader/HttpInval",
00031 sizeof(hdr_inval)) {
00032 bind_offset(&hdr_inval::offset_);
00033 }
00034 } class_httpinvalhdr;
00035
00036 static class HttpInvalClass : public TclClass {
00037 public:
00038 HttpInvalClass() : TclClass("Agent/HttpInval") {}
00039 TclObject* create(int, const char*const*) {
00040 return (new HttpInvalAgent());
00041 }
00042 } class_httpinval_agent;
00043
00044 HttpInvalAgent::HttpInvalAgent() : Agent(PT_INVAL)
00045 {
00046
00047 bind("inval_hdr_size_", &inval_hdr_size_);
00048 }
00049
00050 void HttpInvalAgent::recv(Packet *pkt, Handler*)
00051 {
00052 hdr_ip *ip = hdr_ip::access(pkt);
00053 if ((ip->saddr() == addr()) && (ip->sport() == port()))
00054
00055 return;
00056 if (app_ == 0)
00057 return;
00058 hdr_inval *ih = hdr_inval::access(pkt);
00059 ((HttpApp*)app_)->process_data(ih->size(), pkt->userdata());
00060 Packet::free(pkt);
00061 }
00062
00063
00064
00065
00066 void HttpInvalAgent::send(int realsize, AppData* data)
00067 {
00068 Packet *pkt = allocpkt(data->size());
00069 hdr_inval *ih = hdr_inval::access(pkt);
00070 ih->size() = data->size();
00071 pkt->setdata(data);
00072
00073
00074 hdr_cmn *ch = hdr_cmn::access(pkt);
00075 ch->size() = inval_hdr_size_ + realsize;
00076 Agent::send(pkt, 0);
00077 }
00078
00079
00080
00081 static class HttpUInvalClass : public TclClass {
00082 public:
00083 HttpUInvalClass() : TclClass("Application/TcpApp/HttpInval") {}
00084 TclObject* create(int argc, const char*const* argv) {
00085 if (argc != 5)
00086 return NULL;
00087 Agent *a = (Agent *)TclObject::lookup(argv[4]);
00088 a->set_pkttype(PT_INVAL);
00089 if (a == NULL)
00090 return NULL;
00091 return (new HttpUInvalAgent(a));
00092 }
00093 } class_httpuinval_agent;
00094
00095 void HttpUInvalAgent::process_data(int size, AppData* data)
00096 {
00097 target_->process_data(size, data);
00098 }
00099
00100 int HttpUInvalAgent::command(int argc, const char*const* argv)
00101 {
00102 if (strcmp(argv[1], "set-app") == 0) {
00103
00104 HttpApp* c =
00105 (HttpApp*)TclObject::lookup(argv[2]);
00106 target_ = (Process *)c;
00107 return TCL_OK;
00108 }
00109 return TcpApp::command(argc, argv);
00110 }