Esempio n. 1
0
static cmark_node *match(cmark_syntax_extension *ext, cmark_parser *parser,
                         cmark_node *parent, unsigned char c,
                         cmark_inline_parser *inline_parser) {
  if (cmark_inline_parser_in_bracket(inline_parser, false) ||
      cmark_inline_parser_in_bracket(inline_parser, true))
    return NULL;

  if (c == ':')
    return url_match(parser, parent, inline_parser);

  if (c == 'w')
    return www_match(parser, parent, inline_parser);

  return NULL;

  // note that we could end up re-consuming something already a
  // part of an inline, because we don't track when the last
  // inline was finished in inlines.c.
}
Esempio n. 2
0
int get_decision(struct connection_info *c_info, struct location_tuple * lt)
//TODO int get_decision(struct data_head * dh,struct connection_info *c_info)
{
    struct decision_result*dr=(struct decision_result*)malloc(4*sizeof(int));
    init_result(dr);
    if(c_info==NULL)
    {
        if (NULL != dr)
            free(dr);
        return -1;
    }
    if(c_info->p_type==13)
    dr->trie=url_match(c_info->url);
    else
    dr->url= url_match(c_info->url);
    struct logic_query_result*lr=logic_query_match(c_info->comment);
    struct logic_query_result*lr_N=logic_query_match_N(c_info->comment);
    dr->gk=lr->hit_count;
    dr->monitor=lr_N->hit_count;
    int pattern1=-1,pattern2=-1, rt=0;
    dr->trie+=trie_chk_rule(c_info->user_id, c_info->s_id, c_info->p_type, c_info->r_id, &pattern1,&pattern2);
    if (dr->url==0&&dr->gk==0&&dr->monitor==0&&dr->trie==0)
    {
        free(dr);
	free(lr);
	free(lr_N);
        return 0;
    }
    printf("===========================\n");
    printf("url:%d\ngk:%d\nmonitor%d\ntrie:%d\n",dr->url,dr->gk,dr->monitor,dr->trie) ;
    printf("===========================\n");
    if(dr->monitor>0)
    {
 	//sunpy
 	if(dr->url == 0 && dr->gk == 0 && dr->trie == 0) {
         printf("hit count: %d\n", dr->monitor);

         int i;
         for (i = 0; i < dr->monitor; i++) {
             struct loginfo log;
             initlog(&log, lt);
             log_addsocialinfo(&log, c_info);

             // sunpy: after discussing with Shao
             log_set_gk_type(&log, 4);
            
             int index = lr_N->hit_rule_list[i];
             struct query_expression* qe = query_rule_table_N->table[index];
	     log_addkeyword(&log, qe->full_text);
             log_set_full_text(&log, c_info->comment);
            
             printlog(&log);
             sendlog(&log, dr->monitor);
         }
         
         free(lr);
         free(lr_N);
         free(dr);

         return 0;
        }
    }
        if(dr->url>0)
        {
            printf("============================\n");
            printf("HIT URL\n");
            printf("============================\n");
            struct loginfo log;
            initlog(&log, lt);
            log_addsocialinfo(&log, c_info);
            log_set_gk_type(&log, 3);
            
            char * kw[dr->url];
            int z;
            for(z=0;z<dr->url;z++){
                kw[z]=(char*)malloc(256*sizeof(char));
                bzero(kw[z],256*sizeof(char));
            }
            get_keywords(c_info->url,kw);
            log_addkeywords(&log,kw,dr->url);
            log.keywords[strlen(log.keywords)-1]='\0';
            log_addkeyword(&log, c_info->url);
            log_set_full_text(&log, c_info->comment);
            printlog(&log);
            sendlog(&log,0);
            for (z=0; z < dr->url; z++)
            	FREE(kw[z]);
            //FREE(kw);
        }
        if(dr->gk>0)
        {
            printf("============================\n");
            printf("HIT GK KEYWORD\n");
            printf("============================\n");
            int i;
            for (i = 0; i < dr->gk; i++) {
                struct loginfo log;
                initlog(&log, lt);
                log_addsocialinfo(&log, c_info);
                log_set_gk_type(&log, 0);
                
                int index = lr->hit_rule_list[i];
                struct query_expression* qe = query_rule_table->table[index];
		log_addkeyword(&log, qe->full_text);
		log_set_full_text(&log, c_info->comment);
                
                //printlog(&log);
                sendlog(&log,0);
            }
        }
        if(dr->trie>0)
        {
            printf("============================\n");
            printf("HIT TRIE \n");
            printf("============================\n");
            struct loginfo log;
            initlog(&log, lt);
            log_addsocialinfo(&log, c_info);
            if (pattern1 != -1) {
                if (pattern1 % 2 == 0)
                    log_set_gk_type(&log, 1);
                else
                    log_set_gk_type(&log, 2);
            } else {
                log_set_gk_type(&log,2);
            }
            log_set_full_text(&log, c_info->comment);
//            printlog(&log);
            sendlog(&log,0);
        }
		
    free(lr);
    free(lr_N);
    free(dr);
	return 1;
}
Esempio n. 3
0
/*********************************************************************
 *
 * Function    :  is_untrusted_url
 *
 * Description :  Should we "distrust" this URL (and block it)?
 *
 *                Yes if it matches a line in the trustfile, or if the
 *                    referrer matches a line starting with "+" in the
 *                    trustfile.
 *                No  otherwise.
 *
 * Parameters  :
 *          1  :  csp = Current client state (buffers, headers, etc...)
 *
 * Returns     :  0 => trusted, 1 => untrusted
 *
 *********************************************************************/
