mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-09 00:00:04 +01:00
introduce lws_hdr_copy_fragment
This adds a public API variant of the header copy api that lets you choose which fragment you want copied. Normally you want the existing one that aggregates the fragments. But it can be useful to get each part in turn (that corresponds to the content provided by each duplicated header normally). Signed-off-by: Andy Green <andy.green@linaro.org>
This commit is contained in:
parent
6b5de70f4f
commit
566eb4381c
2 changed files with 37 additions and 1 deletions
|
@ -652,7 +652,7 @@ enum lws_token_indexes {
|
|||
};
|
||||
|
||||
struct lws_token_limits {
|
||||
unsigned short token_limit[WSI_TOKEN_COUNT];
|
||||
unsigned short token_limit[WSI_TOKEN_COUNT];
|
||||
};
|
||||
|
||||
/*
|
||||
|
@ -1622,9 +1622,22 @@ lws_get_library_version(void);
|
|||
LWS_VISIBLE LWS_EXTERN int
|
||||
lws_hdr_total_length(struct lws *wsi, enum lws_token_indexes h);
|
||||
|
||||
/*
|
||||
* copies the whole, aggregated header, even if it was delivered in
|
||||
* several actual headers piece by piece
|
||||
*/
|
||||
LWS_VISIBLE LWS_EXTERN int
|
||||
lws_hdr_copy(struct lws *wsi, char *dest, int len, enum lws_token_indexes h);
|
||||
|
||||
/*
|
||||
* copies only fragment frag_idx of a header. Normally this is only useful
|
||||
* to parse URI arguments like ?x=1&y=2, oken index WSI_TOKEN_HTTP_URI_ARGS
|
||||
* fragment 0 will contain "x=1" and fragment 1 "y=2"
|
||||
*/
|
||||
LWS_VISIBLE LWS_EXTERN int
|
||||
lws_hdr_copy_fragment(struct lws *wsi, char *dest, int len,
|
||||
enum lws_token_indexes h, int frag_idx);
|
||||
|
||||
/* get the active file operations struct */
|
||||
LWS_VISIBLE LWS_EXTERN struct lws_plat_file_ops *
|
||||
lws_get_fops(struct lws_context *context);
|
||||
|
|
|
@ -97,6 +97,29 @@ LWS_VISIBLE int lws_hdr_total_length(struct lws *wsi, enum lws_token_indexes h)
|
|||
return len;
|
||||
}
|
||||
|
||||
LWS_VISIBLE int lws_hdr_copy_fragment(struct lws *wsi, char *dst, int len,
|
||||
enum lws_token_indexes h, int frag_idx)
|
||||
{
|
||||
int n = 0;
|
||||
int f = wsi->u.hdr.ah->frag_index[h];
|
||||
|
||||
while (n < frag_idx) {
|
||||
f = wsi->u.hdr.ah->frags[f].nfrag;
|
||||
if (!f)
|
||||
return -1;
|
||||
n++;
|
||||
}
|
||||
|
||||
if (wsi->u.hdr.ah->frags[f].len >= (len - 1))
|
||||
return -1;
|
||||
|
||||
memcpy(dst, &wsi->u.hdr.ah->data[wsi->u.hdr.ah->frags[f].offset],
|
||||
wsi->u.hdr.ah->frags[f].len);
|
||||
dst[wsi->u.hdr.ah->frags[f].len] = '\0';
|
||||
|
||||
return wsi->u.hdr.ah->frags[f].len;
|
||||
}
|
||||
|
||||
LWS_VISIBLE int lws_hdr_copy(struct lws *wsi, char *dst, int len,
|
||||
enum lws_token_indexes h)
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue