Browse code

serKey allocated in core (fixes strange crashes iff linking with other stuff)

git-svn-id: http://svn.berlios.de/svnroot/repos/sems/trunk@923 8eb893ce-cfd4-0310-b710-fb5ebe64c474

Stefan Sayer authored on 30/04/2008 15:02:22
Showing 12 changed files
... ...
@@ -104,3 +104,11 @@ AmCtrlInterfaceFactory::AmCtrlInterfaceFactory(const string& name)
104 104
   : AmPluginFactory(name) 
105 105
 {
106 106
 }
107
+
108
+AmCtrlInterface::AmCtrlInterface() 
109
+{
110
+}
111
+
112
+AmCtrlInterface::~AmCtrlInterface() 
113
+{
114
+}
... ...
@@ -235,17 +235,20 @@ class AmInterfaceHandler;
235 235
 class AmCtrlInterface: public AmThread
236 236
 {
237 237
  public:
238
-    AmCtrlInterface() {}
239
-    //virtual ~AmCtrlInterface() = 0;
240
-
241
-    //@param serKey An out parameter
242
-    virtual int send(const AmSipRequest &, string &serKey) = 0;
243
-
244
-    virtual int send(const AmSipReply &) = 0;
245
-
246
-    virtual string getContact(const string &displayName, 
247
-        const string &userName, const string &hostName, 
248
-        const string &uriParams, const string &hdrParams) = 0;
238
+  AmCtrlInterface();
239
+  virtual ~AmCtrlInterface();
240
+  
241
+  //@param serKey    [out] An out parameter
242
+  //@param serKeyLen [out] An out parameter
243
+  
244
+  virtual int send(const AmSipRequest &, 
245
+		   char* serKey, unsigned int& serKeyLen) = 0;
246
+  
247
+  virtual int send(const AmSipReply &) = 0;
248
+  
249
+  virtual string getContact(const string &displayName, 
250
+			    const string &userName, const string &hostName, 
251
+			    const string &uriParams, const string &hdrParams) = 0;
249 252
 };
250 253
 
