httpd-test-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From do...@apache.org
Subject cvs commit: httpd-test/perl-framework/t/protocol nntp-like.t
Date Fri, 16 Nov 2001 23:47:45 GMT
dougm       01/11/16 15:47:45

  Added:       perl-framework/c-modules/nntp_like .cvsignore
                        mod_nntp_like.c
               perl-framework/t/protocol nntp-like.t
  Log:
  add a test for nntp-like protocols
  
  Revision  Changes    Path
  1.1                  httpd-test/perl-framework/c-modules/nntp_like/.cvsignore
  
  Index: .cvsignore
  ===================================================================
  Makefile
  .libs
  *.lo
  *.slo
  *.la
  
  
  
  1.1                  httpd-test/perl-framework/c-modules/nntp_like/mod_nntp_like.c
  
  Index: mod_nntp_like.c
  ===================================================================
  #define HTTPD_TEST_REQUIRE_APACHE 2
  
  /*
   * purpose of this module is to test protocol modules that need to 
   * send data to the client before reading any request data.
   * in this case, mod_ssl needs to handshake before sending data to the client.
   * t/protocol/nntp-like.t tests both with and without ssl
   * to make sure the protocol code works in both cases.
   */
  
  #if CONFIG_FOR_HTTPD_TEST
  
  <VirtualHost mod_nntp_like>
      NNTPLike On
  </VirtualHost>
  
  <VirtualHost mod_nntp_like_ssl>
      NNTPLike On
      <IfModule @ssl_module@>
           SSLEngine On
      </IfModule>
  </VirtualHost>
  
  #endif
  
  #include "httpd.h"
  #include "http_config.h"
  #include "http_protocol.h"
  #include "http_connection.h"
  #include "http_request.h"
  #include "http_log.h"
  #include "ap_config.h"
  #include "util_filter.h"
  #include "apr_buckets.h"
  #include "apr_strings.h"
  
  module AP_MODULE_DECLARE_DATA nntp_like_module;
  
  typedef struct {
      int enabled;
  } nntp_like_srv_cfg_t;
  
  static void *nntp_like_srv_cfg_create(apr_pool_t *p, server_rec *s)
  {
      nntp_like_srv_cfg_t *cfg = apr_palloc(p, sizeof(*cfg));
  
      cfg->enabled = 0;
  
      return cfg;
  }
  
  static const char *nntp_like_cmd_enable(cmd_parms *cmd, void *dummy, int arg)
  {
      nntp_like_srv_cfg_t *cfg =
          ap_get_module_config(cmd->server->module_config,
                               &nntp_like_module);
      cfg->enabled = arg;
  
      return NULL;
  }
  
  /* this function just triggers the SSL handshake.
   * normally that would happen in a protocol such as HTTP when
   * the client request is read.  however, with certain protocols
   * such as NNTP, the server sends a response before the client
   * sends a request
   *
   * if SSL is not enabled, this function is a noop
   */
  static apr_status_t nntp_like_init_connection(conn_rec *c)
  {
      apr_bucket_brigade *bb;
      apr_status_t rv;
      apr_off_t zero = 0;
  
      bb = apr_brigade_create(c->pool);
  
      rv = ap_get_brigade(c->input_filters, bb,
                          AP_MODE_INIT, &zero);
  
      apr_brigade_destroy(bb);
  
      return rv;
  }
  
  static apr_status_t nntp_like_send_welcome(conn_rec *c)
  {
      apr_bucket *bucket;
      apr_bucket_brigade *bb = apr_brigade_create(c->pool);
  
  #define NNTP_LIKE_WELCOME \
      "200 localhost - ready\r\n"
  
      bucket = apr_bucket_transient_create(NNTP_LIKE_WELCOME,
                                           strlen(NNTP_LIKE_WELCOME));
      APR_BRIGADE_INSERT_TAIL(bb, bucket);
      APR_BRIGADE_INSERT_TAIL(bb, apr_bucket_flush_create());
  
      return ap_pass_brigade(c->output_filters, bb);
  }
  
  static int nntp_like_process_connection(conn_rec *c)
  {
      apr_bucket_brigade *bb;
      apr_status_t rv;
      apr_off_t zero = 0;
      nntp_like_srv_cfg_t *cfg =
          ap_get_module_config(c->base_server->module_config,
                               &nntp_like_module);
  
      if (!cfg->enabled) {
          return DECLINED;
      }
      
      /* handshake if talking over SSL */
      if ((rv = nntp_like_init_connection(c)) != APR_SUCCESS) {
          return rv;
      }
  
      /* send the welcome message */
      if ((rv = nntp_like_send_welcome(c)) != APR_SUCCESS) {
          return rv;
      }
  
      /* just for testing purposes, this is the same logic as mod_echo */
      bb = apr_brigade_create(c->pool);
  
      for (;;) {
          if ((rv = ap_get_brigade(c->input_filters, bb,
                                   AP_MODE_BLOCKING, &zero) != APR_SUCCESS || 
               APR_BRIGADE_EMPTY(bb)))
          {
              apr_brigade_destroy(bb);
              break;
          }
  
          APR_BRIGADE_INSERT_TAIL(bb, apr_bucket_flush_create());
          ap_pass_brigade(c->output_filters, bb);    
      }
  
      return OK;
  }
  
  static void nntp_like_register_hooks(apr_pool_t *p)
  {
      ap_hook_process_connection(nntp_like_process_connection,
                                 NULL, NULL,
                                 APR_HOOK_MIDDLE);
  }
  
  static const command_rec nntp_like_cmds[] = 
  {
      AP_INIT_FLAG("NNTPLike", nntp_like_cmd_enable, NULL, RSRC_CONF,
                   "enable nntp like protocol on this host"),
      { NULL }
  };
  
  module AP_MODULE_DECLARE_DATA nntp_like_module = {
      STANDARD20_MODULE_STUFF, 
      NULL,                  /* create per-dir    config structures */
      NULL,                  /* merge  per-dir    config structures */
      nntp_like_srv_cfg_create, /* create per-server config structures */
      NULL,                  /* merge  per-server config structures */
      nntp_like_cmds,        /* table of config file commands       */
      nntp_like_register_hooks  /* register hooks                      */
  };
  
  
  
  1.1                  httpd-test/perl-framework/t/protocol/nntp-like.t
  
  Index: nntp-like.t
  ===================================================================
  #testing that the server can respond right after client connects,
  #before client sends any request data
  
  use strict;
  use warnings FATAL => 'all';
  
  use Apache::Test;
  use Apache::TestUtil;
  use Apache::TestRequest;
  
  my $tests = 5;
  my $vars = Apache::Test::vars();
  my @modules = qw(mod_nntp_like);
  
  if (Apache::Test::have_ssl()) {
      $tests *= 2;
      unshift @modules, 'mod_nntp_like_ssl';
  }
  
  plan tests => $tests, ['mod_nntp_like'];
  
  for my $module (@modules) {
      print "testing $module\n";
  
      my $sock = Apache::TestRequest::vhost_socket($module);
      ok $sock;
  
      Apache::TestRequest::socket_trace($sock);
  
      my $response = Apache::TestRequest::getline($sock);
  
      $response =~ s/[\r\n]+$//;
      ok t_cmp('200 localhost - ready', $response,
               'welcome response');
  
      for my $data ('LIST', 'GROUP dev.httpd.apache.org', 'ARTICLE 401') {
          $sock->print("$data\n");
  
          chomp($response = Apache::TestRequest::getline($sock));
          ok t_cmp($data, $response, 'echo');
      }
  }
  
  
  

Mime
View raw message