Mongoose6.0源码分析(3)-重要结构体

原创 2015年11月19日 17:02:24

重要的结构体,但是不往下看很难明白要这么复杂的结构体,所以在读其他代码是慢慢分析

struct mg_mgr {

  struct mg_connection *active_connections;
  const char *hexdump_file; /* Debug hexdump file path */
  sock_t ctl[2];            /* Socketpair for mg_wakeup() */
  void *user_data;          /* User data */
  void *mgr_data;           /* Implementation-specific event manager's data. */ //实施特别事务管理员数据
};


struct mg_connection { //将老版本的mg_context和mg_connection结合了一下
  struct mg_connection *next, *prev; /* mg_mgr::active_connections linkage */ //搞链表
  struct mg_connection *listener;    /* Set only for accept()-ed connections */
  struct mg_mgr *mgr;                /* Pointer to containing manager */


  sock_t sock;             /* Socket to the remote peer */
  union socket_address sa; /* Remote peer address */
  size_t recv_mbuf_limit;  /* Max size of recv buffer */
  struct mbuf recv_mbuf;   /* Received data */ 接收到的数据存储在这个缓冲区中
  struct mbuf send_mbuf;   /* Data scheduled for sending */
  SSL *ssl;
  SSL_CTX *ssl_ctx;
  time_t last_io_time;              /* Timestamp of the last socket IO */
  mg_event_handler_t proto_handler; /* Protocol-specific event handler */
  void *proto_data;                 /* Protocol-specific data */
  mg_event_handler_t handler;       /* Event handler function */
  void *user_data;                  /* User-specific data */
  void *priv_1;                     /* Used by mg_enable_multithreading() */
  void *priv_2;                     /* Used by mg_enable_multithreading() */
  void *mgr_data; /* Implementation-specific event manager's data. */


  unsigned long flags;
/* Flags set by Mongoose */
#define MG_F_LISTENING (1 << 0)          /* This connection is listening */
#define MG_F_UDP (1 << 1)                /* This connection is UDP */
#define MG_F_RESOLVING (1 << 2)          /* Waiting for async resolver */
#define MG_F_CONNECTING (1 << 3)         /* connect() call in progress */
#define MG_F_SSL_HANDSHAKE_DONE (1 << 4) /* SSL specific */
#define MG_F_WANT_READ (1 << 5)          /* SSL specific */
#define MG_F_WANT_WRITE (1 << 6)         /* SSL specific */
#define MG_F_IS_WEBSOCKET (1 << 7)       /* Websocket specific */


/* Flags that are settable by user */
#define MG_F_SEND_AND_CLOSE (1 << 10)      /* Push remaining data and close  */
#define MG_F_DONT_SEND (1 << 11)           /* Do not send data to peer */
#define MG_F_CLOSE_IMMEDIATELY (1 << 12)   /* Disconnect */
#define MG_F_WEBSOCKET_NO_DEFRAG (1 << 13) /* Websocket specific */
#define MG_F_DELETE_CHUNK (1 << 14)        /* HTTP specific */


#define MG_F_USER_1 (1 << 20) /* Flags left for application */
#define MG_F_USER_2 (1 << 21)
#define MG_F_USER_3 (1 << 22)
#define MG_F_USER_4 (1 << 23)
#define MG_F_USER_5 (1 << 24)
#define MG_F_USER_6 (1 << 25)

};

struct mbuf {
  char *buf;   /* Buffer pointer */
  size_t len;  /* Data length. Data is located between offset 0 and len. */
  size_t size; /* Buffer size allocated by realloc(1). Must be >= len */
};

void mbuf_init(struct mbuf *mbuf, size_t initial_size) {
  mbuf->len = mbuf->size = 0;
  mbuf->buf = NULL;
  mbuf_resize(mbuf, initial_size);
}


struct http_message { //存放http消息,对照(2)看较清楚。
  struct
mg_str message; /* Whole message: request line + headers + body */
  struct mg_str proto; /* "HTTP/1.1" -- for both request and response */
  /* HTTP Request line (or HTTP response line) */
  struct mg_str method; /* "GET" */
  struct mg_str uri;    /* "/my_file.html" */
  /* For responses, code and response status message are set */
  int resp_code;
  struct mg_str resp_status_msg;
  /*
   * Query-string part of the URI. For example, for HTTP request
   *    GET /foo/bar?param1=val1&param2=val2
   *    |    uri    |     query_string     |
   *
   * Note that question mark character doesn't belong neither to the uri,
   * nor to the query_string
   */
  struct mg_str query_string;

  /* Headers */
  struct mg_str header_names[MG_MAX_HTTP_HEADERS]; //#define MG_MAX_HTTP_HEADERS 40
  struct mg_str header_values[MG_MAX_HTTP_HEADERS];

  /* Message body */
  struct mg_str body; /* Zero-length for requests with no body */
};


mg_str 

/* Describes chunk of memory */
struct mg_str {
  const char *p; /* Memory chunk pointer */
  size_t len;    /* Memory chunk length */
};


保存了要发送的数据体

struct proto_data_http {
  FILE *fp;         /* Opened file. */
  int64_t cl;       /* Content-Length. How many bytes to send. */
  int64_t sent;     /* How many bytes have been already sent. */
  int64_t body_len; /* How many bytes of chunked body was reassembled重组. */
  struct mg_connection *cgi_nc;
  enum http_proto_data_type type;
};


