Browse code

some clean up!!

Bogdan-Andrei Iancu authored on 21/11/2001 18:55:59
Showing 5 changed files
... ...
@@ -47,3 +47,9 @@ all: $(NAME)
47 47
 
48 48
 .PHONY: dep
49 49
 dep: $(depends)
50
+
51
+clean:
52
+	rm -f *.o
53
+	rm -f tm
54
+
55
+
50 56
deleted file mode 100644
... ...
@@ -1,38 +0,0 @@
1
-#include "semaphore.h"
2
-
3
-int create_sem( key_t key , int val)
4
-{
5
-   int id;
6
-   union semun
7
-   {
8
-      int val;
9
-      struct semid_ds *buf;
10
-      ushort *array;
11
-   } argument;
12
-
13
-   id = semget( key , 1,  0666|IPC_CREAT );
14
-   argument.val = val;
15
-   if  (id!=-1)
16
-      if ( semctl( id , 0 , SETVAL , argument )==-1 )
17
-         id = -1;
18
-   return id;
19
-}
20
-
21
-
22
-int change_sem( int id , int val )
23
-{
24
-   struct sembuf pbuf;
25
-
26
-   pbuf.sem_num = 0;
27
-   pbuf.sem_op =val;
28
-   pbuf.sem_flg = 0;
29
-
30
-   return semop( id , &pbuf , 1);
31
-}
32
-
33
-
34
-
35
-int remove_sem( int id )
36
-{
37
-   return  semctl( id , 0 , IPC_RMID , 0 ) ;
38
-}
39 0
deleted file mode 100644
... ...
@@ -1,16 +0,0 @@
1
-#ifndef _SEMAPHORE_H
2
-#define _SEMAPHORE_H
3
-
4
-#include <sys/types.h>
5
-#include <sys/ipc.h>
6
-#include <sys/sem.h>
7
-
8
-
9
-int create_sem( key_t key , int val);
10
-
11
-int change_sem( int id , int val );
12
-
13
-int remove_sem( int id );
14
-
15
-#endif
16
-
17 0
deleted file mode 100644
... ...
@@ -1,271 +0,0 @@
1
-#include <stdio.h>
2
-#include <stdlib.h>
3
-
4
-#include "tm.h"
5
-
6
-struct s_table*  hash_table;
7
-
8
-int request_received( struct s_table* hash_table, 
9
-		char* incoming_req_uri, char *from, char* to, char* tag, 
10
-		char* call_id, char* cseq_nr ,char* cseq_method, char* outgoing_req_uri)
11
-{
12
-   struct cell*  matched_trans = 0;
13
-   struct cell*  new_trans         = 0;
14
-   int status;
15
-
16
-   /* looking for transaction
17
-    * IMPORTANT NOTE : the lookup_for_Transaction_by_XXXX returns the found trans referenceted -> when finidh you
18
-    * have to unreference manually, otherwise the cell wann't be ever deleted!!!!
19
-    */
20
-
21
-   if ( !strcmp( cseq_method , "ACK") )
22
-   {
23
-      /* we got an ACK -> do we have a transaction pair for it?*/
24
-      matched_trans =  lookup_for_Transaction_by_ACK( hash_table, from , to , tag , call_id , cseq_nr );
25
-      if ( matched_trans )
26
-      {
27
-         /* the trans pair was found -> let's check the trans's status  */
28
-         status = matched_trans->status;
29
-         /* done with reading the transaction -> unref it*/
30
-         unref_Cell( matched_trans );
31
-         if ( status>=200 && status<300 )
32
-         {
33
-            /* response for PROXY -> route the ACK */
34
-          return 1;
35
-         }
36
-         else
37
-         {
38
-            /* response for PROXY->DROP the request!! */
39
-            return 0;
40
-         }
41
-      }
42
-      else
43
-      {
44
-         /* response for PROXY -> route the ACK */
45
-         return 1;
46
-      }
47
-   }
48
-
49
-
50
-   /* looks up for a perfect mache transaction */
51
-   matched_trans =  lookup_for_Transaction_by_req( hash_table, from , to , tag , call_id , cseq_nr , cseq_method );
52
-
53
-   if ( matched_trans )
54
-   {
55
-      /* the trans already exists -> the last response is retransmited  */
56
-      status = matched_trans->status;
57
-      /* done with reading the transaction -> unref it*/
58
-      unref_Cell( matched_trans );
59
-      // TO DO -> replay with <status> response
60
-      /* response for PROXY->DROP the request!! */
61
-      return 0 ;
62
-   }
63
-
64
-
65
-    /* if is not a request -> route it further */
66
-   if ( strcmp( cseq_method , "CANCEL") )
67
-   {
68
-      /* we got a CANCEL -> do we have a transaction pair for it?*/
69
-      matched_trans = lookup_for_Transaction_by_CANCEL( hash_table, incoming_req_uri , from , to , tag , call_id , cseq_nr );
70
-      if ( matched_trans )
71
-      {
72
-         /* the trans pair was found -> let's check the trans's status  */
73
-         status = matched_trans->status;
74
-         /* done with reading the transaction -> unref it*/
75
-         unref_Cell( matched_trans );
76
-        if ( status>=200 )
77
-         {
78
-            /* the trasaction has a final response -> send a 200 reply for the CANCEL */
79
-            // TO DO send 200 reply
80
-            /*response for PROXY -> DROP the request!!! */
81
-            return 0;
82
-         }
83
-      }
84
-   }
85
-
86
-   /* a new trans is created based on the received request */
87
-   new_trans = add_Transaction( hash_table , incoming_req_uri , from , to , tag , call_id , cseq_nr , cseq_method );
88
-   if ( !new_trans )
89
-   {
90
-      /* response for PROXY -> error:cannot alloc memory */
91
-      return -1;
92
-   }
93
-   /* a 100 replay is sent */
94
-   //TO DO ->send a 100 reply
95
-
96
-   /* the FINAL RESPONSE timer is engaged */
97
-   start_FR_timer( hash_table, new_trans );
98
-   /* sets the outgoing req URI */
99
-   new_trans->outgoing_req_uri = sh_malloc( strlen(outgoing_req_uri) + 1 );
100
-   strcpy( new_trans->outgoing_req_uri , outgoing_req_uri );
101
-
102
-   /* response for PROXY -> route the request */
103
-   return 1;
104
-}
105
-
106
-
107
-
108
-
109
-
110
-
111
-int response_received(  struct s_table* hash_table, char* reply_code, char* incoming_url , 
112
-	char* via, char* label , char* from , char* to , char* tag , 
113
-	char* call_id , char* cseq_nr ,char* cseq_method )
114
-{
115
-   struct cell*  matched_trans = 0;
116
-   char* p;
117
-   int  res_status, trans_status;
118
-
119
-   /* looking for a transaction match
120
-    * IMPORTANT NOTE : the lookup_fir_Transaction returns the found trans referenceted -> when finidh you
121
-    * have to unreference manually, otherwise the cell wann't be ever deleted!!!!
122
-    */
123
-   matched_trans =  lookup_for_Transaction_by_res( hash_table, label , from , to , tag , call_id , cseq_nr , cseq_method );
124
-
125
-   if ( !matched_trans )
126
-   {
127
-      /* the trans wasn't found ->  the response is forwarded to next Via hop  */
128
-      return 1;
129
-   }
130
-
131
-   /* getting the matched trasaction  status */
132
-   trans_status = matched_trans->status;
133
-
134
-   /* getting the response status from reply as int form string */
135
-   p = reply_code;
136
-   res_status = strtol( reply_code , &p , 10 );
137
-   if ( *p!=0 )
138
-   {
139
-      /* done with the transaction -> unref it*/
140
-      unref_Cell( matched_trans );
141
-      /* response for PROXY -> error:cannot convert string to number */
142
-      return -1;
143
-   }
144
-
145
-   if ( res_status==100)
146
-   {
147
-      /* done with the transaction -> unref it*/
148
-      unref_Cell( matched_trans );
149
-      /* response for PROXY -> DROP the response!!! */
150
-      return 0;
151
-   }
152
-
153
-   if ( res_status >100 && res_status<200 )
154
-      if ( res_status > trans_status )
155
-      {
156
-         /* updating the transaction status */
157
-         matched_trans->status = res_status;
158
-         /* store the reply's tag (if no response tag has been set)*/
159
-         if ( !matched_trans->res_tag )
160
-         {
161
-            matched_trans->res_tag_length = strlen( tag );
162
-            matched_trans->res_tag = sh_malloc( matched_trans->res_tag_length+1 );
163
-            strcpy( matched_trans->res_tag , tag );
164
-         }
165
-         /* done with the transaction -> unref it*/
166
-         unref_Cell( matched_trans );
167
-         /* response to PROXY ->forward upstream the response */
168
-         return 1;
169
-      }
170
-      else
171
-      {
172
-         /* done with the transaction -> unref it*/
173
-         unref_Cell( matched_trans );
174
-         /* response to PROXY -> DROP the response !!! */
175
-         return 0;
176
-      }
177
-
178
-   /* if is the response for a local CANCEL*/
179
-   if ( via==0 && !strcmp( cseq_method,"CANCEL" ) )
180
-   {
181
-      /* done with the transaction -> unref it*/
182
-      unref_Cell( matched_trans );
183
-      /* response to PROXY -> DROP the response !!! */
184
-      return 0;
185
-   }
186
-
187
-   if ( res_status<200 || res_status>=300 )
188
-      if ( !strcmp( cseq_method,"INVITE" ) )
189
-      {
190
-         char   ack_req[500];
191
-         char* tag = 0;
192
-         /* send ACK for an error INVITE response */
193
-         strcpy( ack_req , "ACK " );
194
-         strcat( ack_req , matched_trans->incoming_req_uri ); strcat( ack_req , "\n" );
195
-         // via TO DO ?!!?!?!
196
-         strcat( ack_req , "From: " ); strcat( ack_req , matched_trans->from ); strcat( ack_req , "\n" );
197
-         strcat( ack_req , "To: " ); strcat( ack_req , matched_trans->to );
198
-         if ( matched_trans->req_tag )
199
-            tag = matched_trans->req_tag;
200
-         if ( !tag && matched_trans->res_tag )
201
-            tag = matched_trans->res_tag;
202
-         if (tag)
203
-            {strcat(ack_req," ;tag=");strcat(ack_req,tag);}
204
-         strcat( ack_req , "\n" );
205
-         strcat( ack_req , "Call-ID: " ); strcat( ack_req , matched_trans->call_id ); strcat( ack_req , "\n" );
206
-         strcat( ack_req , "CSeq: " ); strcat( ack_req , matched_trans->cseq_nr ); strcat( ack_req , " ACK\n\n" );
207
-         //TO DO - send the request
208
-      }
209
-   else
210
-      if ( strcmp( cseq_method,"INVITE" ) && trans_status>=200 )
211
-      {
212
-         /* done with the transaction -> unref it*/
213
-         unref_Cell( matched_trans );
214
-         /* response to PROXY -> DROP the response !!! */
215
-         return 0;
216
-      }
217
-
218
-
219
-   /* Final clean up */
220
-
221
-   /* updating the transaction status */
222
-   matched_trans->status = res_status;
223
-   /* store the reply's tag (if it's unset)*/
224
-   if ( !matched_trans->res_tag )
225
-   {
226
-      matched_trans->res_tag_length = strlen( tag );
227
-      matched_trans->res_tag = sh_malloc( matched_trans->res_tag_length+1 );
228
-      strcpy( matched_trans->res_tag , tag );
229
-   }
230
-   /* starts the WAIT timer */
231
-   start_WT_timer( hash_table, matched_trans );
232
-   /* done with the transaction -> unref it*/
233
-   unref_Cell( matched_trans );
234
-
235
-   /* response to PROXY ->forward upstream the response */
236
-   return 1;
237
-}
238
-
239
-
240
-
241
-
242
-
243
-int main()
244
-{
245
-    struct cell* cell1,*cell2 , *cell3 ,*cell4;
246
-
247
-   hash_table = init_hash_table();
248
-
249
-   cell1 = add_Transaction( hash_table , "iptel.org" , "sfo@iptel.org", "sfo@iptel.org", 0 , "1234ef2312@fesarius.gmd.de" , "100" , "INVITE"  );
250
-   cell2 = add_Transaction( hash_table , "iptel.org" , "sfo@iptel.org", "sfo@iptel.org", 0 , "3437625476@cucu.de" , "200" ,"REGISTER" );
251
-
252
-   start_FR_timer( hash_table, cell1 ) ;
253
-   start_FR_timer( hash_table, cell2 ) ;
254
-
255
-   cell3 = lookup_for_Transaction_by_req( hash_table, "sfo@iptel.org", "sfo@iptel.org", 0 , "1234ef2312@fesarius.gmd.de" , "100" ,"INVITE");
256
-
257
-    if (cell3)
258
-    {
259
-       printf(" From %s to %s a %s request\n",cell3->from,cell3->to,cell3->cseq_method);
260
-        unref_Cell ( cell3 );
261
-    }
262
-
263
-   while(1)
264
-   {
265
-      cell3 = lookup_for_Transaction_by_req( hash_table, "sfo@iptel.org", "sfo@iptel.org", 0 , "1234ef2312@fesarius.gmd.de" , "100" ,"INVITE");
266
-      if (cell3)  unref_Cell(cell3);
267
-      cell4 = lookup_for_Transaction_by_req( hash_table, "sfo@iptel.org" , "sfo@iptel.org", 0 , "3437625476@cucu.de" , "200" ,"REGISTER" );
268
-      if (cell4)  unref_Cell(cell4);
269
-   }
270
-
271
-}
272 0
deleted file mode 100644
... ...
@@ -1,15 +0,0 @@
1
-#ifndef _TM_H
2
-#define _TM_H
3
-
4
-#include <stdio.h>
5
-#include <stdlib.h>
6
-
7
-#include "h_table.h"
8
-
9
-int request_received(  struct s_table* hash_table, char* incoming_req_uri, char *from, char* to, char* tag, 
10
-	char* call_id, char* cseq_nr ,char* cseq_method, char* outgoing_req_uri);
11
-
12
-int response_received( struct s_table* hash_table, char* reply_code, char* incoming_url , char* via, char* label , 
13
-		char* from , char* to , char* tag , char* call_id , char* cseq_nr ,char* cseq_method );
14
-
15
-#endif