"Fossies" - the Fresh Open Source Software Archive

Member "mod_ftp-0.9.6/modules/ftp/mod_ftp_example.c" (17 Aug 2009, 3118 Bytes) of package /linux/www/apache_httpd_modules/old/mod_ftp-0.9.6-beta.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "mod_ftp_example.c" see the Fossies "Dox" file reference documentation.

    1 /* Licensed to the Apache Software Foundation (ASF) under one or more
    2  * contributor license agreements.  See the NOTICE file distributed with
    3  * this work for additional information regarding copyright ownership.
    4  * The ASF licenses this file to You under the Apache License, Version 2.0
    5  * (the "License"); you may not use this file except in compliance with
    6  * the License.  You may obtain a copy of the License at
    7  *
    8  *     http://www.apache.org/licenses/LICENSE-2.0
    9  *
   10  * Unless required by applicable law or agreed to in writing, software
   11  * distributed under the License is distributed on an "AS IS" BASIS,
   12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   13  * See the License for the specific language governing permissions and
   14  * limitations under the License.
   15  */
   16 
   17 /*
   18  * Original Copyright (c) 2005 Covalent Technologies
   19  *
   20  * FTP Protocol module for Apache 2.0
   21  */
   22 
   23 /*
   24  * A simple example of how to override a commmand.  The FTP hooks will
   25  * run all handlers for a command, until a module returns anything other
   26  * than DECLINED.  All core commands are registered as FTP_HOOK_LAST, so
   27  * any module can override using FTP_HOOK_MIDDLE or FTP_HOOK_FIRST.
   28  *
   29  * Implements simple SITE PING and SITE ECHO commands
   30  */
   31 
   32 #include "mod_ftp.h"
   33 #include "apr_strings.h"
   34 
   35 extern AP_MODULE_DECLARE_DATA module ftp_example_module;
   36 
   37 static int mod_ftp_cmd_site(request_rec *r, const char *arg)
   38 {
   39     ftp_connection *fc = ftp_get_module_config(r->connection->conn_config);
   40 
   41     /* Only handling SITE ECHO or SITE PING, let all others fall through
   42      * to another registered command handler.
   43      */
   44     if ((strncasecmp(arg, "ECHO", 4) && strncasecmp(arg, "PING", 4))
   45             || (arg[4] && arg[4] != ' '))
   46         return DECLINED;
   47 
   48     if (!strncasecmp(arg, "PING", 4))
   49     {
   50         for (arg += 4; *arg == ' '; ++arg) 
   51             /* noop */;
   52 
   53         if (*arg) {
   54             fc->response_notes = "SITE PING accepts no parameters";
   55             return FTP_REPLY_SYNTAX_ERROR;
   56         }
   57 
   58         fc->response_notes = "PONG";
   59     }
   60     else /* !strncasecmp(arg, "ECHO", 4) */
   61     {
   62         fc->response_notes = ftp_escape_control_text(arg + 4, r->pool);
   63     }
   64     return FTP_REPLY_COMMAND_OK;
   65 }
   66 
   67 static int example_pre_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp)
   68 {
   69     ftp_hook_cmd("SITE", mod_ftp_cmd_site, FTP_HOOK_MIDDLE,
   70                  FTP_NEED_LOGIN | FTP_TAKE1 | FTP_KEEP_WHITESPACE,
   71                  "<sp> [ PING | ECHO <sp> message ]");
   72     return OK;
   73 }
   74 
   75 static void register_hooks(apr_pool_t *p)
   76 {
   77     ap_hook_pre_config(example_pre_config, NULL, NULL, APR_HOOK_MIDDLE);
   78 }
   79 
   80 AP_MODULE_DECLARE_DATA module ftp_example_module = {
   81     STANDARD20_MODULE_STUFF,
   82     NULL,                       /* create per-directory config structure */
   83     NULL,                       /* merge per-directory config structures */
   84     NULL,                       /* create per-server config structure */
   85     NULL,                       /* merge per-server config structures */
   86     NULL,                       /* command apr_table_t */
   87     register_hooks              /* register hooks */
   88 };