~ubuntu-branches/ubuntu/saucy/resiprocate/saucy-proposed

« back to all changes in this revision

Viewing changes to presSvr/TuPresSvr.cpp

  • Committer: Package Import Robot
  • Author(s): Daniel Pocock
  • Date: 2012-05-17 19:29:59 UTC
  • Revision ID: package-import@ubuntu.com-20120517192959-vv00m77isztdy64q
Tags: upstream-1.8.2
ImportĀ upstreamĀ versionĀ 1.8.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "resip/stack/Helper.hxx"
 
2
 
 
3
#include "ResourceMgr.h"
 
4
#include "SubDialog.h"
 
5
#include "TuPresSvr.h"
 
6
 
 
7
using namespace resip;
 
8
 
 
9
bool
 
10
TuPresSvr::process()
 
11
{
 
12
 
 
13
    bool done = 0;
 
14
    FdSet fdset;
 
15
    mStack->buildFdSet(fdset);
 
16
//    int err = fdset.selectMilliSeconds(0);
 
17
    int err = fdset.selectMilliSeconds(100);
 
18
    assert( err != -1 );
 
19
 
 
20
    mStack->process(fdset);
 
21
 
 
22
    SipMessage* msg = (mStack->receive());
 
23
    if (msg)
 
24
    {
 
25
      if (msg->isRequest())
 
26
      {
 
27
        if (msg->header(h_RequestLine).getMethod() == SUBSCRIBE )
 
28
        {
 
29
          processSubscribe(msg);
 
30
        }
 
31
        else if (msg->header(h_RequestLine).getMethod() == REGISTER )
 
32
        {
 
33
          processPublish(msg);
 
34
        }
 
35
        else if (msg->header(h_RequestLine).getMethod() == OPTIONS )
 
36
        {
 
37
          auto_ptr<SipMessage> resp(
 
38
               Helper::makeResponse(*msg,500,"You Shot Me!")); 
 
39
          mStack->send(*resp);
 
40
          done = 1;
 
41
        }
 
42
        else if (msg->header(h_RequestLine).getMethod() == PUBLISH)
 
43
        {
 
44
           processPublish(msg);
 
45
        }
 
46
        else
 
47
        {
 
48
          auto_ptr<SipMessage> resp(Helper::makeResponse(*msg,501,"")); 
 
49
          mStack->send(*resp);
 
50
        }
 
51
      }
 
52
      else
 
53
      {
 
54
        /*
 
55
         Nope - dialog key is currently overscoped to requests - bad.
 
56
        assert(msg->isResponse());
 
57
        if (msg->header(h_CSeq).method()==NOTIFY)
 
58
          mDialogMgr.dispatchNotifyResponse(msg);
 
59
         */
 
60
      }
 
61
      delete msg;
 
62
    } else {
 
63
      mDialogMgr.processExpirations();
 
64
    }
 
65
    return done;
 
66
}
 
67
 
 
68
void
 
69
TuPresSvr::processSubscribe(SipMessage* msg)
 
70
{
 
71
  // See if this subscribe matches a dialog we have in progress
 
72
  if (mDialogMgr.dialogExists(msg))
 
73
  { 
 
74
     mDialogMgr.dispatchSubscribe(msg); 
 
75
  }
 
76
  else
 
77
  { 
 
78
     processNewSubscribe(msg); 
 
79
  }
 
80
}
 
81
 
 
82
void TuPresSvr::processNewSubscribe(SipMessage* msg)
 
83
{
 
84
  static Token presence("presence");
 
85
  if (   !msg->exists(h_Event)
 
86
       || msg->header(h_Event).value()!=presence.value()
 
87
     )
 
88
  {
 
89
    auto_ptr<SipMessage> resp(Helper::makeResponse(*msg,489,"")); 
 
90
    resp->header(h_AllowEvents).push_back(presence); 
 
91
    mStack->send(*resp);
 
92
    return;
 
93
  }
 
94
 
 
95
  if (ResourceMgr::instance()
 
96
                  .exists(msg->header(h_RequestLine).uri().getAorNoPort()))
 
97
  {
 
98
    mDialogMgr.dispatchNewSubscribe(msg);
 
99
  }
 
100
  else
 
101
  {
 
102
    auto_ptr<SipMessage> resp(Helper::makeResponse(*msg,404,"")); 
 
103
    mStack->send(*resp);
 
104
  }
 
105
 
 
106
}
 
107
 
 
108
void TuPresSvr::processPublish(SipMessage* msg)
 
109
{
 
110
  //ignore any PUBLISH related headers and any contacts
 
111
  //provided in a REGISTER
 
112
  //This is a rather vile hack for SIMPLEt 1
 
113
  Data aor;
 
114
  if ( msg->header(h_RequestLine).getMethod() == REGISTER )
 
115
  {
 
116
    aor = msg->header(h_To).uri().getAorNoPort();
 
117
  }
 
118
  else
 
119
  {
 
120
    aor = msg->header(h_RequestLine).uri().getAorNoPort();
 
121
  }
 
122
  if (ResourceMgr::instance().exists(aor))
 
123
  {
 
124
    Contents * contents = msg->getContents();
 
125
    if (contents)
 
126
    {
 
127
      int retcode = (ResourceMgr::instance().setPresenceDocument(aor,contents)
 
128
                     ?200:403);
 
129
      auto_ptr<SipMessage> resp(Helper::makeResponse(*msg,retcode,"")); 
 
130
      mStack->send(*resp);
 
131
    }
 
132
    else
 
133
    {
 
134
      auto_ptr<SipMessage> resp(Helper::makeResponse(*msg,400,"This hacked-up service requires a body")); 
 
135
      mStack->send(*resp);
 
136
    }
 
137
  }
 
138
  else
 
139
  {
 
140
    auto_ptr<SipMessage> resp(Helper::makeResponse(*msg,404,"")); 
 
141
    mStack->send(*resp);
 
142
  }
 
143
}