lws_get_urlarg_by_name
Adds a convenient way to directly get the value of a URL argument like ...?x=y&v=1, regardless of position in the parameter list. Signed-off-by: Andy Green <andy@warmcat.com>
This commit is contained in:
parent
4889566d5d
commit
1dca916bec
2 changed files with 31 additions and 0 deletions
|
@ -557,6 +557,34 @@ lws_close_free_wsi_final(struct lws *wsi)
|
|||
lws_free_wsi(wsi);
|
||||
}
|
||||
|
||||
/**
|
||||
* lws_get_urlarg_by_name() - return pointer to arg value if present
|
||||
* @wsi: the connection to check
|
||||
* @name: the arg name, like "token="
|
||||
* @buf: the buffer to receive the urlarg (including the name= part)
|
||||
* @len: the length of the buffer to receive the urlarg
|
||||
*
|
||||
* Returns NULL if not found or a pointer inside @buf to just after the
|
||||
* name= part.
|
||||
*/
|
||||
|
||||
LWS_VISIBLE LWS_EXTERN const char *
|
||||
lws_get_urlarg_by_name(struct lws *wsi, const char *name, char *buf, int len)
|
||||
{
|
||||
int n = 0, sl = strlen(name);
|
||||
|
||||
while (lws_hdr_copy_fragment(wsi, buf, len,
|
||||
WSI_TOKEN_HTTP_URI_ARGS, n) >= 0) {
|
||||
|
||||
if (!strncmp(buf, name, sl))
|
||||
return buf + sl;
|
||||
|
||||
n++;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#if LWS_POSIX
|
||||
LWS_VISIBLE int
|
||||
interface_to_sa(struct lws_context *context, const char *ifname, struct sockaddr_in *addr, size_t addrlen)
|
||||
|
|
|
@ -2077,6 +2077,9 @@ LWS_VISIBLE LWS_EXTERN int
|
|||
lws_hdr_copy_fragment(struct lws *wsi, char *dest, int len,
|
||||
enum lws_token_indexes h, int frag_idx);
|
||||
|
||||
LWS_VISIBLE LWS_EXTERN const char *
|
||||
lws_get_urlarg_by_name(struct lws *wsi, const char *name, char *buf, int len);
|
||||
|
||||
|
||||
/* get the active file operations struct */
|
||||
LWS_VISIBLE LWS_EXTERN struct lws_plat_file_ops * LWS_WARN_UNUSED_RESULT
|
||||
|
|
Loading…
Add table
Reference in a new issue