Apache模块 请大家帮忙分析下哪里有有关问题
发布时间:2010-06-14 18:51:15 文章来源:www.iduyao.cn 采编人员:星星草
Apache模块 请大家帮忙分析下哪里有问题?
关于正则匹配的地方详细说下(http://localhost/preview?filename=a.dat)有什么方法把a.dat直接取出来给fn。
#include "httpd.h"
#include "http_config.h"
#include "http_protocol.h"
#include "ap_config.h"
#include "ap_regex.h"
#include "http_log.h"
/* The content handler */
static int preview_handler(request_rec *r)
{
char *fn;// = "/usr/local/httpd-2.3.8/include/httpd.h";
apr_file_t *f = NULL;
apr_status_t rv;
apr_size_t sz;
ap_regex_t *preg;
const char *regex = "filename=([^\\&]*)(.*)";
int regRet = AP_REG_NOMATCH;
int nmatch = AP_MAX_REG_MATCH;
ap_regmatch_t pmatch[nmatch];
if(strlen(r->args) == 0){
ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, NULL,r->server,"No args.");
return HTTP_INTERNAL_SERVER_ERROR;
}else{
if(ap_regcomp(preg,regex,0) == 0){
regRet = ap_regexec(preg,r->args,nmatch,pmatch,AP_REG_EXTENDED|AP_REG_ICASE);
ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, NULL,r->server,"Compile a regular expression. %s",regex);
}
else{
ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, NULL,r->server," Compile regular expression fail.");
ap_rputs("ap_regexec error.",r);
return DONE;
}
if(regRet == 0){
fn = (char *)calloc(pmatch[1].rm_eo - pmatch[1].rm_so + 1,sizeof(char));
memcpy(fn,r->args+pmatch[1].rm_so,pmatch[1].rm_eo - pmatch[1].rm_so);
rv = apr_file_open(&f,fn,APR_READ|APR_SENDFILE_ENABLED,APR_OS_DEFAULT,r->pool);
ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, NULL,r->server,"Get matched parameter : %s",fn);
ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, NULL,r->server,"File open status : %d",rv);
}else{
ap_rprintf(r,"Reguler Expression is not matched %s.\n",r->args);
ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, NULL,r->server,"Reguler Expression is not matched.");
return DONE;
}
}
if (strcmp(r->handler, "preview")) {
return DECLINED;
}
r->content_type = "text/html";
if (!r->header_only){
if(rv == APR_SUCCESS){
apr_finfo_t info;
apr_stat(&info,fn,APR_FINFO_SIZE,r->pool);
apr_size_t size = (apr_size_t)info.size;
if (APR_SUCCESS != ap_send_fd(f, r, 0, size, &sz)) {
return HTTP_INTERNAL_SERVER_ERROR;
}
apr_off_t fpos = sz;
while (1) {
/* flush output first */
ap_flush_conn(r->connection);
if (fpos < size) {
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。
其他相似内容:
-
有关 CAS 证书认证的 单点登录 问题
cas框架,证书jre中可以查看到证书,开启了ssl ,修改hosts为sso.wsria.com
输入https:\\sso.w...
-
后缀名问题
我写了一个登陆用的htmL页面 名字就叫:logion.html但是那个图标就是不变成浏览器的样子是一个未知图标,请问要怎么样解...
-
请问如何用java代码实现 ,重启tomcat6啊
请问如何用java代码实现 ,重启tomcat6啊
公司领导有个需求:需要在页面上实现一个按钮来重启...
-
IIS与TOMCAT的整合,函数不正确
我的服务器是IIS+TOMCAT整合起来的,里面挂有ASP、PHP和JAVA等网站,以前一直用得好好的,但前些天删除掉...
-
关闭tomcat时出错了!!!怎么回事
息: Stopping Coyote HTTP/1.1 on http-8080
Exception in thread "ShutdownHook" java.lang.NullPo...
-
struts2 Exception 求解答
严重: Exception starting filter strutsdangdang
java.lang.ClassNotFoundException: org.apache.str...
-
tomcat启动后无法访问localhost
2011-10-10 16:12:08 org.apache.catalina.core.AprLifecycleListener init
信息: The Apache To...
-
JSP页面和Servlet页面不在同一个目录下,JSP页面通过表单的action如何跳转到servlet页面
我的项目的名称是Exercise,然后在src目录...
-
Apache下的DocumentRoot目录指定
apache配置文件已经指定了,但是日志里面还是报错。
<VirtualHost *:8080>
DocumentRoot /var/...
-
如何让外网访问虚拟机上的apache
apache安装在虚拟机上,通过局域网的ip地址能够在本机上对它进行访问,但是在外网就不能通过外网的I...