Menu

const for ApacheRequestRec::custom_response()

2001-11-17
2001-11-19
  • Kurt M. Brown

    Kurt M. Brown - 2001-11-17

    I suggest the change of:

       ApacheRequestRec::custom_response(int status, char *string)

    to

       ApacheRequestRec::custom_response(int status, const char* str)

    This would better support c++ std::string.

    An issue with the Apache api is that ap_custom_response() signature:

      void ap_custom_response(request_rec *r, int status, char *string)

    I changed the signature and recompiled without warnings or errors:

    Index: include/http_core.h

    RCS file: /home/cvspublic/httpd-2.0/include/http_core.h,v
    retrieving revision 1.52
    diff -r1.52 http_core.h
    257c257
    < AP_DECLARE(void) ap_custom_response(request_rec *r, int status, char *string);
    ---
    > AP_DECLARE(void) ap_custom_response(request_rec *r, int status, const char *string);

    Index: server/core.c

    RCS file: /home/cvspublic/httpd-2.0/server/core.c,v
    retrieving revision 1.98
    diff -r1.98 core.c
    946c946
    < AP_DECLARE(void) ap_custom_response(request_rec *r, int status, char *string)
    ---
    > AP_DECLARE(void) ap_custom_response(request_rec *r, int status, const char *string)

    So it would be best if the Apache api is modified. Otherwise, a portable
    c-style cast (char*) could be used in the member function.

    Apache developers might have chosen the non-const signature because
    ap_custom_response() uses apr_pstrcat() which does a char* cast instead of a
    const char*:

    Index: srclib/apr/strings/apr_strings.c

    RCS file: /home/cvspublic/apr/strings/apr_strings.c,v
    retrieving revision 1.22
    diff -r1.22 apr_strings.c
    126c126
    <     while ((cp = va_arg(adummy, char *)) != NULL) {
    ---
    >     while ((cp = va_arg(adummy, const char *)) != NULL) {
    146c146
    <     while ((argp = va_arg(adummy, char *)) != NULL) {
    ---
    >     while ((argp = va_arg(adummy, const char *)) != NULL) {

    The change to apr_pstrcat() is not required for the change to ap_custom_response().

     
    • John Sterling

      John Sterling - 2001-11-19

      I will try to submit the patch back to new-httpd ... in the meantime cpp_request will take in a const char *, and cast when calling the new-httpd method - that should shield cplusplus consumers from the mis-constification.

       
      • Kurt M. Brown

        Kurt M. Brown - 2001-11-19

        I submitted the change to ap_custom_response() and it was commited in the Apache-2.0 source.

         

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.