op.h 9.42 KB
Newer Older
1
/*
2
 * op.h
Ronan's avatar
Ronan committed
3
 * Copyright (C) 2010-2018 Belledonne Communications SARL
4
 *
Ghislain MARY's avatar
Ghislain MARY committed
5 6 7 8
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
9 10 11 12 13 14 15
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
Ghislain MARY's avatar
Ghislain MARY committed
16 17
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
 */
19

20 21
#ifndef _L_SAL_OP_H_
#define _L_SAL_OP_H_
22 23 24 25

#include <bctoolbox/list.h>
#include <bctoolbox/port.h>
#include <belle-sip/types.h>
26 27

#include "c-wrapper/internal/c-sal.h"
28
#include "content/content.h"
29
#include "logger/logger.h"
30
#include "sal/sal.h"
31 32 33 34 35

LINPHONE_BEGIN_NAMESPACE

class SalOp {
public:
36 37
	SalOp (Sal *sal);
	virtual ~SalOp ();
38

39 40
	SalOp *ref ();
	void *unref ();
41

42
	Sal *getSal () const { return mRoot; }
43

44 45
	void setUserPointer (void *value) { mUserPointer = value; }
	void *getUserPointer () const { return mUserPointer; }
46

47 48
	void setSubject (const char *value);
	const char *getSubject () const { return mSubject; }
49

50 51 52 53
	void setFrom (const char *value);
	void setFromAddress (const SalAddress *value);
	const char *getFrom () const { return mFrom; }
	const SalAddress *getFromAddress () const { return mFromAddress; }
54

55 56 57 58
	void setTo (const char *value);
	void setToAddress (const SalAddress *value);
	const char *getTo () const { return mTo; }
	const SalAddress *getToAddress () const { return mToAddress; }
59

60 61
	void setContactAddress (const SalAddress* value);
	const SalAddress *getContactAddress() const { return mContactAddress; }
62

63 64 65 66
	void setRoute (const char *value);
	void setRouteAddress (const SalAddress *value);
	const bctbx_list_t *getRouteAddresses () const { return mRouteAddresses; }
	void addRouteAddress (const SalAddress *address);
67

68 69
	void setDiversionAddress (const SalAddress *value);
	const SalAddress *getDiversionAddress () const { return mDiversionAddress; }
70

71 72
	void setServiceRoute (const SalAddress *value);
	const SalAddress *getServiceRoute () const { return mServiceRoute; }
73

74
	void setManualRefresherMode (bool_t value) { mManualRefresher = value; }
75

76 77
	void setEntityTag (const char *value);
	const char *getEntityTag() const { return mEntityTag; }
78

79
	void setEvent (const char *eventName);
80

81 82
	void setPrivacy (SalPrivacyMask value) { mPrivacy = value; }
	SalPrivacyMask getPrivacy() const { return mPrivacy; }
83

84
	void setRealm (const char *value);
85

86
	void setSentCustomHeaders (SalCustomHeader *ch);
87

88 89
	void enableCnxIpTo0000IfSendOnly (bool_t value) { mCnxIpTo0000IfSendOnlyEnabled = value; }
	bool_t cnxIpTo0000IfSendOnlyEnabled () const { return mCnxIpTo0000IfSendOnlyEnabled; }
90

91 92 93 94 95 96 97 98 99
	const char *getProxy () const { return mRoute; }
	const char *getNetworkOrigin () const { return mOrigin; }
	const char *getCallId () const { return  mCallId; }
	char *getDialogId () const;
	int getAddressFamily () const;
	const SalCustomHeader *getRecvCustomHeaders () const { return mRecvCustomHeaders; }
	const char *getRemoteContact () const { return mRemoteContact; }
	const SalAddress *getRemoteContactAddress () const { return mRemoteContactAddress; }
	const char *getRemoteUserAgent () const { return mRemoteUserAgent; }
100

101 102 103 104 105 106
	const char *getPublicAddress (int *port) {
		return mRefresher ? belle_sip_refresher_get_public_address(mRefresher, port) : nullptr;
	}
	const char *getLocalAddress (int *port) {
		return mRefresher ? belle_sip_refresher_get_local_address(mRefresher, port) : nullptr;
	}
107

108 109
	const SalErrorInfo *getErrorInfo () const { return &mErrorInfo; }
	const SalErrorInfo *getReasonErrorInfo () const { return &mReasonErrorInfo; }
110

111 112 113 114
	bool_t isForkedOf (const SalOp *op) const {
		return mCallId && op->mCallId && strcmp(mCallId, op->mCallId) == 0;
	}
	bool_t isIdle () const;
115

116 117 118 119 120 121 122
	void stopRefreshing () {
		if (mRefresher)
			belle_sip_refresher_stop(mRefresher);
	}
	int refresh ();
	void killDialog ();
	void release ();
123

124 125 126 127
	virtual void authenticate (const SalAuthInfo *info) { 
        processAuthentication(); }
	void cancelAuthentication () { lFatal() << "SalOp::cancelAuthentication not implemented yet"; }
	SalAuthInfo *getAuthRequested () { return mAuthInfo; }
128

129 130
	int ping (const char *from, const char *to);
	int sendInfo (const char *from, const char *to, const SalBodyHandler *bodyHandler);
131

132 133 134 135
protected:
	enum class State {
		Early = 0,
		Active,
136
		Terminating, // This state is used to wait until a proceeding state, so we can send the cancel
137 138
		Terminated
	};
139

140
	static const char *toString (const State value);
141 142 143 144 145

