1 /*
2  *  This program is free software; you can redistribute it and/or modify
3  *  it under the terms of the GNU General Public License as published by
4  *  the Free Software Foundation; either version 2 of the License, or
5  *  (at your option) any later version.
6  *
7  *  This program is distributed in the hope that it will be useful,
8  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  *  GNU General Public License for more details.
11  *
12  *  You should have received a copy of the GNU General Public License
13  *  along with this program; if not, write to the Free Software
14  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15  *
16  *  Author : Richard GAYRAUD - 04 Nov 2003
17  *           Olivier Jacques
18  *           From Hewlett Packard Company.
19  *           Shriram Natarajan
20  *           Peter Higginson
21  *           Eric Miller
22  *           Venkatesh
23  *           Enrico Hartung
24  *           Nasir Khan
25  *           Lee Ballard
26  *           Guillaume Teissier from FTR&D
27  *           Wolfgang Beck
28  *           Venkatesh
29  *           Vlad Troyanker
30  *           Charles P Wright from IBM Research
31  *           Amit On from Followap
32  *           Jan Andres from Freenet
33  *           Ben Evans from Open Cloud
34  *           Marc Van Diest from Belgacom
35  *           Andy Aicken
36  */
37 
38 #ifndef __MESSAGE__
39 #define __MESSAGE__
40 
41 #include <vector>
42 
43 class scenario;
44 
45 struct MessageComponent;
46 
47 typedef enum {
48     E_Message_Literal,
49     E_Message_Remote_IP,
50     E_Message_Remote_Host,
51     E_Message_Remote_Port,
52     E_Message_Transport,
53     E_Message_Local_IP,
54     E_Message_Local_IP_Type,
55     E_Message_Local_Port,
56     E_Message_Server_IP,
57     E_Message_Media_IP,
58     E_Message_Auto_Media_Port,
59     E_Message_Media_Port,
60     E_Message_Media_IP_Type,
61     E_Message_Call_Number,
62     E_Message_DynamicId,   // general usage, global, autoincrementing and wrapping counter
63     E_Message_Call_ID,
64     E_Message_CSEQ,
65     E_Message_PID,
66     E_Message_Service,
67     E_Message_Branch,
68     E_Message_Index,
69     E_Message_Next_Url,
70     E_Message_Len,
71     E_Message_Peer_Tag_Param,
72     E_Message_Routes,
73     E_Message_Variable,
74     E_Message_Fill,
75     E_Message_Injection,
76     E_Message_Last_Header,
77     E_Message_Last_Request_URI,
78     E_Message_Last_CSeq_Number,
79     E_Message_Last_Message,
80     E_Message_TDM_Map,
81     E_Message_Authentication,
82     E_Message_ClockTick,
83     E_Message_Users,
84     E_Message_UserID,
85     E_Message_Timestamp,
86     E_Message_Date,
87     E_Message_SippVersion,
88     E_Message_File,
89     E_Message_Custom
90 #ifdef RTP_STREAM
91     ,
92     E_Message_RTPStream_Audio_Port,
93     E_Message_RTPStream_Video_Port
94 #endif
95 } MessageCompType;
96 
97 class SendingMessage
98 {
99 public:
100     SendingMessage(scenario *msg_scenario, char *msg, bool skip_sanity = false);
101     ~SendingMessage();
102 
103     struct MessageComponent *getComponent(int);
104     int numComponents();
105 
106     char *getMethod();
107     int getCode();
108 
109     bool isResponse();
110     bool isAck();
111     bool isCancel();
112 
113     static void parseAuthenticationKeyword(scenario *msg_scenario, struct MessageComponent *dst, char *keyword);
114     static void freeMessageComponent(struct MessageComponent *comp);
115 private:
116     std::vector <struct MessageComponent *> messageComponents;
117 
118     char *method;
119     int code;
120 
121     bool ack;
122     bool cancel;
123     bool response;
124 
125     scenario *msg_scenario;
126 
127     // Get parameters from a [keyword]
128     static void getQuotedParam(char * dest, char * src, int * len);
129     static void getHexStringParam(char * dest, char * src, int * len);
130     static void getKeywordParam(char * src, const char * param, char * output);
131 };
132 
133 /* Custom Keyword Function Type. */
134 struct MessageComponent;
135 class call;
136 typedef int (*customKeyword)(call *, struct MessageComponent *, char *, int);
137 /* Custom Keyword Registration Function. */
138 int registerKeyword(char *keyword, customKeyword fxn);
139 
140 struct MessageComponent {
141     MessageCompType type;
142     char *literal;
143     int literalLen;
144     int offset;
145     int varId;
146     union u {
147         /* Authentication Parameters. */
148         struct {
149             SendingMessage *auth_user;
150             SendingMessage *auth_pass;
151             SendingMessage *aka_OP;
152             SendingMessage *aka_AMF;
153             SendingMessage *aka_K;
154         } auth_param;
155         /* Field Substitution. */
156         struct {
157             char *filename;
158             int field;
159             SendingMessage *line;
160         } field_param;
161         SendingMessage *filename;
162         customKeyword fxn;
163     } comp_param;
164 };
165 
166 #endif
167