mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-09 00:00:04 +01:00
http: custom hdr: add custom name iterator
This commit is contained in:
parent
4d81fee54f
commit
f6954e432c
2 changed files with 45 additions and 0 deletions
|
@ -494,6 +494,26 @@ LWS_VISIBLE LWS_EXTERN int
|
|||
lws_hdr_custom_copy(struct lws *wsi, char *dst, int len, const char *name,
|
||||
int nlen);
|
||||
|
||||
typedef void (*lws_hdr_custom_fe_cb_t)(const char *name, int nlen, void *opaque);
|
||||
/**
|
||||
* lws_hdr_custom_name_foreach() - Iterate the custom header names
|
||||
*
|
||||
* \param wsi: websocket connection
|
||||
* \param cb: callback for each custom header name
|
||||
* \param opaque: ignored by lws except to pass to callback
|
||||
*
|
||||
* Lws knows about 100 common http headers, and parses them into indexes when
|
||||
* it recognizes them. When it meets a header that it doesn't know, it stores
|
||||
* the name and value directly, and you can look them up using
|
||||
* lws_hdr_custom_length() and lws_hdr_custom_copy().
|
||||
*
|
||||
* This api returns -1 on error else 0. Use lws_hdr_custom_copy() to get the
|
||||
* values of headers. Lws must be built with LWS_WITH_CUSTOM_HEADERS (on by
|
||||
* default) to use this api.
|
||||
*/
|
||||
LWS_VISIBLE LWS_EXTERN int
|
||||
lws_hdr_custom_name_foreach(struct lws *wsi, lws_hdr_custom_fe_cb_t cb, void *opaque);
|
||||
|
||||
/**
|
||||
* lws_get_urlarg_by_name_safe() - get copy and return length of y for x=y urlargs
|
||||
*
|
||||
|
|
|
@ -656,6 +656,31 @@ lws_hdr_custom_copy(struct lws *wsi, char *dst, int len, const char *name,
|
|||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int
|
||||
lws_hdr_custom_name_foreach(struct lws *wsi, lws_hdr_custom_fe_cb_t cb,
|
||||
void *custom)
|
||||
{
|
||||
ah_data_idx_t ll;
|
||||
|
||||
if (!wsi->http.ah || wsi->mux_substream)
|
||||
return -1;
|
||||
|
||||
ll = wsi->http.ah->unk_ll_head;
|
||||
|
||||
while (ll) {
|
||||
if (ll >= wsi->http.ah->data_length)
|
||||
return -1;
|
||||
|
||||
cb(&wsi->http.ah->data[ll + UHO_NAME],
|
||||
lws_ser_ru16be((uint8_t *)&wsi->http.ah->data[ll + UHO_NLEN]),
|
||||
custom);
|
||||
|
||||
ll = lws_ser_ru32be((uint8_t *)&wsi->http.ah->data[ll + UHO_LL]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
char *lws_hdr_simple_ptr(struct lws *wsi, enum lws_token_indexes h)
|
||||
|
|
Loading…
Add table
Reference in a new issue