Statistics
| Branch: | Revision:

ml / ml.c @ 2c702104

History | View | Annotate | Download (5.97 KB)

1
/*
2
 *          Policy Management
3
 *
4
 *          NEC Europe Ltd. PROPRIETARY INFORMATION
5
 *
6
 * This software is supplied under the terms of a license agreement
7
 * or nondisclosure agreement with NEC Europe Ltd. and may not be
8
 * copied or disclosed except in accordance with the terms of that
9
 * agreement.
10
 *
11
 *      Copyright (c) 2009 NEC Europe Ltd. All Rights Reserved.
12
 *
13
 * Authors: Kristian Beckers  <beckers@nw.neclab.eu>
14
 *          Sebastian Kiesel  <kiesel@nw.neclab.eu>
15
 *          
16
 *
17
 * NEC Europe Ltd. DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED,
18
 * INCLUDING BUT NOT LIMITED TO IMPLIED WARRANTIES OF MERCHANTABILITY
19
 * AND FITNESS FOR A PARTICULAR PURPOSE AND THE WARRANTY AGAINST LATENT
20
 * DEFECTS, WITH RESPECT TO THE PROGRAM AND THE ACCOMPANYING
21
 * DOCUMENTATION.
22
 *
23
 * No Liability For Consequential Damages IN NO EVENT SHALL NEC Europe
24
 * Ltd., NEC Corporation OR ANY OF ITS SUBSIDIARIES BE LIABLE FOR ANY
25
 * DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS
26
 * OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF INFORMATION, OR
27
 * OTHER PECUNIARY LOSS AND INDIRECT, CONSEQUENTIAL, INCIDENTAL,
28
 * ECONOMIC OR PUNITIVE DAMAGES) ARISING OUT OF THE USE OF OR INABILITY
29
 * TO USE THIS PROGRAM, EVEN IF NEC Europe Ltd. HAS BEEN ADVISED OF THE
30
 * POSSIBILITY OF SUCH DAMAGES.
31
 *
32
 *     THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY.
33
 */
