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*:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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().
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.
I submitted the change to ap_custom_response() and it was commited in the Apache-2.0 source.