	enum class Dir {
		Incoming = 0,
		Outgoing
	};
146

147 148 149 150 151 152 153
	enum class Type {
		Unknown,
		Register,
		Call,
		Message,
		Presence,
		Publish,
154
		Subscribe,
155
		Refer // For out of dialog refer only
156
	};
157

158
	static const char *toString (const Type type);
159

160
	using ReleaseCb = void (*) (SalOp *op);
161

162 163 164 165
	virtual void fillCallbacks () {}
	void releaseImpl ();
	void processAuthentication ();
	int processRedirect ();
166

167 168 169 170 171 172
	belle_sip_request_t *buildRequest (const char *method);
	int sendRequest (belle_sip_request_t *request);
	int sendRequestWithContact (belle_sip_request_t *request, bool_t addContact);
	int sendRequestWithExpires (belle_sip_request_t *request, int expires);
	void resendRequest (belle_sip_request_t *request);
	int sendRequestAndCreateRefresher (belle_sip_request_t *request, int expires, belle_sip_refresher_listener_t listener);
173

174 175
	void setReasonErrorInfo (belle_sip_message_t *message);
	void setErrorInfoFromResponse (belle_sip_response_t *response);
176

177 178
	void setReferredBy (belle_sip_header_referred_by_t *referredByHeader);
	void setReplaces (belle_sip_header_replaces_t *replacesHeader);
179

180 181 182 183 184
	void setRemoteContact (const char *value);
	void setNetworkOrigin (const char *value);
	void setNetworkOriginAddress (SalAddress *value);
	void setPrivacyFromMessage (belle_sip_message_t *message);
	void setRemoteUserAgent (belle_sip_message_t *message);
185

186 187 188 189
	belle_sip_response_t *createResponseFromRequest (belle_sip_request_t *request, int code) {
		return mRoot->createResponseFromRequest(request, code);
	}
	belle_sip_header_contact_t *createContact ();
190

191 192 193
	void setOrUpdateDialog (belle_sip_dialog_t *dialog);
	belle_sip_dialog_t *linkOpWithDialog (belle_sip_dialog_t *dialog);
	void unlinkOpFromDialog (belle_sip_dialog_t *dialog);
194

195
	SalBodyHandler *getBodyHandler (belle_sip_message_t *message);
196

197
	void assignRecvHeaders (belle_sip_message_t *message);
198

199 200 201 202
	bool_t isSecure () const;
	void addHeaders (belle_sip_header_t *h, belle_sip_message_t *message);
	void addCustomHeaders (belle_sip_message_t *message);
	int unsubscribe ();
203

204 205 206
	void processIncomingMessage (const belle_sip_request_event_t *event);
	int replyMessage (SalReason reason);
	void addMessageAccept (belle_sip_message_t *message);
207

208 209 210 211 212
	static bool_t isExternalBody (belle_sip_header_content_type_t* contentType);