34

    
35
#include <string.h>
36
#include <stdio.h>
37
#include <stddef.h>
38
#include <sys/types.h>
39
#include <netinet/in.h>
40
#include <arpa/inet.h>
41
#include <errno.h>
42
#include <stdlib.h>
43
#include <unistd.h>
44
#include <time.h>
45
#include <event.h>
46

    
47
#include "ml.h"
48
#include "transmissionHandler.h"
49
#include "util/udpSocket.h"
50

    
51
void init_messaging_layer(bool recv_data_cb,struct timeval timeout_value,const int port,const char *ipaddr,const int stun_port,const char *stun_ipaddr,receive_localsocketID_cb local_socketID_cb,void *arg){
52

    
53
  init_transmissionHandler(recv_data_cb,timeout_value,port,ipaddr,stun_port,stun_ipaddr,local_socketID_cb,arg);
54

    
55
}
56

    
57
/* register callbacks  */
58
void register_Get_recv_pkt_inf(get_recv_pkt_inf_cb recv_pkt_inf_cb){
59

    
60
  register_get_recv_pkt_inf(recv_pkt_inf_cb);
61

    
62
}
63

    
64
void register_Get_send_pkt_inf(get_send_pkt_inf_cb  send_pkt_inf_cb){
65

    
66
  register_get_send_pkt_inf(send_pkt_inf_cb);
67

    
68
}
69

    
70

    
71
void register_Set_monitoring_header_pkt_cb(set_monitoring_header_pkt_cb monitoring_header_pkt_cb ){
72

    
73
  register_set_monitoring_header_pkt_cb(monitoring_header_pkt_cb);
74

    
75
}
76

    
77
void register_Get_recv_data_inf(get_recv_data_inf_cb recv_data_inf_cb){
78

    
79
  register_get_recv_data_inf(recv_data_inf_cb);
80

    
81
}
82

    
83
void register_Get_send_data_inf(get_send_data_inf_cb  send_data_inf_cb){
84

    
85
  register_get_send_data_inf(send_data_inf_cb);
86

    
87
}
88

    
89
void register_Set_monitoring_header_data_cb(set_monitoring_header_data_cb monitoring_header_data_cb){
90

    
91
  register_set_monitoring_header_data_cb(monitoring_header_data_cb);
92

    
93
}
94

    
95
void register_Recv_connection_cb(receive_connection_cb recv_conn_cb){
96

    
97
  register_recv_connection_cb(recv_conn_cb);
98

    
99
}
100

    
101
void register_Error_connection_cb(connection_failed_cb conn_failed){
102

    
103
  register_error_connection_cb(conn_failed);
104

    
105
}
106

    
107
void register_Recv_data_cb(receive_data_cb data_cb,unsigned char msgtype){
108

    
109
  register_recv_data_cb(data_cb,msgtype);
110

    
111
}
112

    
113
void close_Socket(socketID_handle socketID){
114

    
115
  close_socket(socketID);
116

    
117
}
118

    
119
/* connection functions */
120
int open_Connection(socketID_handle external_socketID,int *connectionID,receive_connection_cb connection_cb,void *arg){
121

    
122
  int return_val = open_connection(external_socketID,connectionID,connection_cb,arg); 
123

    
124
  return return_val;
125
}
126

    
127
void close_Connection(const int connectionID){
128

    
129
  close_connection(connectionID);
130

    
131
}
132

    
133
/* transmit data functions  */
134
int send_All_data(const int connectionID,send_all_data_container *container,int nr_entries,unsigned char msgtype,send_params *sParams){
135

    
136
  int returnvalue = send_all_data(connectionID,container,nr_entries,msgtype,sParams);
137
  return returnvalue;
138

    
139
}
140

    
141
void send_Data(const int connectionID,char *sendbuf,int bufsize,unsigned char msgtype,send_params *sParams){
142

    
143
   send_data(connectionID,sendbuf,bufsize,msgtype,sParams);
144

    
145
}
146

    
147
int recv_Data(const int connectionID,char *recvbuf,int *bufsize,recv_params *rParams){
148

    
149
  int i;
150
  i = recv_data(connectionID,recvbuf,bufsize,rParams);
151
  return i;
152

    
153
}
154

    
155
/* setter  */
156
void set_Stun_Server(const int port,const char *ipaddr){
157

    
158
  setStunServer(port,ipaddr);
159

    
160
}
161

    
162
void set_Recv_Timeout(struct timeval timeout_value){
163

    
164
  setRecvTimeout(timeout_value);
165

    
166
}
167

    
168
int get_Standard_ttl(socketID_handle socketID,uint8_t *ttl){
169

    
170
  int returnValue = get_standard_ttl(socketID,ttl);
171

    
172
  return returnValue;
173
}
174

    
175
socketID_handle get_Local_socketID(int *errorstatus){
176

    
177
  socketID_handle local_socketID = get_local_socketID(errorstatus);
178

    
179
  return local_socketID;
180

    
181
}
182

    
183
int get_External_IP(char* external_addr){
184

    
185
  int returnvalue = get_external_IP(external_addr);
186

    
187
  return returnvalue; 
188

    
189
}
190

    
191
int socketID_To_String(socketID_handle socketID,char* socketID_string){
192

    
193
  int returnvalue  = socketID_to_String(socketID,socketID_string);
194

    
195
  return returnvalue;
196

    
197
}
198

    
199
int string_To_SocketID(char* socketID_string, socketID_handle socketID){
200

    
201
  int returnvalue = string_to_socketID(socketID_string, socketID);
202

    
203
  return returnvalue;
204
}
205

    
206
int get_Connection_status(int connectionID){
207

    
208
  int returnvalue  = get_connection_status(connectionID);
209

    
210
  return returnvalue;
211
    
212
}
213

    
214

    
215
int connection_Exist(socketID_handle socketID){
216

    
217
  int returnvalue  = connection_exist(socketID);
218

    
219
  return returnvalue;
220

    
221
}
222

    
223
//Added by Robert Birke as comodity functions
224

    
225
int print_SocketID(socketID_handle socketID) {
226
        return print_socketID(socketID);
227
}
228
int hash_SocketID(socketID_handle sock) {
229
   return hash_socketID(sock);
230
}
231

    
232
int compare_SocketIDs(socketID_handle sock1, socketID_handle sock2) {
233
        return compare_socketIDs(sock1,sock2);
234
}
235

    
236
int compare_SocketIDs_By_Port(socketID_handle sock1, socketID_handle sock2)
237
{
238
        if (sock1->internal_addr.udpaddr.sin_port !=
239
                 sock2->internal_addr.udpaddr.sin_port)
240
                        return 1;
241

    
242
        if (sock1->external_addr.udpaddr.sin_port !=
243
                 sock2->external_addr.udpaddr.sin_port)
244
                        return 1;
245

    
246
        return 0;
247
}