11cb0ef41Sopenharmony_ci/* 21cb0ef41Sopenharmony_ci * nghttp3 31cb0ef41Sopenharmony_ci * 41cb0ef41Sopenharmony_ci * Copyright (c) 2019 nghttp3 contributors 51cb0ef41Sopenharmony_ci * Copyright (c) 2016 nghttp2 contributors 61cb0ef41Sopenharmony_ci * 71cb0ef41Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining 81cb0ef41Sopenharmony_ci * a copy of this software and associated documentation files (the 91cb0ef41Sopenharmony_ci * "Software"), to deal in the Software without restriction, including 101cb0ef41Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish, 111cb0ef41Sopenharmony_ci * distribute, sublicense, and/or sell copies of the Software, and to 121cb0ef41Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to 131cb0ef41Sopenharmony_ci * the following conditions: 141cb0ef41Sopenharmony_ci * 151cb0ef41Sopenharmony_ci * The above copyright notice and this permission notice shall be 161cb0ef41Sopenharmony_ci * included in all copies or substantial portions of the Software. 171cb0ef41Sopenharmony_ci * 181cb0ef41Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 191cb0ef41Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 201cb0ef41Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 211cb0ef41Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 221cb0ef41Sopenharmony_ci * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 231cb0ef41Sopenharmony_ci * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 241cb0ef41Sopenharmony_ci * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 251cb0ef41Sopenharmony_ci */ 261cb0ef41Sopenharmony_ci#ifndef NGHTTP3_RCBUF_H 271cb0ef41Sopenharmony_ci#define NGHTTP3_RCBUF_H 281cb0ef41Sopenharmony_ci 291cb0ef41Sopenharmony_ci#ifdef HAVE_CONFIG_H 301cb0ef41Sopenharmony_ci# include <config.h> 311cb0ef41Sopenharmony_ci#endif /* HAVE_CONFIG_H */ 321cb0ef41Sopenharmony_ci 331cb0ef41Sopenharmony_ci#include <nghttp3/nghttp3.h> 341cb0ef41Sopenharmony_ci 351cb0ef41Sopenharmony_cistruct nghttp3_rcbuf { 361cb0ef41Sopenharmony_ci /* mem is the memory allocator that allocates memory for this 371cb0ef41Sopenharmony_ci object. */ 381cb0ef41Sopenharmony_ci const nghttp3_mem *mem; 391cb0ef41Sopenharmony_ci /* The pointer to the underlying buffer */ 401cb0ef41Sopenharmony_ci uint8_t *base; 411cb0ef41Sopenharmony_ci /* Size of buffer pointed by |base|. */ 421cb0ef41Sopenharmony_ci size_t len; 431cb0ef41Sopenharmony_ci /* Reference count */ 441cb0ef41Sopenharmony_ci int32_t ref; 451cb0ef41Sopenharmony_ci}; 461cb0ef41Sopenharmony_ci 471cb0ef41Sopenharmony_ci/* 481cb0ef41Sopenharmony_ci * Allocates nghttp3_rcbuf object with |size| as initial buffer size. 491cb0ef41Sopenharmony_ci * When the function succeeds, the reference count becomes 1. 501cb0ef41Sopenharmony_ci * 511cb0ef41Sopenharmony_ci * This function returns 0 if it succeeds, or one of the following 521cb0ef41Sopenharmony_ci * negative error codes: 531cb0ef41Sopenharmony_ci * 541cb0ef41Sopenharmony_ci * NGHTTP3_ERR_NOMEM: 551cb0ef41Sopenharmony_ci * Out of memory. 561cb0ef41Sopenharmony_ci */ 571cb0ef41Sopenharmony_ciint nghttp3_rcbuf_new(nghttp3_rcbuf **rcbuf_ptr, size_t size, 581cb0ef41Sopenharmony_ci const nghttp3_mem *mem); 591cb0ef41Sopenharmony_ci 601cb0ef41Sopenharmony_ci/* 611cb0ef41Sopenharmony_ci * Like nghttp3_rcbuf_new(), but initializes the buffer with |src| of 621cb0ef41Sopenharmony_ci * length |srclen|. This function allocates additional byte at the 631cb0ef41Sopenharmony_ci * end and puts '\0' into it, so that the resulting buffer could be 641cb0ef41Sopenharmony_ci * used as NULL-terminated string. Still (*rcbuf_ptr)->len equals to 651cb0ef41Sopenharmony_ci * |srclen|. 661cb0ef41Sopenharmony_ci * 671cb0ef41Sopenharmony_ci * This function returns 0 if it succeeds, or one of the following 681cb0ef41Sopenharmony_ci * negative error codes: 691cb0ef41Sopenharmony_ci * 701cb0ef41Sopenharmony_ci * NGHTTP3_ERR_NOMEM: 711cb0ef41Sopenharmony_ci * Out of memory. 721cb0ef41Sopenharmony_ci */ 731cb0ef41Sopenharmony_ciint nghttp3_rcbuf_new2(nghttp3_rcbuf **rcbuf_ptr, const uint8_t *src, 741cb0ef41Sopenharmony_ci size_t srclen, const nghttp3_mem *mem); 751cb0ef41Sopenharmony_ci 761cb0ef41Sopenharmony_ci/* 771cb0ef41Sopenharmony_ci * Frees |rcbuf| itself, regardless of its reference cout. 781cb0ef41Sopenharmony_ci */ 791cb0ef41Sopenharmony_civoid nghttp3_rcbuf_del(nghttp3_rcbuf *rcbuf); 801cb0ef41Sopenharmony_ci 811cb0ef41Sopenharmony_ci#endif /* NGHTTP3_RCBUF_H */ 82