diff --git a/lib/libwebsockets.c b/lib/libwebsockets.c index 2efa864e..ded1bc11 100644 --- a/lib/libwebsockets.c +++ b/lib/libwebsockets.c @@ -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) diff --git a/lib/libwebsockets.h b/lib/libwebsockets.h index 341d4b18..480c2d00 100644 --- a/lib/libwebsockets.h +++ b/lib/libwebsockets.h @@ -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