1
/* Copyright 2000-2004 The Apache Software Foundation
3
* Licensed under the Apache License, Version 2.0 (the "License");
4
* you may not use this file except in compliance with the License.
5
* You may obtain a copy of the License at
7
* http://www.apache.org/licenses/LICENSE-2.0
9
* Unless required by applicable law or agreed to in writing, software
10
* distributed under the License is distributed on an "AS IS" BASIS,
11
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
* See the License for the specific language governing permissions and
13
* limitations under the License.
1
16
#ifndef MODPERL_UTIL_H
2
17
#define MODPERL_UTIL_H
50
65
#define MP_magical_tie(sv, mg_flags) \
51
66
SvFLAGS((SV*)sv) |= mg_flags
69
/* XXX: this should be removed */
53
70
#define MP_FAILURE_CROAK(rc_run) do { \
54
71
apr_status_t rc = rc_run; \
55
72
if (rc != APR_SUCCESS) { \
56
Perl_croak(aTHX_ modperl_apr_strerror(rc)); \
73
Perl_croak(aTHX_ modperl_error_strerror(aTHX_ rc)); \
60
77
/* check whether the response phase has been initialized already */
61
78
#define MP_CHECK_WBUCKET_INIT(func) \
62
79
if (!rcfg->wbucket) { \
63
Perl_croak(aTHX_ "%s: " func " can't be called before the response phase", MP_FUNC); \
80
Perl_croak(aTHX_ "%s: " func " can't be called " \
81
"before the response phase", MP_FUNC); \
66
84
/* turn off cgi header parsing. in case we are already inside
86
104
MP_INLINE SV *modperl_perl_sv_setref_uv(pTHX_ SV *rv,
87
105
const char *classname, UV uv);
89
apr_pool_t *modperl_sv2pool(pTHX_ SV *obj);
91
char *modperl_apr_strerror(apr_status_t rv);
93
107
int modperl_errsv(pTHX_ int status, request_rec *r, server_rec *s);
95
109
int modperl_require_module(pTHX_ const char *pv, int logfailure);
156
170
void modperl_clear_symtab(pTHX_ HV *symtab);
172
char *modperl_file2package(apr_pool_t *p, const char *file);
174
SV *modperl_server_root_relative(pTHX_ SV *sv, const char *fname);
177
* convert a compiled *CV ref to its original source code
178
* @param p pool object (with a shortest possible life scope)
179
* @param cv compiled *CV
180
* @return string of original source code
182
char *modperl_coderef2text(pTHX_ apr_pool_t *p, CV *cv);
159
186
void modperl_apr_table_dump(pTHX_ apr_table_t *table, char *name);
188
/* dump the contents of PL_modglobal */
189
void modperl_perl_modglobal_dump(pTHX);
162
char *modperl_file2package(apr_pool_t *p, const char *file);
193
#if defined(MP_TRACE) && defined(APR_HAS_THREADS)
194
#define MP_TRACEf_TID "/tid 0x%lx"
195
#define MP_TRACEv_TID (unsigned long)apr_os_thread_current()
196
#define MP_TRACEv_TID_ MP_TRACEv_TID,
197
#define MP_TRACEv__TID ,MP_TRACEv_TID
199
#define MP_TRACEf_TID
200
#define MP_TRACEv_TID
201
#define MP_TRACEv_TID_
202
#define MP_TRACEv__TID
203
#endif /* APR_HAS_THREADS */
205
#if defined(MP_TRACE) && defined(USE_ITHREADS)
206
#define MP_TRACEf_PERLID "/perl id 0x%lx"
207
#define MP_TRACEv_PERLID (unsigned long)my_perl
208
#define MP_TRACEv_PERLID_ MP_TRACEv_PERLID,
209
#define MP_TRACEv__PERLID ,MP_TRACEv_PERLID
211
#define MP_TRACEf_PERLID
212
#define MP_TRACEv_PERLID
213
#define MP_TRACEv_PERLID_
214
#define MP_TRACEv__PERLID
215
#endif /* USE_ITHREADS */
217
/* dumping hundreds of lines in the trace, makes it less useful. Get a
218
* string chunk of MP_TRACE_STR_LEN bytes or less. Not too long so it
219
* won't wrap when posted in email. Notice that we copy 'count' bytes
220
* of the string even if count < MP_TRACE_STR_LEN, because the 'str'
221
* buffer doesn't necessarily have \0 terminator at 'count'. As this
222
* is for debug tracing, not to be used in production, it doesn't make
223
* any difference if it's not efficient.
225
#define MP_TRACE_STR_LEN 35
226
#define MP_TRACE_STR_TRUNC(p, str, count) \
227
count < MP_TRACE_STR_LEN \
228
? (char *)apr_pstrmemdup(p, str, count) \
229
: (char *)apr_psprintf(p, "%s...", \
230
apr_pstrmemdup(p, str, MP_TRACE_STR_LEN))
163
232
#endif /* MODPERL_UTIL_H */