You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficserver.apache.org by "James Peach (JIRA)" <ji...@apache.org> on 2013/12/03 19:30:35 UTC

[jira] [Commented] (TS-2407) we should add API TSUrlStringGetBuf in ts.h

    [ https://issues.apache.org/jira/browse/TS-2407?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13838000#comment-13838000 ] 

James Peach commented on TS-2407:
---------------------------------

This patch seems ok in principle.

    - the documentation comment seems wrong since it discusses {{TSmalloc}}
    - how should the caller know how large a buffer to pass in?
    - what is the behavior if the buffer is too small?
    - is anything NUL-terminated?

Since this is a change to the public API, please follow the API review process, <https://cwiki.apache.org/confluence/display/TS/API+Review+Process>.

> we should add API TSUrlStringGetBuf in ts.h
> -------------------------------------------
>
>                 Key: TS-2407
>                 URL: https://issues.apache.org/jira/browse/TS-2407
>             Project: Traffic Server
>          Issue Type: Improvement
>          Components: HTTP
>            Reporter: Yu Qing
>            Assignee: Yu Qing
>         Attachments: 0001-TS-2407-add-API-TSUrlStringGetBuf.patch
>
>
> the existing API TSUrlStringGet call ats_malloc to malloc buffer for the url string. the caller should call ats_free to free the buffer. the API prototype is:
> tsapi char* TSUrlStringGet(TSMBuffer bufp, TSMLoc offset, int* length);
> call this API is expensive because dynamic memory alloc and free.
> we wish the buffer can be passed in. the new API prototype is:
>  tsapi char* TSUrlStringGetBuf(TSMBuffer bufp, TSMLoc offset, char *buff, int buf_size, int* length);
> the implements as:
> char *
> TSUrlStringGetBuf(TSMBuffer bufp, TSMLoc obj, char *buff, int buf_size, int* length)
> {
>   sdk_assert(sdk_sanity_check_mbuffer(bufp) == TS_SUCCESS);
>   sdk_assert(sdk_sanity_check_url_handle(obj) == TS_SUCCESS);
>   sdk_assert(sdk_sanity_check_null_ptr((void*)buff) == TS_SUCCESS);
>   sdk_assert(sdk_sanity_check_null_ptr((void*)length) == TS_SUCCESS);
>   URLImpl *url_impl = (URLImpl *) obj;
>   return url_string_get_buf(url_impl, buff, buf_size, length);
> }



--
This message was sent by Atlassian JIRA
(v6.1#6144)