保存服务选项

struct mg_serve_http_opts {  
  /* Path to web root directory */
  const char *document_root;


  /* List of index files. Default is "" */
  const char *index_files;


  /*
   * Leave as NULL to disable authentication.
   * To enable directory protection with authentication, set this to ".htpasswd"
   * Then, creating ".htpasswd" file in any directory automatically protects
   * it with digest authentication.
   * Use `mongoose` web server binary, or `htdigest` Apache utility to
   * create/manipulate passwords file.
   * Make sure `auth_domain` is set to a valid domain name.
   */
  const char *per_directory_auth_file;


  /* Authorization domain (domain name of this web server) */
  const char *auth_domain;


  /*
   * Leave as NULL to disable authentication.
   * Normally, only selected directories in the document root are protected.
   * If absolutely every access to the web server needs to be authenticated,
   * regardless of the URI, set this option to the path to the passwords file.
   * Format of that file is the same as ".htpasswd" file. Make sure that file
   * is located outside document root to prevent people fetching it.
   */
  const char *global_auth_file;


  /* Set to "no" to disable directory listing. Enabled by default. */
  const char *enable_directory_listing;


  /* SSI files pattern. If not set, "**.shtml$|**.shtm$" is used. */
  const char *ssi_pattern;


  /* IP ACL. By default, NULL, meaning all IPs are allowed to connect */
  const char *ip_acl;


  /* URL rewrites.
   *
   * Comma-separated list of `uri_pattern=file_or_directory_path` rewrites.
   * When HTTP request is received, Mongoose constructs a file name from the
   * requested URI by combining `document_root` and the URI. However, if the
   * rewrite option is used and `uri_pattern` matches requested URI, then
   * `document_root` is ignored. Instead, `file_or_directory_path` is used,
   * which should be a full path name or a path relative to the web server's
   * current working directory. Note that `uri_pattern`, as all Mongoose
   * patterns, is a prefix pattern.
   *
   * If uri_pattern starts with `@` symbol, then Mongoose compares it with the
   * HOST header of the request. If they are equal, Mongoose sets document root
   * to `file_or_directory_path`, implementing virtual hosts support.
   */
  const char *url_rewrites;


  /* DAV document root. If NULL, DAV requests are going to fail. */
  const char *dav_document_root;


  /* Glob pattern for the files to hide. */
  const char *hidden_file_pattern;


  /* Set to non-NULL to enable CGI, e.g. **.cgi$|**.php$" */
  const char *cgi_file_pattern;


  /* If not NULL, ignore CGI script hashbang and use this interpreter */
  const char *cgi_interpreter;


  /*
   * Comma-separated list of Content-Type overrides for path suffixes, e.g.
   * ".txt=text/plain; charset=utf-8,.c=text/plain"
   */
  const char *custom_mime_types;
};

相关文章推荐

c++利用mongoose实现http服务

近来在项目中需要实现一个http service的功能。虽然可以通过封装socket自己实现http的发送和解析。但考虑到目前网络上还是有大量的http的解析源码,自己再从头实现一番稍显麻烦。因此在网...

Mongoose6.0源码分析(1)-从一个example开始到读取数据

Mongoose6.0源码分析
  • zxy355
  • zxy355
  • 2015年10月22日 10:55
  • 1739

ndpi源码分析一--几个重要的结构体

最近研究了ndpi的源代码,过程中看到关于这方面的资料很少,所以就想把自己的收获写下来分享一下,也让之后的同学有所参考。首先简单介绍一下ndpi源码中几个比较重要的结构体,这些结构体的定义一般都在nd...

x264重要结构体详细说明(3): x264_sps_t、x264_pps_t

本博客转载于:http://nkwavelet.blog.163.com/blog/static/227756038201431095653355/ /***************...

《The C programming language》笔记3_重要的结构体

C语言结构体,可谓是C强大功能之一,也是C++语言之所以能衍生的有利条件,事实上,当结构体中成员中有函数指针了后,那么,结构体也即C++中的类了。 C语言中,结构体的声明、定义是用到关键字struc...

USB驱动之几个重要结构体分析

USB驱动之几个重要结构体分析arm linux设备驱 2010-07-12 22:20:37 阅读192 评论0   字号:大中小 订阅 USB设备其实很复杂,但是Linux内核提供了一个称为USB...

【linux驱动分析】之dm9000驱动分析(五):另外几个重要的结构体

除了sk_buff和net_device,dm9000驱动中用到的另外几个重要的结构体 一、platform_driver 定义在include/linux/platform_device...

结构体数字锁相放大器源码

  • 2014年08月17日 20:15
  • 30KB
  • 下载

USB 设备驱动开发之几个重要结构体分析

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/aaa6695798/archive/2009/11/06/4776202.aspx  该部分所有结构体的声明均可以在内...
  • WInScar
  • WInScar
  • 2011年04月09日 23:49
  • 4624

libevent源码分析---回顾主要的结构体

以前忘记说明,这里源码分析使用的是libevent库的1.4.12-stable版本,在2.0以上的版本都是4W+行,过于庞大,网络上看到关于libevent库中几个重要的结构体关系图,很清楚很好,感...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Mongoose6.0源码分析(3)-重要结构体
举报原因:
原因补充:

(最多只允许输入30个字)