stun.h 3.54 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

9
10
typedef enum
{
Olivier Crête's avatar
import  
Olivier Crête committed
11
12
13
14
15
16
17
18
  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;

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

24
25
typedef enum
{
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
  // 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
55
56
57
58
59
60
61
} StunAttributeType;

typedef struct _StunAttribute StunAttribute;

struct _StunAttribute {
  guint16 type;
  guint16 length;
62
63
64
65
66
67
68
69
70
71
  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
72
73
74
75
76
77
78
79
80
81
};

typedef struct _StunMessage StunMessage;

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

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

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

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

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

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

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

104
void
105
stun_message_init (StunMessage *msg, guint type, const gchar *id);
106

107
G_GNUC_WARN_UNUSED_RESULT
108
StunMessage *
109
stun_message_new (guint type, const gchar *id, guint n_attributes);
110

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

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

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

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

126
127
128
StunAttribute *
stun_message_find_attribute (StunMessage *msg, StunAttributeType type);

Dafydd Harries's avatar
Dafydd Harries committed
129
130
G_END_DECLS

Olivier Crête's avatar
import  
Olivier Crête committed
131
132
#endif /* __STUN_H__ */