Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
libnice
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
libnice
Commits
8eab0fac
Commit
8eab0fac
authored
Nov 04, 2009
by
Youness Alaoui
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a stun_agent_set_software API and correctly append only the first 128 utf-8 characters
parent
9c56802a
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
82 additions
and
12 deletions
+82
-12
stun/stun5389.c
stun/stun5389.c
+30
-4
stun/stun5389.h
stun/stun5389.h
+2
-1
stun/stunagent.c
stun/stunagent.c
+20
-6
stun/stunagent.h
stun/stunagent.h
+30
-1
No files found.
stun/stun5389.c
View file @
8eab0fac
...
@@ -53,6 +53,21 @@
...
@@ -53,6 +53,21 @@
#include "stuncrc32.h"
#include "stuncrc32.h"
#include "stunmessage.h"
#include "stunmessage.h"
static
const
char
utf8_skip_data
[
256
]
=
{
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
2
,
2
,
2
,
2
,
2
,
2
,
2
,
2
,
2
,
2
,
2
,
2
,
2
,
2
,
2
,
2
,
2
,
2
,
2
,
2
,
2
,
2
,
2
,
2
,
2
,
2
,
2
,
2
,
2
,
2
,
2
,
2
,
3
,
3
,
3
,
3
,
3
,
3
,
3
,
3
,
3
,
3
,
3
,
3
,
3
,
3
,
3
,
3
,
4
,
4
,
4
,
4
,
4
,
4
,
4
,
4
,
5
,
5
,
5
,
5
,
6
,
6
,
1
,
1
};
#define next_utf8_char(p) (char *)((p) + \
utf8_skip_data[*(const unsigned char *)(p)])
uint32_t
stun_fingerprint
(
const
uint8_t
*
msg
,
size_t
len
,
uint32_t
stun_fingerprint
(
const
uint8_t
*
msg
,
size_t
len
,
bool
wlm2009_stupid_crc32_typo
)
bool
wlm2009_stupid_crc32_typo
)
{
{
...
@@ -81,10 +96,21 @@ bool stun_message_has_cookie (const StunMessage *msg)
...
@@ -81,10 +96,21 @@ bool stun_message_has_cookie (const StunMessage *msg)
}
}
StunMessageReturn
stun_message_append_software
(
StunMessage
*
msg
)
StunMessageReturn
stun_message_append_software
(
StunMessage
*
msg
,
const
char
*
software
)
{
{
static
const
char
software
[]
=
PACKAGE_STRING
;
int
len
=
0
;
// assert (strlen (software) < 128);
const
char
*
ptr
=
NULL
;
if
(
software
==
NULL
)
software
=
PACKAGE_STRING
;
ptr
=
software
;
while
(
*
ptr
&&
len
<
128
)
{
ptr
=
next_utf8_char
(
ptr
);
len
++
;
}
return
stun_message_append_string
(
msg
,
STUN_ATTRIBUTE_SOFTWARE
,
software
);
return
stun_message_append_bytes
(
msg
,
STUN_ATTRIBUTE_SOFTWARE
,
software
,
ptr
-
software
);
}
}
stun/stun5389.h
View file @
8eab0fac
...
@@ -60,7 +60,8 @@
...
@@ -60,7 +60,8 @@
uint32_t
stun_fingerprint
(
const
uint8_t
*
msg
,
size_t
len
,
uint32_t
stun_fingerprint
(
const
uint8_t
*
msg
,
size_t
len
,
bool
wlm2009_stupid_crc32_typo
);
bool
wlm2009_stupid_crc32_typo
);
StunMessageReturn
stun_message_append_software
(
StunMessage
*
msg
);
StunMessageReturn
stun_message_append_software
(
StunMessage
*
msg
,
const
char
*
software
);
#endif
/* _STUN_5389_H */
#endif
/* _STUN_5389_H */
...
...
stun/stunagent.c
View file @
8eab0fac
...
@@ -59,6 +59,7 @@ void stun_agent_init (StunAgent *agent, const uint16_t *known_attributes,
...
@@ -59,6 +59,7 @@ void stun_agent_init (StunAgent *agent, const uint16_t *known_attributes,
agent
->
known_attributes
=
(
uint16_t
*
)
known_attributes
;
agent
->
known_attributes
=
(
uint16_t
*
)
known_attributes
;
agent
->
compatibility
=
compatibility
;
agent
->
compatibility
=
compatibility
;
agent
->
usage_flags
=
usage_flags
;
agent
->
usage_flags
=
usage_flags
;
agent
->
software_attribute
=
NULL
;
for
(
i
=
0
;
i
<
STUN_AGENT_MAX_SAVED_IDS
;
i
++
)
{
for
(
i
=
0
;
i
<
STUN_AGENT_MAX_SAVED_IDS
;
i
++
)
{
agent
->
sent_ids
[
i
].
valid
=
FALSE
;
agent
->
sent_ids
[
i
].
valid
=
FALSE
;
...
@@ -358,6 +359,12 @@ bool stun_agent_init_request (StunAgent *agent, StunMessage *msg,
...
@@ -358,6 +359,12 @@ bool stun_agent_init_request (StunAgent *agent, StunMessage *msg,
uint32_t
cookie
=
htonl
(
STUN_MAGIC_COOKIE
);
uint32_t
cookie
=
htonl
(
STUN_MAGIC_COOKIE
);
memcpy
(
msg
->
buffer
+
STUN_MESSAGE_TRANS_ID_POS
,
&
cookie
,
sizeof
(
cookie
));
memcpy
(
msg
->
buffer
+
STUN_MESSAGE_TRANS_ID_POS
,
&
cookie
,
sizeof
(
cookie
));
}
}
if
(
agent
->
software_attribute
!=
NULL
||
((
agent
->
compatibility
==
STUN_COMPATIBILITY_RFC5389
||
agent
->
compatibility
==
STUN_COMPATIBILITY_WLM2009
)
&&
agent
->
usage_flags
&
STUN_AGENT_USAGE_ADD_SOFTWARE
))
{
stun_message_append_software
(
msg
,
agent
->
software_attribute
);
}
}
}
return
ret
;
return
ret
;
...
@@ -416,10 +423,11 @@ bool stun_agent_init_response (StunAgent *agent, StunMessage *msg,
...
@@ -416,10 +423,11 @@ bool stun_agent_init_response (StunAgent *agent, StunMessage *msg,
if
(
stun_message_init
(
msg
,
STUN_RESPONSE
,
if
(
stun_message_init
(
msg
,
STUN_RESPONSE
,
stun_message_get_method
(
request
),
id
))
{
stun_message_get_method
(
request
),
id
))
{
if
((
agent
->
compatibility
==
STUN_COMPATIBILITY_RFC5389
||
if
(
agent
->
software_attribute
!=
NULL
||
((
agent
->
compatibility
==
STUN_COMPATIBILITY_RFC5389
||
agent
->
compatibility
==
STUN_COMPATIBILITY_WLM2009
)
&&
agent
->
compatibility
==
STUN_COMPATIBILITY_WLM2009
)
&&
agent
->
usage_flags
&
STUN_AGENT_USAGE_ADD_SOFTWARE
)
{
agent
->
usage_flags
&
STUN_AGENT_USAGE_ADD_SOFTWARE
)
)
{
stun_message_append_software
(
msg
);
stun_message_append_software
(
msg
,
agent
->
software_attribute
);
}
}
return
TRUE
;
return
TRUE
;
}
}
...
@@ -452,10 +460,11 @@ bool stun_agent_init_error (StunAgent *agent, StunMessage *msg,
...
@@ -452,10 +460,11 @@ bool stun_agent_init_error (StunAgent *agent, StunMessage *msg,
if
(
stun_message_init
(
msg
,
STUN_ERROR
,
if
(
stun_message_init
(
msg
,
STUN_ERROR
,
stun_message_get_method
(
request
),
id
))
{
stun_message_get_method
(
request
),
id
))
{
if
((
agent
->
compatibility
==
STUN_COMPATIBILITY_RFC5389
||
if
(
agent
->
software_attribute
!=
NULL
||
((
agent
->
compatibility
==
STUN_COMPATIBILITY_RFC5389
||
agent
->
compatibility
==
STUN_COMPATIBILITY_WLM2009
)
&&
agent
->
compatibility
==
STUN_COMPATIBILITY_WLM2009
)
&&
agent
->
usage_flags
&
STUN_AGENT_USAGE_ADD_SOFTWARE
)
{
agent
->
usage_flags
&
STUN_AGENT_USAGE_ADD_SOFTWARE
)
)
{
stun_message_append_software
(
msg
);
stun_message_append_software
(
msg
,
agent
->
software_attribute
);
}
}
if
(
stun_message_append_error
(
msg
,
err
)
==
STUN_MESSAGE_RETURN_SUCCESS
)
{
if
(
stun_message_append_error
(
msg
,
err
)
==
STUN_MESSAGE_RETURN_SUCCESS
)
{
return
TRUE
;
return
TRUE
;
...
@@ -674,3 +683,8 @@ stun_agent_find_unknowns (StunAgent *agent, const StunMessage * msg,
...
@@ -674,3 +683,8 @@ stun_agent_find_unknowns (StunAgent *agent, const StunMessage * msg,
stun_debug
(
"STUN unknown: %u mandatory attribute(s)!
\n
"
,
count
);
stun_debug
(
"STUN unknown: %u mandatory attribute(s)!
\n
"
,
count
);
return
count
;
return
count
;
}
}
void
stun_agent_set_software
(
StunAgent
*
agent
,
char
*
software
)
{
agent
->
software_attribute
=
software
;
}
stun/stunagent.h
View file @
8eab0fac
...
@@ -138,7 +138,10 @@ typedef enum {
...
@@ -138,7 +138,10 @@ typedef enum {
* @STUN_AGENT_USAGE_USE_FINGERPRINT: The agent should add the FINGERPRINT
* @STUN_AGENT_USAGE_USE_FINGERPRINT: The agent should add the FINGERPRINT
* attribute to the STUN messages it creates.
* attribute to the STUN messages it creates.
* @STUN_AGENT_USAGE_ADD_SOFTWARE: The agent should add the SOFTWARE attribute
* @STUN_AGENT_USAGE_ADD_SOFTWARE: The agent should add the SOFTWARE attribute
* to the STUN messages it creates
* to the STUN messages it creates. Calling nice_agent_set_software() will have
* the same effect as enabling this Usage. STUN Indications do not have the
* SOFTWARE attributes added to them though. The SOFTWARE attribute is only
* added for the RFC5389 and WLM2009 compatibility modes.
* @STUN_AGENT_USAGE_IGNORE_CREDENTIALS: The agent should ignore any credentials
* @STUN_AGENT_USAGE_IGNORE_CREDENTIALS: The agent should ignore any credentials
* in the STUN messages it receives (the MESSAGE-INTEGRITY attribute
* in the STUN messages it receives (the MESSAGE-INTEGRITY attribute
* will never be validated by stun_agent_validate())
* will never be validated by stun_agent_validate())
...
@@ -184,6 +187,7 @@ struct stun_agent_t {
...
@@ -184,6 +187,7 @@ struct stun_agent_t {
StunAgentSavedIds
sent_ids
[
STUN_AGENT_MAX_SAVED_IDS
];
StunAgentSavedIds
sent_ids
[
STUN_AGENT_MAX_SAVED_IDS
];
uint16_t
*
known_attributes
;
uint16_t
*
known_attributes
;
StunAgentUsageFlags
usage_flags
;
StunAgentUsageFlags
usage_flags
;
char
*
software_attribute
;
};
};
/**
/**
...
@@ -470,4 +474,29 @@ size_t stun_agent_finish_message (StunAgent *agent, StunMessage *msg,
...
@@ -470,4 +474,29 @@ size_t stun_agent_finish_message (StunAgent *agent, StunMessage *msg,
bool
stun_agent_forget_transaction
(
StunAgent
*
agent
,
StunTransactionId
id
);
bool
stun_agent_forget_transaction
(
StunAgent
*
agent
,
StunTransactionId
id
);
/**
* stun_agent_set_software:
* @agent: The #StunAgent
* @software: The value of the SOFTWARE attribute to add.
*
* This function will set the value of the SOFTWARE attribute to be added to
* STUN requests, responses and error responses.
* <para>
* Calling this function will automatically enable the addition of the SOFTWARE
* attribute for RFC5389 and WLM2009 compatibility modes.
* </para>
* <note>
<para>
The @software argument must be in UTF-8 encoding and only the first
128 characters will be sent.
</para>
<para>
The value of the @software argument must stay valid throughout the life of
the StunAgent's life. Do not free its content.
</para>
</note>
*
*/
void
stun_agent_set_software
(
StunAgent
*
agent
,
char
*
software
);
#endif
/* _STUN_AGENT_H */
#endif
/* _STUN_AGENT_H */
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment