/[resiprocate]/main/resip/dum/test/treg.cxx
ViewVC logotype

Annotation of /main/resip/dum/test/treg.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 7081 - (hide annotations) (download)
Tue Apr 17 14:46:38 2007 UTC (12 years, 7 months ago) by bcampen
File MIME type: text/plain
File size: 4164 byte(s)
Reverting rev 7077 until it can get some review.
1 jason 6057 #include "rutil/Logger.hxx"
2     #include "resip/dum/MasterProfile.hxx"
3 jason 6092 #include "resip/dum/DumFeature.hxx"
4     #include "resip/dum/OutgoingEvent.hxx"
5    
6     #include "CommandLineParser.hxx"
7 jason 6057 #include "RegEventClient.hxx"
8    
9     using namespace resip;
10    
11     #define RESIPROCATE_SUBSYSTEM Subsystem::TEST
12 jason 6092
13     // This feature will add a missing Contact header to incoming SIP messages on
14     // 2xx responses to SUBSCRIBE or on NOTIFY requests.
15     class FixMissingContact : public DumFeature
16     {
17     public:
18     FixMissingContact(DialogUsageManager& dum, TargetCommand::Target& target) :
19     DumFeature(dum, target)
20     {
21     }
22    
23 bcampen 7081 virtual ProcessingResult process(Message* msg)
24 jason 6092 {
25 bcampen 7081 SipMessage* sip = dynamic_cast<SipMessage*>(msg);
26 jason 6057
27 jason 6092 if (sip)
28     {
29     switch (sip->header(h_CSeq).method())
30     {
31     case NOTIFY:
32     if (sip->isRequest() && !sip->exists(h_Contacts) && sip->header(h_Contacts).empty())
33     {
34     sip->header(h_Contacts).push_back(sip->header(h_From));
35     }
36     break;
37 jason 6057
38 jason 6092 case SUBSCRIBE:
39     if (sip->isResponse() &&
40     sip->header(h_StatusLine).statusCode() / 200 == 1 &&
41     !sip->exists(h_Contacts) &&
42     sip->header(h_Contacts).empty())
43     {
44     sip->header(h_Contacts).push_back(sip->header(h_To));
45     }
46     break;
47    
48     default:
49     break;
50     }
51     }
52     return DumFeature::FeatureDone;
53     }
54     };
55    
56    
57     // This feature is used to hardcode the host and port of the Contact header and
58     // will apply to any outgoing SIP requests.
59     class OverrideContact : public DumFeature
60     {
61     public:
62     OverrideContact(const Uri& contact,
63     DialogUsageManager& dum,
64     TargetCommand::Target& target) :
65     DumFeature(dum, target),
66     mContact(contact)
67     {
68     }
69    
70 bcampen 7081 virtual ProcessingResult process(Message* msg)
71 jason 6092 {
72 bcampen 7081 OutgoingEvent* og = dynamic_cast<OutgoingEvent*>(msg);
73 jason 6092 if (og)
74     {
75     SharedPtr<SipMessage> sip = og->message();
76     if (sip->isRequest() &&
77     sip->exists(h_Contacts) &&
78     sip->header(h_Contacts).size() == 1)
79     {
80     sip->header(h_Contacts).front().uri().host() = mContact.host();
81     sip->header(h_Contacts).front().uri().port() = mContact.port();
82     }
83     }
84    
85     return DumFeature::FeatureDone;
86     }
87    
88     private:
89     Uri mContact;
90     };
91    
92    
93 jason 6057 class MyApp : public RegEventClient
94     {
95     public:
96     MyApp(resip::SharedPtr<resip::MasterProfile> profile) : RegEventClient(profile)
97     {
98 jason 6092 SharedPtr<DumFeature> f1(new FixMissingContact(mDum, mDum.dumIncomingTarget()));
99     mDum.addIncomingFeature(f1);
100 jason 6057 }
101 jason 6092
102     // optionally call this method once to override the host/port of contact
103     // on outbound requests
104     void overrideContact(const resip::Uri& contact)
105     {
106     // This is only necessary if the user agent is running behind a NAT.
107     SharedPtr<DumFeature> f2(new OverrideContact(contact, mDum, mDum.dumOutgoingTarget()));
108     mDum.addOutgoingFeature(f2);
109     }
110 jason 6057
111     virtual void onRegEvent(const resip::Data& aor, const resip::Data& reg)
112     {
113 jason 6092 WarningLog (<< "Got result from " << aor << " --> " << reg);
114 jason 6057 }
115    
116     virtual void onRegEventError(const resip::Data& aor, const resip::Data& reg)
117     {
118 jason 6092 WarningLog (<< "Got error for " << aor);
119 jason 6057 }
120     };
121    
122     int
123     main(int argc, char** argv)
124     {
125 jason 6092 CommandLineParser clp(argc, argv);
126     Log::initialize(clp.mLogType, clp.mLogLevel, argv[0]);
127    
128 jason 6057 SharedPtr<MasterProfile> profile(new MasterProfile);
129 jason 6092
130     NameAddr from(clp.mAor);
131 jason 6057 profile->setDefaultFrom(from);
132 jason 6092
133     MyApp client(profile);
134 jason 6057
135 jason 6092 // only necessary if behind a NAT
136     client.overrideContact(clp.mContact);
137    
138 jason 6057 client.run();
139    
140 jason 6092 Uri a1(clp.mAor);
141 jason 6057 client.watchAor(a1);
142    
143     sleep(3600);
144     return 0;
145     }
146    

Properties

Name Value
svn:eol-style native
svn:mime-type text/plain

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27