stun.h 3.44 KB
Newer Older
Olivier Crête's avatar
import  
Olivier Crête committed
1
2
3
4
5
6

#ifndef __STUN_H__
#define __STUN_H__

#include <glib.h>

Dafydd Harries's avatar
Dafydd Harries committed
7
8
G_BEGIN_DECLS

Olivier Crête's avatar
import  
Olivier Crête committed
9
10
11
12
13
14
15
16
17
typedef enum {
  STUN_MESSAGE_BINDING_REQUEST              = 0x001,
  STUN_MESSAGE_BINDING_RESPONSE             = 0x101,
  STUN_MESSAGE_BINDING_ERROR_RESPONSE       = 0x111,
  STUN_MESSAGE_SHARED_SECRET_REQUEST        = 0x002,
  STUN_MESSAGE_SHARED_SECRET_RESPONSE       = 0x102,
  STUN_MESSAGE_SHARED_SECRET_ERROR_RESPONSE = 0x112
} StunMessageType;

18
19
20
21
22
/* a = defined by RFC 3489
 * b = defined by RFC 3489bis
 * c = defined by draft-ietf-behave-turn-02
 */

Olivier Crête's avatar
import  
Olivier Crête committed
23
typedef enum {
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
  // mandatory parameters (<= 0x7fff)
  STUN_ATTRIBUTE_MAPPED_ADDRESS       = 0x0001, // ab
  STUN_ATTRIBUTE_RESPONSE_ADDRESS     = 0x0002, // a
  STUN_ATTRIBUTE_CHANGE_REQUEST       = 0x0003, // a
  STUN_ATTRIBUTE_CHANGED_ADDRESS      = 0x0004, // a
  STUN_ATTRIBUTE_SOURCE_ADDRESS       = 0x0005, // a
  STUN_ATTRIBUTE_USERNAME             = 0x0006, // ab
  STUN_ATTRIBUTE_PASSWORD             = 0x0007, // ab
  STUN_ATTRIBUTE_MESSAGE_INTEGRITY    = 0x0008, // ab
  STUN_ATTRIBUTE_ERROR_CODE           = 0x0009, // ab
  STUN_ATTRIBUTE_UNKNOWN_ATTRIBUTES   = 0x000a, // ab
  STUN_ATTRIBUTE_REFLECTED_FROM       = 0x000b, // a
  STUN_ATTRIBUTE_REALM                = 0x0014, //  b
  STUN_ATTRIBUTE_NONCE                = 0x0015, //  b
  STUN_ATTRIBUTE_LIFETIME             = 0x000D, //   c
  STUN_ATTRIBUTE_BANDWIDTH            = 0x0010, //   c
  STUN_ATTRIBUTE_REMOTE_ADDRESS       = 0x0012, //   c
  STUN_ATTRIBUTE_DATA                 = 0x0013, //   c
  STUN_ATTRIBUTE_RELAY_ADDRESS        = 0x0016, //   c
  STUN_ATTRIBUTE_REQUESTED_PORT_PROPS = 0x0018, //   c
  STUN_ATTRIBUTE_REQUESTED_TRANSPORT  = 0x0019, //   c
  STUN_ATTRIBUTE_REQUESTED_IP         = 0x0022, //   c
  STUN_ATTRIBUTE_TIMER_VAL            = 0x0021, //   c
  // optional parameters (> 0x7fff)
  STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS   = 0x8020, //  b
  STUN_ATTRIBUTE_FINGERPRINT          = 0x8023, //  b
  STUN_ATTRIBUTE_SERVER               = 0x8022, //  b
  SUTN_ATTRIBUTE_ALTERNATE_SERVER     = 0x8023, //  b
  STUN_ATTRIBUTE_REFRESH_INTERVAL     = 0x8024, //  b
Olivier Crête's avatar
import  
Olivier Crête committed
53
54
55
56
57
58
59
} StunAttributeType;

typedef struct _StunAttribute StunAttribute;

struct _StunAttribute {
  guint16 type;
  guint16 length;
60
61
62
63
64
65
66
67
68
69
  union {
    struct {
      guint8 padding;
      guint8 af;
      guint16 port;
      guint32 ip;
    } address;
    gchar username[128];
    gchar password[128];
  };
Olivier Crête's avatar
import  
Olivier Crête committed
70
71
72
73
74
75
76
77
78
79
};

typedef struct _StunMessage StunMessage;

struct _StunMessage {
  guint16 type;
  gchar transaction_id[16];
  StunAttribute **attributes;
};

80
G_GNUC_WARN_UNUSED_RESULT
Olivier Crête's avatar
import  
Olivier Crête committed
81
StunAttribute *
82
stun_attribute_mapped_address_new (guint32 ip_address, guint16 port);
83

Dafydd Harries's avatar
Dafydd Harries committed
84
85
StunAttribute *
stun_attribute_username_new (const gchar *username);
86

Olivier Crête's avatar
import  
Olivier Crête committed
87
void
88
stun_attribute_free (StunAttribute *attr);
89

90
G_GNUC_WARN_UNUSED_RESULT
Olivier Crête's avatar
import  
Olivier Crête committed
91
guint
92
stun_attribute_pack (StunAttribute *attr, gchar **ret);
93

94
G_GNUC_WARN_UNUSED_RESULT
Olivier Crête's avatar
import  
Olivier Crête committed
95
gchar *
96
stun_attribute_dump (StunAttribute *attr);
97

98
G_GNUC_WARN_UNUSED_RESULT
Olivier Crête's avatar
import  
Olivier Crête committed
99
StunAttribute *
100
stun_attribute_unpack (guint length, const gchar *s);
Olivier Crête's avatar
import  
Olivier Crête committed
101

102
void
103
stun_message_init (StunMessage *msg, guint type, gchar *id);
104

105
G_GNUC_WARN_UNUSED_RESULT
106
StunMessage *
107
stun_message_new (guint type, gchar *id, guint n_attributes);
108

Olivier Crête's avatar
import  
Olivier Crête committed
109
void
110
stun_message_free (StunMessage *msg);
111
G_GNUC_WARN_UNUSED_RESULT
112

Olivier Crête's avatar
import  
Olivier Crête committed
113
guint
114
stun_message_pack (StunMessage *msg, gchar **packed);
115
G_GNUC_WARN_UNUSED_RESULT
116

Olivier Crête's avatar
import  
Olivier Crête committed
117
118
gchar *
stun_message_dump (StunMessage *msg);
119
G_GNUC_WARN_UNUSED_RESULT
120

Olivier Crête's avatar
import  
Olivier Crête committed
121
StunMessage *
122
stun_message_unpack (guint length, gchar *s);
Olivier Crête's avatar
import  
Olivier Crête committed
123

Dafydd Harries's avatar
Dafydd Harries committed
124
125
G_END_DECLS

Olivier Crête's avatar
import  
Olivier Crête committed
126
127
#endif /* __STUN_H__ */