	static void assignAddress (SalAddress **address, const char *value);
	static void assignString (char **str, const char *arg);
	static void addInitialRouteSet (belle_sip_request_t *request, const MSList *list);
213

214
	// SalOpBase
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
	Sal *mRoot = nullptr;
	char *mRoute = nullptr; // Or request-uri for REGISTER
	MSList *mRouteAddresses = nullptr; // List of SalAddress *
	SalAddress *mContactAddress = nullptr;
	char *mSubject = nullptr;
	char *mFrom = nullptr;
	SalAddress* mFromAddress = nullptr;
	char *mTo = nullptr;
	SalAddress *mToAddress = nullptr;
	char *mOrigin = nullptr;
	SalAddress *mOriginAddress = nullptr;
	SalAddress *mDiversionAddress = nullptr;
	char *mRemoteUserAgent = nullptr;
	SalAddress *mRemoteContactAddress = nullptr;
	char *mRemoteContact = nullptr;
	void *mUserPointer = nullptr;
	char *mCallId = nullptr;
	char *mRealm = nullptr;
	SalAddress *mServiceRoute = nullptr; // As defined by rfc3608, might be a list
	SalCustomHeader *mSentCustomHeaders = nullptr;
	SalCustomHeader *mRecvCustomHeaders = nullptr;
	char *mEntityTag = nullptr; // As defined by rfc3903 (I.E publih)
	ReleaseCb mReleaseCb = nullptr;

	const belle_sip_listener_callbacks_t *mCallbacks = nullptr;
	SalErrorInfo mErrorInfo;
	SalErrorInfo mReasonErrorInfo;
	belle_sip_client_transaction_t *mPendingAuthTransaction = nullptr;
	belle_sip_server_transaction_t *mPendingServerTransaction = nullptr;
	belle_sip_server_transaction_t *mPendingUpdateServerTransaction = nullptr;
	belle_sip_client_transaction_t *mPendingClientTransaction = nullptr;
	SalAuthInfo *mAuthInfo = nullptr;
	belle_sip_dialog_t *mDialog = nullptr;
	belle_sip_header_replaces_t *mReplaces = nullptr;
	belle_sip_header_referred_by_t *mReferredBy = nullptr;
	SalMediaDescription *mResult = nullptr;
	belle_sdp_session_description_t *mSdpAnswer = nullptr;
	State mState = State::Early;
	Dir mDir = Dir::Incoming;
	belle_sip_refresher_t *mRefresher = nullptr;
	int mRef = 0;
	Type mType = Type::Unknown;
	SalPrivacyMask mPrivacy = SalPrivacyNone;
	belle_sip_header_event_t *mEvent = nullptr; // Used by SalOpSubscribe kinds
	SalOpSDPHandling mSdpHandling = SalOpSDPNormal;
	int mAuthRequests = 0; // number of auth requested for this op
	bool_t mCnxIpTo0000IfSendOnlyEnabled = FALSE;
	bool_t mAutoAnswerAsked = FALSE;
	bool_t mSdpOffering = FALSE;
	bool_t mCallReleased = FALSE;
	bool_t mManualRefresher = FALSE;
	bool_t mHasAuthPending = FALSE;
	bool_t mSupportsSessionTimers = FALSE;
	bool_t mOpReleased = FALSE;
269

270 271 272 273 274
	friend class Sal;
};

LINPHONE_END_NAMESPACE

275
#endif // ifndef _L_SAL_OP_H_