⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 olsrd_httpinfo.c

📁 wifi 无线网络路由协议OLSR linux下C代码
💻 C
📖 第 1 页 / 共 3 页
字号:
	  size = static_bin_files[i].data_size;	  c = build_http_header(HTTP_OK, OLSR_FALSE, size, req, MAX_HTTPREQ_SIZE);  	  goto send_http_data;	}      i = 0;      while(static_txt_files[i].filename)	{	  if(FILENREQ_MATCH(filename, static_txt_files[i].filename))	    break;	  i++;	}            if(static_txt_files[i].filename)	{	  stats.ok_hits++;	  y = 0;	  while(static_txt_files[i].data[y])	    {	      size += snprintf(&body[size], sizeof(body)-size, static_txt_files[i].data[y]);	      y++;	    }	  c = build_http_header(HTTP_OK, OLSR_FALSE, size, req, MAX_HTTPREQ_SIZE);  	  goto send_http_data;	}      i = 0;      if(strlen(filename) > 1)	{	  while(tab_entries[i].filename)	    {	      if(FILENREQ_MATCH(filename, tab_entries[i].filename))		break;	      i++;	    }	}      if(tab_entries[i].filename)	{#ifdef NETDIRECT	  c = build_http_header(HTTP_OK, OLSR_TRUE, size, req, MAX_HTTPREQ_SIZE);	  r = send(client_sockets[curr_clients], req, c, 0);   	  if(r < 0)	    {	      olsr_printf(1, "(HTTPINFO) Failed sending data to client!\n");	      goto close_connection;	    }	  netsprintf_error = 0;	  netsprintf_direct = 1;#endif          size += snprintf(&body[size], sizeof(body)-size, "%s", http_ok_head);	  	  size += build_tabs(&body[size], sizeof(body)-size, i);	  size += build_frame(&body[size], 			      sizeof(body)-size, 			      "Current Routes", 			      "routes", 			      FRAMEWIDTH, 			      tab_entries[i].build_body_cb);	  	  stats.ok_hits++;          size += snprintf(&body[size], sizeof(body)-size, http_ok_tail);	  #ifdef NETDIRECT	  netsprintf_direct = 1;	  goto close_connection;#else	  c = build_http_header(HTTP_OK, OLSR_TRUE, size, req, MAX_HTTPREQ_SIZE);	  	  goto send_http_data;#endif	}                  stats.ill_hits++;      strcpy(body, HTTP_404_MSG);      c = build_http_header(HTTP_BAD_FILE, OLSR_TRUE, strlen(body), req, MAX_HTTPREQ_SIZE);    }  else    {      /* We only support GET */      strcpy(body, HTTP_400_MSG);      stats.ill_hits++;      c = build_http_header(HTTP_BAD_REQ, OLSR_TRUE, strlen(body), req, MAX_HTTPREQ_SIZE);    } send_http_data:    r = writen(client_sockets[curr_clients], req, c);     if(r < 0)    {      olsr_printf(1, "(HTTPINFO) Failed sending data to client!\n");      goto close_connection;    }  r = writen(client_sockets[curr_clients], body, size);  if(r < 0)    {      olsr_printf(1, "(HTTPINFO) Failed sending data to client!\n");      goto close_connection;    } close_connection:  close(client_sockets[curr_clients]);  curr_clients--;}intbuild_http_header(http_header_type type, 		  olsr_bool is_html, 		  olsr_u32_t msgsize, 		  char *buf, 		  olsr_u32_t bufsize){  time_t currtime;  const char *h;  int size;  switch(type) {  case(HTTP_BAD_REQ):      h = HTTP_400;      break;  case(HTTP_BAD_FILE):      h = HTTP_404;      break;  default:      /* Defaults to OK */      h = HTTP_200;      break;  }  size = snprintf(buf, bufsize, "%s", h);  /* Date */  time(&currtime);  size += strftime(&buf[size], bufsize-size, "Date: %a, %d %b %Y %H:%M:%S GMT\r\n", localtime(&currtime));    /* Server version */  size += snprintf(&buf[size], bufsize-size, "Server: %s %s %s\r\n", PLUGIN_NAME, PLUGIN_VERSION, HTTP_VERSION);  /* connection-type */  size += snprintf(&buf[size], bufsize-size, "Connection: closed\r\n");  /* MIME type */  size += snprintf(&buf[size], bufsize-size, "Content-type: text/%s\r\n", is_html ? "html" : "plain");  /* Content length */  if(msgsize > 0) {      size += snprintf(&buf[size], bufsize-size, "Content-length: %i\r\n", msgsize);  }  /* Cache-control    * No caching dynamic pages   */  size += snprintf(&buf[size], bufsize-size, "Cache-Control: no-cache\r\n");  if(!is_html) {    size += snprintf(&buf[size], bufsize-size, "Accept-Ranges: bytes\r\n");  }  /* End header */  size += snprintf(&buf[size], bufsize-size, "\r\n");    olsr_printf(1, "HEADER:\n%s", buf);  return size;}static int build_tabs(char *buf, const olsr_u32_t bufsize, int active){  int size = 0, tabs = 0;  size += snprintf(&buf[size], bufsize-size, html_tabs_prolog);  for(tabs = 0; tab_entries[tabs].tab_label; tabs++) {    if(!tab_entries[tabs].display_tab)      continue;    size += snprintf(&buf[size], bufsize-size,                      "<li><a href=\"%s\"%s>%s</a></li>\n",                     tab_entries[tabs].filename,                      tabs == active ? " class=\"active\"" : "",                     tab_entries[tabs].tab_label);  }  size += snprintf(&buf[size], bufsize-size, html_tabs_epilog);  return size;}/* * destructor - called at unload */voidolsr_plugin_exit(void){  if(http_socket)    close(http_socket);}static int section_title(char *buf, olsr_u32_t bufsize, const char *title){  return snprintf(buf, bufsize,                  "<h2>%s</h2>\n"                  "<table width=\"100%%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">\n", title);}static int build_frame(char *buf,                       olsr_u32_t bufsize,                       char *title __attribute__((unused)),                        char *link __attribute__((unused)),                        int width __attribute__((unused)),                       int(*frame_body_cb)(char *, olsr_u32_t)){  int size = 0;  size += snprintf(&buf[size], bufsize-size, "<div id=\"maintable\">\n");  size += frame_body_cb(&buf[size], bufsize-size);    size += snprintf(&buf[size], bufsize-size, "</div>\n");  return size;}static int fmt_href(char *buf,                    const olsr_u32_t bufsize,                    const union olsr_ip_addr * const ipaddr){  return snprintf(buf, bufsize,                  "<a href=\"http://%s:%d/all\">",                  olsr_ip_to_string(ipaddr),                  http_port);}static int build_ip_txt(char *buf,                        const olsr_u32_t bufsize,                        const olsr_bool print_link,                        const union olsr_ip_addr * const ipaddr,                        const int prefix_len){  int size = 0;  if (print_link) { /* Print the link only if there is no prefix_len */    size += fmt_href(&buf[size], bufsize-size, ipaddr);  }  /* print ip address or ip prefix ? */  if (prefix_len == -1) {      size += snprintf(&buf[size], bufsize-size, "%s", olsr_ip_to_string(ipaddr));  } else {      size += snprintf(&buf[size], bufsize-size, "%s/%d", olsr_ip_to_string(ipaddr),                       prefix_len);  }    if (print_link) { /* Print the link only if there is no prefix_len */    size += snprintf(&buf[size], bufsize-size, "</a>");  }  return size;}static int build_ipaddr_link(char *buf, const olsr_u32_t bufsize,                             const olsr_bool want_link,                             const union olsr_ip_addr * const ipaddr,                             const int prefix_len){  int size = 0;  const struct hostent * const hp =#ifndef WIN32      resolve_ip_addresses ? gethostbyaddr(ipaddr, olsr_cnf->ipsize, olsr_cnf->ip_version) :#endif      NULL;  const int print_link = want_link && (prefix_len == -1 || prefix_len == olsr_cnf->maxplen);  size += snprintf(&buf[size], bufsize-size, "<td>");  size += build_ip_txt(&buf[size], bufsize-size, print_link, ipaddr, prefix_len);  size += snprintf(&buf[size], bufsize-size, "</td>");  if (resolve_ip_addresses) {    if (hp) {      size += snprintf(&buf[size], bufsize-size, "<td>(");      if (print_link) {        size += fmt_href(&buf[size], bufsize-size, ipaddr);      }      size += snprintf(&buf[size], bufsize-size, "%s", hp->h_name);      if (print_link) {        size += snprintf(&buf[size], bufsize-size, "</a>");      }      size += snprintf(&buf[size], bufsize-size, ")</td>");    } else {      size += snprintf(&buf[size], bufsize-size, "<td/>");    }  }  return size;}#define build_ipaddr_with_link(buf, bufsize, ipaddr, plen) \          build_ipaddr_link((buf), (bufsize), OLSR_TRUE, (ipaddr), (plen))#define build_ipaddr_no_link(buf, bufsize, ipaddr, plen) \          build_ipaddr_link((buf), (bufsize), OLSR_FALSE, (ipaddr), (plen))static int build_route(char *buf, olsr_u32_t bufsize, const struct rt_entry * rt){  int size = 0;  size += snprintf(&buf[size], bufsize-size, "<tr>");  size += build_ipaddr_with_link(&buf[size], bufsize-size, &rt->rt_dst.prefix,                                 rt->rt_dst.prefix_len);  size += build_ipaddr_with_link(&buf[size], bufsize-size,                                 &rt->rt_best->rtp_nexthop.gateway, -1);  size += snprintf(&buf[size], bufsize-size, "<td align=\"center\">%d</td>",                   rt->rt_best->rtp_metric.hops);  size += snprintf(&buf[size], bufsize-size, "<td align=\"center\">%.3f</td>",                     rt->rt_best->rtp_metric.etx);  size += snprintf(&buf[size], bufsize-size, "<td align=\"center\">%s</td></tr>\n",                   if_ifwithindex_name(rt->rt_best->rtp_nexthop.iif_index));  return size;}static int build_routes_body(char *buf, olsr_u32_t bufsize){  int size = 0;  struct rt_entry *rt;  size += section_title(&buf[size], bufsize-size, "OLSR Routes in Kernel");  size += snprintf(&buf[size], bufsize-size,                   "<tr><th%1$s>Destination</th><th%1$s>Gateway</th><th>Metric</th><th>ETX</th><th>Interface</th></tr>\n",                  resolve_ip_addresses ? " colspan=\"2\"" : "");  /* Walk the route table */  OLSR_FOR_ALL_RT_ENTRIES(rt) {      size += build_route(&buf[size], bufsize-size, rt);  } OLSR_FOR_ALL_RT_ENTRIES_END(rt);  size += snprintf(&buf[size], bufsize-size, "</table>\n");  return size;}static int build_config_body(char *buf, olsr_u32_t bufsize){    int size = 0;    struct olsr_if *ifs;    struct plugin_entry *pentry;    struct plugin_param *pparam;    size += snprintf(&buf[size], bufsize-size, "Version: %s (built on %s on %s)\n<br>", olsrd_version, build_date, build_host);    size += snprintf(&buf[size], bufsize-size, "OS: %s\n<br>", OS);    {       time_t currtime = time(NULL);      int rc = strftime(&buf[size], bufsize-size, "System time: <em>%a, %d %b %Y %H:%M:%S</em><br>", localtime(&currtime));      if (rc > 0) {        size += rc;      }    }    {      struct timeval now, uptime;      int hours, mins, days;      gettimeofday(&now, NULL);      timersub(&now, &start_time, &uptime);      days = uptime.tv_sec/86400;      uptime.tv_sec %= 86400;      hours = uptime.tv_sec/3600;      uptime.tv_sec %= 3600;      mins = uptime.tv_sec/60;      uptime.tv_sec %= 60;      size += snprintf(&buf[size], bufsize-size, "Olsrd uptime: <em>");      if (days) {        size += snprintf(&buf[size], bufsize-size, "%d day(s) ", days);      }      size += snprintf(&buf[size], bufsize-size, "%02d hours %02d minutes %02d seconds</em><br/>\n", hours, mins, (int)uptime.tv_sec);    }    size += snprintf(&buf[size], bufsize-size, "HTTP stats(ok/dyn/error/illegal): <em>%d/%d/%d/%d</em><br>\n", stats.ok_hits, stats.dyn_hits, stats.err_hits, stats.ill_hits);    size += snprintf(&buf[size], bufsize-size, "Click <a href=\"/cfgfile\">here</a> to <em>generate a configuration file for this node</em>.\n");    size += snprintf(&buf[size], bufsize-size, "<h2>Variables</h2>\n");    size += snprintf(&buf[size], bufsize-size, "<table width=\"100%%\" border=\"0\">\n<tr>");    size += snprintf(&buf[size], bufsize-size, "<td>Main address: <strong>%s</strong></td>\n", olsr_ip_to_string(&olsr_cnf->main_addr));        size += snprintf(&buf[size], bufsize-size, "<td>IP version: %d</td>\n", olsr_cnf->ip_version == AF_INET ? 4 : 6);    size += snprintf(&buf[size], bufsize-size, "<td>Debug level: %d</td>\n", olsr_cnf->debug_level);    size += snprintf(&buf[size], bufsize-size, "</tr>\n<tr>\n");    size += snprintf(&buf[size], bufsize-size, "<td>Pollrate: %0.2f</td>\n", olsr_cnf->pollrate);    size += snprintf(&buf[size], bufsize-size, "<td>TC redundancy: %d</td>\n", olsr_cnf->tc_redundancy);    size += snprintf(&buf[size], bufsize-size, "<td>MPR coverage: %d</td>\n", olsr_cnf->mpr_coverage);    size += snprintf(&buf[size], bufsize-size, "</tr>\n<tr>\n");    size += snprintf(&buf[size], bufsize-size, "<td>Fisheye: %s</td>\n", olsr_cnf->lq_fish ? "Enabled" : "Disabled");    size += snprintf(&buf[size], bufsize-size, "<td>TOS: 0x%04x</td>\n", olsr_cnf->tos);    size += snprintf(&buf[size], bufsize-size, "<td>RtTable: 0x%04x</td>\n", olsr_cnf->rttable);    size += snprintf(&buf[size], bufsize-size, "<td>Willingness: %d %s</td>\n", olsr_cnf->willingness, olsr_cnf->willingness_auto ? "(auto)" : "");        size += snprintf(&buf[size], bufsize-size, "</tr>\n<tr>\n");    if (olsr_cnf->lq_level == 0)      {        size += snprintf(&buf[size], bufsize-size, "<td>Hysteresis: %s</td>\n", olsr_cnf->use_hysteresis ? "Enabled" : "Disabled");	if (olsr_cnf->use_hysteresis)          {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -