示例#1
0
static void ndpi_http_subprotocol_conf(struct ndpi_detection_module_struct *ndpi_struct, 
				char *attr, char *value, int protocol_id) {
#ifdef AHOCORASICK
  AC_PATTERN_t ac_pattern;
#else
  ndpi_protocol_match *tmp_host_match;
#endif

  /* e.g attr = "host" value = ".facebook.com" protocol_id = NDPI_PROTOCOL_FACEBOOK */

#ifdef AHOCORASICK
  if (strcmp(attr, "finalize") == 0) { /* trick to finalize automa */
    if (ac_automa != NULL)
      ac_automata_finalize(ac_automa);
    return;
  }
#endif

  if (strcmp(attr, "host") != 0) {
#ifdef DEBUG
    printf("[NTOP] attribute %s not supported\n", attr);
#endif
    return;
  }

#ifdef AHOCORASICK
  if (ac_automa == NULL)
    ac_automa = ac_automata_init(ac_match_handler); 
    /* call ac_automata_release(ac_automa); to free ac_automa */

  ac_pattern.astring = value;
  ac_pattern.rep.number = protocol_id;
  ac_pattern.length = strlen(tmp_patt.astring);
  ac_automata_add(ac_automa, &ac_pattern);
#else
  /* realloc */
  tmp_host_match = ndpi_malloc(sizeof(ndpi_protocol_match) * (host_match_num_items + 1));
  if (tmp_host_match == NULL) {
    return;
  }
  if (host_match != NULL) {
    memcpy(tmp_host_match, host_match, sizeof(ndpi_protocol_match) * host_match_num_items);
    ndpi_free(host_match);
  }
  host_match = tmp_host_match; 
  
  host_match[host_match_num_items].string_to_match = ndpi_strdup(value);
  if (host_match[host_match_num_items].string_to_match == NULL) {
    return;
  }

  host_match[host_match_num_items].protocol_id = protocol_id;

  host_match_num_items++;
#endif

#ifdef DEBUG
  printf("[NTOP] new http subprotocol: %s = %s -> %d\n", attr, value, protocol_id);
#endif
}
示例#2
0
文件: btlib.c 项目: houcy/nDPI-1
static void _print_safe_str(char *msg,char *k,const u_int8_t *s,size_t l) {
  static const char *th="0123456789abcdef?";
  char *buf = (char*)ndpi_malloc((size_t)(l*3+2));

  int sl = l;
  if(buf) {
    char *b = buf;
    for(;l > 0; s++,l--) {
      if(*s < ' ' || *s >= 127) {
	*b++ = '%';
	*b++ = th[(*s >> 4)&0xf];
	*b++ = th[(*s)&0xf];
      } else *b++ = *s;
    }