apt-get install apache2-threaded-dev
apt-get install apache2-prefork-dev
uptags / config.m4 mod_uptags.c README
#include "apr_general.h"
#include "apr_lib.h"
#include "apr_buckets.h"
#include "apr_strings.h"
#include "ap_config.h"
#include "util_filter.h"
#include "httpd.h"
#include "http_config.h"
#include "http_request.h"
#include "http_core.h"
#include "http_protocol.h"
#include "http_log.h"
#include "http_main.h"
#include "util_script.h"
#include "http_core.h"
#include < string .h>
#include <stdio.h>
#include <ctype.h>
#include <sys/stat.h>
module AP_MODULE_DECLARE_DATA uptags_module;
* This source code was highlighted with Source Code Highlighter .
engine = On / Off - will allow you to enable / disable the work of the entire module.
typedef struct uptags_cfg {
int engine;
} uptags_cfg;
* This source code was highlighted with Source Code Highlighter .
/**
*
*
*/
static uptags_cfg *uptags_dconfig( const request_rec *r) {
return (uptags_cfg *) ap_get_module_config( r->per_dir_config, &uptags_module);
}
/**
*
*
*/
static uptags_cfg *uptags_sconfig( const server_rec *s) {
return (uptags_cfg *) ap_get_module_config( s->module_config, &uptags_module);
}
* This source code was highlighted with Source Code Highlighter .
/**
* -
*/
static void *uptags_create_dir_config( apr_pool_t *p, char *dirspec) {
uptags_cfg *cfg;
/**
*
*/
cfg = (uptags_cfg *) apr_pcalloc( p, sizeof ( uptags_cfg));
/**
*
*/
cfg->engine = 1;
return ( void *) cfg;
}
/**
*
*/
static void *uptags_create_server_config( apr_pool_t *p, server_rec *s) {
uptags_cfg *cfg;
cfg = (uptags_cfg *) apr_pcalloc( p, sizeof ( uptags_cfg));
cfg->engine = 1;
return ( void *) cfg;
}
* This source code was highlighted with Source Code Highlighter .
/**
*
*
*
*/
static void *uptags_merge_dir_config( apr_pool_t *p, void *parent_conf, void *newloc_conf) {
uptags_cfg *megred_conf = (uptags_cfg *) apr_pcalloc( p, sizeof ( uptags_cfg));
uptags_cfg *pconf = (uptags_cfg *) parent_conf;
uptags_cfg *nconf = (uptags_cfg *) newloc_conf;
/**
* ...
*
*/
return ( void *) merged_conf;
}
/**
*
*/
static void *uptags_merge_server_config( apr_pool_t *p, void *srv1conf, void *srv2conf) {
uptags_cfg *merged_config = (uptags_cfg *) apr_pcalloc( p, sizeof ( uptags_cfg));
uptags_cfg *s1conf = (uptags_cfg *) srv1conf;
uptags_cfg *s2conf = (uptags_cfg *) srv2conf;
/**
* ...
*
*/
return ( void *) merged_config;
}
* This source code was highlighted with Source Code Highlighter .
static command_rec uptags_directives[] = {
AP_INIT_FLAG(
"UptagsEngine" ,
ap_set_flag_slot,
( void *) APR_OFFSETOF( uptags_cfg, engine),
OR_OPTIONS,
"uptags module switcher"
),
{NULL}
};
* This source code was highlighted with Source Code Highlighter .
/**
*
*/
AP_DECLARE_NONSTD( const char *) ap_set_string_slot( cmd_parms *cmd, void *struct_ptr, const char *arg);
/**
*
*/
AP_DECLARE_NONSTD( const char *) ap_set_int_slot( cmd_parms *cmd, void *struct_ptr, const char *arg);
/**
* ,
*/
AP_DECLARE_NONSTD( const char *) ap_set_string_slot_lower( cmd_parms *cmd, void *struct_ptr, const char *arg);
/**
* ( On/Off)
*/
AP_DECLARE_NONSTD( const char *) ap_set_flag_slot( cmd_parms *cmd, void *struct_ptr, const char *arg);
/**
* , -
*/
AP_DECLARE_NONSTD( const char *) ap_set_file_slot( cmd_parms *cmd, void *struct_ptr, const char *arg);
/**
* , :
* AP_INIT_RAW_ARGS("Foo", ap_set_deprecated, NULL, OR_ALL,
* " Foo , Bar")
*/
AP_DECLARE_NONSTD( const char *) ap_set_deprecated( cmd_parms *cmd, void *struct_ptr, const char *arg);
* This source code was highlighted with Source Code Highlighter .
static int uptags_handler( request_rec *r) {
if (strcmp( r->handler, "uptags-handler" )) {
return DECLINED;
}
r->content_type = "text/html" ;
/**
* -
*/
if (r->header_only) {
return OK;
}
/**
* , :
*/
ap_rputs( DOCTYPE_HTML_4_0_STRICT, r);
ap_rputs( "<HTML>\n" , r);
ap_rputs( " <HEAD>\n" , r);
ap_rputs( " <TITLE>Example Title</TITLE>\n" , r);
ap_rputs( " </HEAD>\n" , r);
ap_rputs( " <BODY>\n" , r);
ap_rputs( " <H1>Example content</H1>\n" , r);
ap_rputs( " <P>Example text</P>\n" , r);
ap_rputs( " </BODY>\n" , r);
ap_rputs( "</HTML>\n" , r);
return OK;
}
* This source code was highlighted with Source Code Highlighter .
<Location / uptags-handler-example> SetHandler uptags-handler </ Location>
/**
*
*/
static void uptags_in_filter( request_rec *r) {
/**
* ,
*/
ap_add_output_filter( "Uptags" , NULL, r, r->connection);
}
/**
* -
*/
static apr_status_t uptags_out_filter( ap_filter_t *f, apr_bucket_brigade *pbbIn) {
request_rec *r = f->r;
conn_rec *c = r->connection;
apr_bucket *pbktIn;
apr_bucket_brigade *pbbOut;
uptags_cfg *cfg = uptags_dconfig( f->r);
/**
* , . -
* , HTML
*/
if (!cfg->engine || strcmp( r->content_type, "text/html" ) != 0) {
return ap_pass_brigade( f->next, pbbIn);
}
/* */
pbbOut = apr_brigade_create( r->pool, c->bucket_alloc);
/**
*
*/
for (pbktIn = APR_BRIGADE_FIRST( pbbIn); pbktIn != APR_BRIGADE_SENTINEL( pbbIn); pbktIn = APR_BUCKET_NEXT( pbktIn)) {
const char *data;
apr_size_t len;
char *buf;
apr_bucket *pbktOut;
/* "" - - - */
if (APR_BUCKET_IS_EOS( pbktIn)) {
apr_bucket *pbktEOS = apr_bucket_eos_create( c->bucket_alloc);
APR_BRIGADE_INSERT_TAIL( pbbOut,pbktEOS);
continue ;
}
/* */
apr_bucket_read( pbktIn, &data, &len, APR_NONBLOCK_READ);
/**
*
* ! - .
* .
*/
buf = apr_bucket_alloc( len, c->bucket_alloc);
memset( buf, 0, sizeof ( buf));
uptags_tags_to_uppercase( data, buf);
/* */
pbktOut = apr_bucket_heap_create( buf, len, apr_bucket_free, c->bucket_alloc);
APR_BRIGADE_INSERT_TAIL( pbbOut, pbktOut);
}
apr_brigade_cleanup( pbbIn);
return ap_pass_brigade( f->next, pbbOut);
}
* This source code was highlighted with Source Code Highlighter .
/**
*
*/
void uptags_tags_to_uppercase( const char *data, char *str) {
int i, s = strlen( data), tag_opened = 0;
for (i = 0; i < s; i++) {
str[i] = data[i];
if (str[i] == '<' ) {
tag_opened = 1;
} else if (str[i] == '>' ) {
tag_opened = 0;
}
if (tag_opened && str[i] != '\0' ) {
str[i] = apr_toupper( str[i]);
}
}
}
* This source code was highlighted with Source Code Highlighter .
/**
* Apache
*/
module AP_MODULE_DECLARE_DATA uptags_module = {
STANDARD20_MODULE_STUFF,
uptags_create_dir_config, /* */
NULL, /* */
uptags_create_server_config, /* */
NULL, /* */
uptags_directives, /* */
uptags_register_hooks /* */
};
* This source code was highlighted with Source Code Highlighter .
/**
*
*/
static void uptags_register_hooks( apr_pool_t *p) {
ap_hook_insert_filter( uptags_in_filter, NULL, NULL, APR_HOOK_MIDDLE);
ap_register_output_filter( "Uptags" , uptags_out_filter, NULL, AP_FTYPE_RESOURCE);
}
* This source code was highlighted with Source Code Highlighter .
apxs2 -c mod_uppertags.c
LoadModule uptags_module /usr/lib/apache2/modules/mod_uptags.so <IfModule mod_uptags.c> Uptagsengine on </ IfModule>
/etc/init.d/apache2 restart
APACHE_MODPATH_INIT (uptags) APACHE_MODULE (uptags, reformatting all HTML tags to upercase,,, no) APACHE_MODPATH_FINISH
./configure --enable-uptags
Source: https://habr.com/ru/post/50909/