int is_untrusted_url(struct client_state *csp)
{
   struct file_list *fl;
   struct block_spec *b;
   struct url_spec **trusted_url;
   struct http_request rhttp[1];
   const char * referer;
   jb_err err;

   /*
    * If we don't have a trustlist, we trust everybody
    */
   if (((fl = csp->tlist) == NULL) || ((b  = fl->f) == NULL))
   {
      return 0;
   }

   memset(rhttp, '\0', sizeof(*rhttp));

   /*
    * Do we trust the request URL itself?
    */
   for (b = b->next; b ; b = b->next)
   {
      if (url_match(b->url, csp->http))
      {
         return b->reject;
      }
   }

   if (NULL == (referer = get_header_value(csp->headers, "Referer:")))
   {
      /* no referrer was supplied */
      return 1;
   }


   /*
    * If not, do we maybe trust its referrer?
    */
   err = parse_http_url(referer, rhttp, csp);
   if (err)
   {
      return 1;
   }

   for (trusted_url = csp->config->trust_list; *trusted_url != NULL; trusted_url++)
   {
      if (url_match(*trusted_url, rhttp))
      {
         /* if the URL's referrer is from a trusted referrer, then
          * add the target spec to the trustfile as an unblocked
          * domain and return NULL (which means it's OK).
          */

         FILE *fp;

         if (NULL != (fp = fopen(csp->config->trustfile, "a")))
         {
            char * path;
            char * path_end;
            char * new_entry = strdup("~");

            string_append(&new_entry, csp->http->hostport);

            path = csp->http->path;
            if ( (path[0] == '/')
              && (path[1] == '~')
              && ((path_end = strchr(path + 2, '/')) != NULL))
            {
               /* since this path points into a user's home space
                * be sure to include this spec in the trustfile.
                */
               int path_len = path_end - path; /* save offset */
               path = strdup(path); /* Copy string */
               if (path != NULL)
               {
                  path_end = path + path_len; /* regenerate ptr to new buffer */
                  *(path_end + 1) = '\0'; /* Truncate path after '/' */
               }
               string_join(&new_entry, path);
            }

            if (new_entry != NULL)
            {
               fprintf(fp, "%s\n", new_entry);
               free(new_entry);
            }
            else
            {
               /* FIXME: No way to handle out-of memory, so mostly ignoring it */
               log_error(LOG_LEVEL_ERROR, "Out of memory adding pattern to trust file");
            }

            fclose(fp);
         }
         return 0;
      }
   }
   return 1;
}