summaryrefslogtreecommitdiffstats
path: root/tinyNET/src/turn/tnet_turn_message.c
blob: b0eff4660bcdefdc911ae333737549ca27e95e08 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
///*
//* Copyright (C) 2010-2011 Mamadou Diop.
//*
//* Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
//*
//* This file is part of Open Source Doubango Framework.
//*
//* DOUBANGO 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 3 of the License, or
//* (at your option) any later version.
//*
//* DOUBANGO 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
//* along with DOUBANGO.
//*
//*/
//
///**@file tnet_turn_message.c
// * @brief Traversal Using Relays around NAT (TURN) messages.
// *
// * @author Mamadou Diop <diopmamadou(at)doubango[dot]org>
// *
//
// */
//#include "tnet_turn_message.h"
//
//#include "../tnet_types.h"
//#include "../tnet_endianness.h"
//
//#include "tsk_memory.h"
//
//#include <string.h>
//
//tnet_turn_channel_data_t* tnet_turn_channel_data_create(uint16_t number, uint16_t length, const void* data)
//{
//	return tsk_object_new(tnet_turn_channel_data_def_t, number, length, data);
//}
//
//tnet_turn_channel_data_t* tnet_turn_channel_data_create_null()
//{
//	return tnet_turn_channel_data_create(0, 0, tsk_null);
//}
//
///**@ingroup tnet_turn_group
//*/
//tsk_buffer_t* tnet_turn_channel_data_serialize(const tnet_turn_channel_data_t *message)
//{
//	tsk_buffer_t *output = 0;
//
//	if(!message) goto bail;
//
//	output = tsk_buffer_create_null();
//
//	/*	draft-ietf-behave-turn-16 11.4.  The ChannelData Message
//		0                   1                   2                   3
//		0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
//		+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
//		|         Channel Number        |            Length             |
//		+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
//		|                                                               |
//		/                       Application Data                        /
//		/                                                               /
//		|                                                               |
//		|                               +-------------------------------+
//		|                               |
//		+-------------------------------+
//	*/
//
//	/* Channel Number
//	*/
//	{
//		uint16_t number = tnet_htons(message->chanel_number);
//		tsk_buffer_append(output, &(number), 2);
//	}
//
//	/* Length
//	*/
//	{
//		uint16_t length = tnet_htons(message->length);
//		tsk_buffer_append(output, &(length), 2);
//	}
//
//	/* Application Data
//	*/
//	{
//		tsk_buffer_append(output, message->data, message->length);
//
//		/*	=== Padding:
//			Over stream transports, the ChannelData message MUST be padded to a
//			multiple of four bytes in order to ensure the alignment of subsequent
//			messages.  The padding is not reflected in the length field of the
//			ChannelData message, so the actual size of a ChannelData message
//			(including padding) is (4 + Length) rounded up to the nearest
//			multiple of 4.  Over UDP, the padding is not required but MAY be included.
//		*/
//		if(message->length%4)
//		{
//			static uint32_t zeros = 0x00000000;
//			tsk_buffer_append(output, &zeros, 4-(message->length%4));
//		}
//	}
//
//bail:
//	return output;
//}
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
////=================================================================================================
////	TURN CHANNEL-DATA message object definition
////
//static tsk_object_t* tnet_turn_channel_data_ctor(tsk_object_t * self, va_list * app)
//{
//	tnet_turn_channel_data_t *message = self;
//	if(message){
//		const void* data;
//		message->chanel_number = tsk_va_arg_u16(*app);
//		message->length = tsk_va_arg_u16(*app);
//		data = va_arg(*app, const void*);
//		if(data && message->length){
//			if((message->data = tsk_calloc(message->length, sizeof(uint8_t)))){
//				memcpy(message->data, data, message->length);
//			}
//		}
//	}
//	return self;
//}
//
//static tsk_object_t* tnet_turn_channel_data_dtor(tsk_object_t * self)
//{
//	tnet_turn_channel_data_t *message = self;
//	if(message){
//		TSK_FREE(message->data);
//	}
//
//	return self;
//}
//
//static const tsk_object_def_t tnet_turn_channel_data_def_s =
//{
//	sizeof(tnet_turn_channel_data_t),
//	tnet_turn_channel_data_ctor,
//	tnet_turn_channel_data_dtor,
//	tsk_null,
//};
//const tsk_object_def_t *tnet_turn_channel_data_def_t = &tnet_turn_channel_data_def_s;
OpenPOWER on IntegriCloud