251 254
 /**
... ...
@@ -62,9 +62,9 @@ bool AmServer::sendReply(const AmSipReply &reply)
62 62
   return ctrlIface->send(reply);
63 63
 }
64 64
 
65
-bool AmServer::sendRequest(const AmSipRequest &req, string &serKey)
65
+bool AmServer::sendRequest(const AmSipRequest &req, char* serKey, unsigned int& serKeyLen)
66 66
 {
67
-  return ctrlIface->send(req, serKey);
67
+  return ctrlIface->send(req, serKey, serKeyLen);
68 68
 }
69 69
 
70 70
 string AmServer::getContact(const string &displayName, 
... ...
@@ -66,7 +66,7 @@ public:
66 66
   void regIface(const AmCtrlInterface *i);
67 67
   bool hasIface() { return ctrlIface != NULL; };
68 68
 
69
-  static bool sendRequest(const AmSipRequest &, string &);
69
+  static bool sendRequest(const AmSipRequest &, char* serKey, unsigned int& serKeyLen);
70 70
   static bool sendReply(const AmSipReply &);
71 71
   static string getContact(const string &displayName, 
72 72
       const string &userName, const string &hostName, 
... ...
@@ -40,6 +40,11 @@ const char* AmSipDialog::status2str[4]  = {
40 40
   "Disconnecting" };
41 41
 
42 42
 
43
+AmSipDialog::AmSipDialog(AmSipDialogEventHandler* h)
44
+  : status(Disconnected),cseq(10),hdl(h), serKeyLen(0)
45
+{
46
+}
47
+
43 48
 AmSipDialog::~AmSipDialog()
44 49
 {
45 50
   DBG("callid = %s\n",callid.c_str());
... ...
@@ -527,9 +532,10 @@ int AmSipDialog::cancel()
527 532
   req.callid = callid;
528 533
   req.cseq = cancel_cseq;
529 534
   //useful for SER-2.0.0
530
-  req.serKey = serKey;
531
-  string empty;
532
-  return AmServer::sendRequest(req, empty) ? 0 : -1;
535
+  req.serKey = string(serKey, serKeyLen);
536
+  char empty[MAX_SER_KEY_LEN];
537
+  unsigned int unused = 0;
538
+  return AmServer::sendRequest(req, empty, unused) ? 0 : -1;
533 539
 }
534 540
 
535 541
 int AmSipDialog::sendRequest(const string& method, 
... ...
@@ -584,7 +590,7 @@ int AmSipDialog::sendRequest(const string& method,
584 590
     req.body = body;
585 591
   }
586 592
 
587
-  if (AmServer::sendRequest(req, serKey))
593
+  if (AmServer::sendRequest(req, serKey, serKeyLen))
588 594
     return -1;
589 595
     
590 596
   uac_trans[cseq] = AmSipTransaction(method,cseq);
... ...
@@ -35,6 +35,7 @@
35 35
 #include <map>
36 36
 using std::string;
37 37
 
38
+#define MAX_SER_KEY_LEN 30
38 39
 #define CONTACT_USER_PREFIX "sems"
39 40
 
40 41
 // flags which may be used when sending request/reply
... ...
@@ -137,12 +138,10 @@ class AmSipDialog
137 138
 
138 139
   int cseq;            // CSeq for next request
139 140
 
140
-  string serKey;      // opaque string returned by SER, when staring a T
141
-
142
-  AmSipDialog(AmSipDialogEventHandler* h=0)
143
-    : status(Disconnected),cseq(10),hdl(h)
144
-    {}
141
+  char serKey[MAX_SER_KEY_LEN];      // opaque string returned by SER, when staring a T
142
+  unsigned int serKeyLen;
145 143
 
144
+  AmSipDialog(AmSipDialogEventHandler* h=0);
146 145
   ~AmSipDialog();
147 146
 
148 147
   bool   getUACTransPending() { return !uac_trans.empty(); }
... ...
@@ -1120,7 +1120,7 @@ static inline brpc_t *build_request(const AmSipRequest &amReq,
1120 1120
   return req;
1121 1121
 }
1122 1122
 
1123
-int BrpcCtrlInterface::send(const AmSipRequest &amReq, string &serKey)
1123
+int BrpcCtrlInterface::send(const AmSipRequest &amReq, char *serKey, unsigned int &serKeyLen)
1124 1124
 {
1125 1125
   int ret = -1;
1126 1126
   brpc_t *req, *rpl = NULL;
... ...
@@ -1161,7 +1161,8 @@ int BrpcCtrlInterface::send(const AmSipRequest &amReq, string &serKey)
1161 1161
   }
1162 1162
   DBG("SER's opaque/reason: `%.*s'.\n", BRPC_STR_FMT(ser_opaque));
1163 1163
   //len must be fed, as the opaque could contain 0s
1164
-  serKey = string(ser_opaque->val, ser_opaque->len);
1164
+  memcpy(serKey, ser_opaque->val, ser_opaque->len);
1165
+  serKeyLen = ser_opaque->len;
1165 1166
 
1166 1167
   ret = 0;
1167 1168
 end:
... ...
@@ -75,7 +75,7 @@ class BrpcCtrlInterface: public AmCtrlInterface
75 75
     void on_stop() {}
76 76
 
77 77
     // AmCtrlInterface
78
-    int send(const AmSipRequest &, string &);
78
+    int send(const AmSipRequest &, char *, unsigned int &);
79 79
     int send(const AmSipReply &);
80 80
 
81 81
     string getContact(const string &displayName, 
... ...
@@ -158,8 +158,10 @@ string SipCtrlInterface::getContact(const string &displayName,
158 158
 }
159 159
 #endif
160 160
 
161
-int SipCtrlInterface::send(const AmSipRequest &req, string &serKey)
161
+int SipCtrlInterface::send(const AmSipRequest &req, char* serKey, unsigned int& serKeyLen)
162 162
 {
163
+    serKeyLen = 0;
164
+
163 165
     if(req.method == "CANCEL")
164 166
 	return cancel(req);
165 167
 
... ...
@@ -269,12 +271,10 @@ int SipCtrlInterface::send(const AmSipRequest &req, string &serKey)
269 271
 	}
270 272
     }
271 273
 
272
-    char tid[12];
273
-
274
-    tl->send_request(msg,tid);
274
+    tl->send_request(msg,serKey);
275 275
     delete msg;
276 276
 
277
-    serKey = string(tid,12);
277
+    serKeyLen=12;
278 278
     return 0;
279 279
 }
280 280
 
... ...
@@ -81,8 +81,7 @@ public:
81 81
     /**
82 82
      * From AmCtrlInterface
83 83
      */
84
-
85
-    int send(const AmSipRequest &req, string &serKey);
84
+    int send(const AmSipRequest &req, char* serKey, unsigned int& serKeyLen);
86 85
     int send(const AmSipReply &rep);
87 86
     
88 87
 #ifndef _STANDALONE
... ...
@@ -130,7 +130,7 @@ int UnixCtrlInterface::init(const string& socket_name)
130 130
     return 0;
131 131
 }
132 132
 
133
-int UnixCtrlInterface::send(const AmSipRequest &req, string &_)
133
+int UnixCtrlInterface::send(const AmSipRequest &req, char *, unsigned int &)
134 134
 {
135 135
   return rplAdapt.send(req, reply_socket_name, ser_socket_name);
136 136
 }
... ...
@@ -65,7 +65,7 @@ class UnixCtrlInterface : public AmCtrlInterface
65 65
     ~UnixCtrlInterface();
66 66
 
67 67
     // AmCtrlInterface
68
-    int send(const AmSipRequest &, string &);
68
+    int send(const AmSipRequest &, char *, unsigned int &);
69 69
     int send(const AmSipReply &);
70 70
 
71 71
     string getContact(const string &displayName,