Changeset 08c48d7 in mod_gnutls


Ignore:
Timestamp:
Jan 2, 2019, 3:22:48 PM (3 months ago)
Author:
Fiona Klute <fiona.klute@…>
Branches:
debian/master, master
Children:
4d38cbd
Parents:
c7710cf
Message:

Extract code for turning APR array of strings into gnutls_datum_t array

Having it as a separate function will allow sharing the code between
server and client (proxy) side ALPN proposal handling.

Location:
src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/gnutls_hooks.c

    rc7710cf r08c48d7  
    198198                  apr_array_pstrcat(ctxt->c->pool, pupgrades, ','));
    199199    gnutls_datum_t *alpn_protos =
    200         apr_palloc(ctxt->c->pool,
    201                    (pupgrades->nelts + 1) * sizeof(gnutls_datum_t));
    202     for (int i = 0; i < pupgrades->nelts; i++)
    203     {
    204         alpn_protos[i].data = (void *) APR_ARRAY_IDX(pupgrades, i, char *);
    205         alpn_protos[i].size =
    206             strnlen(APR_ARRAY_IDX(pupgrades, i, char *),
    207                     pupgrades->elt_size);
    208     }
     200        mgs_str_array_to_datum_array(pupgrades,
     201                                     ctxt->c->pool,
     202                                     pupgrades->nelts + 1);
    209203
    210204    /* Add the current (default) protocol at the end of the list */
  • src/gnutls_util.c

    rc7710cf r08c48d7  
    182182    gnutls_priority_deinit(default_prio);
    183183}
     184
     185
     186
     187gnutls_datum_t * mgs_str_array_to_datum_array(const apr_array_header_t *src,
     188                                              apr_pool_t *pool,
     189                                              const int min_elements)
     190{
     191    int num = min_elements > src->nelts ? min_elements : src->nelts;
     192    gnutls_datum_t *dest = apr_palloc(pool, num * sizeof(gnutls_datum_t));
     193    for (int i = 0; i < src->nelts; i++)
     194    {
     195        dest[i].data = (void *) APR_ARRAY_IDX(src, i, char *);
     196        dest[i].size = strlen(APR_ARRAY_IDX(src, i, char *));
     197    }
     198    return dest;
     199}
  • src/gnutls_util.h

    rc7710cf r08c48d7  
    9696void mgs_default_priority_deinit();
    9797
     98/**
     99 * Create a shallow copy of an APR array of `char *` into a new array
     100 * of gnutls_datum_t, filling `size` via `strlen()`. "Shallow copy"
     101 * means that the strings themselves are not copied, just the pointers
     102 * to them.
     103 *
     104 * @param src array to copy
     105 * @param pool allocate memory for the new array
     106 * @param min_elements allocate room for at least this many elements
     107 *
     108 * @return pointer to the first element of the new array
     109 */
     110gnutls_datum_t * mgs_str_array_to_datum_array(const apr_array_header_t *src,
     111                                              apr_pool_t *pool,
     112                                              const int min_elements);
     113
    98114#endif /* __MOD_GNUTLS_UTIL_H__ */
Note: See TracChangeset for help on using the changeset viewer.