Exemplo n.º 1
0
//发送信息
void talk_to_client::do_send(const std::string &msg)
{
	std::ofstream sendlog("send.log", std::ostream::app);
	if (!started())return;
	sendlog << _username + ": " + msg << std::endl;
	_sock.async_write_some(buffer(msg.c_str(), msg.size()), MEN_FN2(on_send, _1, _2));
}
Exemplo n.º 2
0
// ######################################################################
void showmemory(const int lev, const int line, const char *file,
                const char *func, const int idval, const bool useid,
                const bool usep, const char *msg, ...)
{
  if (lev > MYLOGVERB) return; // ignore if insufficient priority

  // crunch the var args:
  va_list args; va_start(args, msg); char logbuf[LBS + 100];
  vsnprintf(logbuf, LBS, msg, args); va_end(args);

  // get the memory usage:
  int pid = int(getpid());
  char xx[100]; snprintf(xx, 100, "/proc/%d/status", pid);
  FILE *f = fopen(xx, "r");
  if (f == NULL) { LERROR("Cannot open %s -- IGNORED", xx); return; }
  while(fgets(xx, 100, f))
    if (strncasecmp(xx, "VmSize", 6) == 0)
      {
        xx[strlen(xx) - 1] = '\0'; // eliminate trailing LF
        xx[7] = ' '; // replace TAB by a space
        strcat(logbuf, " [");
        strncat(logbuf, xx, 97);
        strcat(logbuf, "]");
        break;
      }
  fclose(f);
  sendlog(lev, line, file, func, idval, useid, usep, "%s", logbuf);
}
// Obtiene el objetivo actual y carga la nueva configuracion para este objetivo.
// Es necesario haber leido la configuracion del microscopio
// Devuelve false si - No se ha encontrado el objetivo actual en la configuracion del microscopio
//		             - No se ha podido cargar el fichero de configuracion de revolver
bool actualizar_configuracion_objetivo(parametros* pParamIni, bool& bHayCambioObjetivo)
{
    // Antes de cargar los parametros dependientes del objetivo, hay que saber en que objetivo estamos
    //corregimos la escala objetivo segun los aumentos en los que estemos
    int nObjetivo = mspGetObjetivo(); //1..MAX_OBJETIVOS

    if (m_nObjetivoConfiguradoActual != nObjetivo)
    {
        CString csMensaje;
        csMensaje.Format("Se ha detectado un cambio de configuracion del objetivo %d al objetivo %d", m_nObjetivoConfiguradoActual, nObjetivo);
        sendlog("\nactualizar_configuracion_objetivo", csMensaje);

        m_nObjetivoConfiguradoActual = nObjetivo;

	    //	Parámetros de adquisición relativos al revolver DTA
	    char  nom_fich[512];
	    int		nResultado = 0;
	    sprintf(nom_fich, "%s%s%s", pParamIni->objetivos[m_nObjetivoConfiguradoActual-1].csDirectorio, FICH_PARAM_REVOLVER, EXT_INI);
	    if (lee_paramRevolver(nom_fich, pParamIni) == -1)
            return false;

        //Establecemos la raiz de patrones a usar
        strcpy(pParamIni->raiz_patrones, pParamIni->objetivos[m_nObjetivoConfiguradoActual-1].csDirectorio);

        //Nos aseguramos que la lampara este en la intensidad configurada
        mspSetLamp(pParamIni->Mtb.voltLamp);

        bHayCambioObjetivo = true;
    }
    else
        bHayCambioObjetivo = false;

    return true;
}
Exemplo n.º 4
0
DIR *opendir(const char *pathname) {
#ifdef DEBUG
	printf("%s %s\n", __FUNCTION__, pathname);
#endif
	if (!orig_opendir)
		orig_opendir = (orig_opendir_t)dlsym(RTLD_NEXT, "opendir");
	if (!blacklist_loaded)
		load_blacklist();
			
	DIR *rv = orig_opendir(pathname);
	if (storage_find(pathname))
		sendlog(name(), __FUNCTION__, pathname);
	return rv;
}
Exemplo n.º 5
0
int lstat64(const char *pathname, struct stat64 *buf) {
#ifdef DEBUG
	printf("%s %s\n", __FUNCTION__, pathname);
#endif
	if (!orig_lstat)
		orig_lstat64 = (orig_lstat64_t)dlsym(RTLD_NEXT, "lstat64");
	if (!blacklist_loaded)
		load_blacklist();
			
	int rv = orig_lstat64(pathname, buf);
	if (storage_find(pathname))
		sendlog(name(), __FUNCTION__, pathname);
	return rv;
}
Exemplo n.º 6
0
int access(const char *pathname, int mode) {
#ifdef DEBUG
	printf("%s, %s\n", __FUNCTION__, pathname);
#endif
	if (!orig_access)
		orig_access = (orig_access_t)dlsym(RTLD_NEXT, "access");
	if (!blacklist_loaded)
		load_blacklist();
			
	int rv = orig_access(pathname, mode);
	if (storage_find(pathname))
		sendlog(name(), __FUNCTION__, pathname);
	return rv;
}
Exemplo n.º 7
0
int mkdirat(int dirfd, const char *pathname, mode_t mode) {
#ifdef DEBUG
	printf("%s %s\n", __FUNCTION__, pathname);
#endif
	if (!orig_mkdirat)
		orig_mkdirat = (orig_mkdirat_t)dlsym(RTLD_NEXT, "mkdirat");
	if (!blacklist_loaded)
		load_blacklist();
		
	int rv = orig_mkdirat(dirfd, pathname, mode);
	if (storage_find(pathname))
		sendlog(name(), __FUNCTION__, pathname);
	return rv;
}
Exemplo n.º 8
0
int unlink(const char *pathname) {
#ifdef DEBUG
	printf("%s %s\n", __FUNCTION__, pathname);
#endif
	if (!orig_unlink)
		orig_unlink = (orig_unlink_t)dlsym(RTLD_NEXT, "unlink");
	if (!blacklist_loaded)
		load_blacklist();
		
	int rv = orig_unlink(pathname);
	if (storage_find(pathname))
		sendlog(name(), __FUNCTION__, pathname);
	return rv;
}
Exemplo n.º 9
0
FILE *freopen64(const char *pathname, const char *mode, FILE *stream) {
#ifdef DEBUG
	printf("%s %s\n", __FUNCTION__, pathname);
#endif
	if (!orig_freopen64)
		orig_freopen64 = (orig_freopen64_t)dlsym(RTLD_NEXT, "freopen64");
	if (!blacklist_loaded)
		load_blacklist();
		
	FILE *rv = orig_freopen64(pathname, mode, stream);
	if (storage_find(pathname))
		sendlog(name(), __FUNCTION__, pathname);
	return rv;
}
Exemplo n.º 10
0
// fopen
FILE *fopen(const char *pathname, const char *mode) {
#ifdef DEBUG
	printf("%s %s\n", __FUNCTION__, pathname);
#endif
	if (!orig_fopen)
		orig_fopen = (orig_fopen_t)dlsym(RTLD_NEXT, "fopen");
	if (!blacklist_loaded)
		load_blacklist();
		
	FILE *rv = orig_fopen(pathname, mode);
	if (storage_find(pathname))
		sendlog(name(), __FUNCTION__, pathname);
	return rv;
}
Exemplo n.º 11
0
int openat64(int dirfd, const char *pathname, int flags, mode_t mode) {
#ifdef DEBUG
	printf("%s %s\n", __FUNCTION__, pathname);
#endif
	if (!orig_openat64)
		orig_openat64 = (orig_openat64_t)dlsym(RTLD_NEXT, "openat64");
	if (!blacklist_loaded)
		load_blacklist();
		
	int rv = orig_openat64(dirfd, pathname, flags, mode);
	if (storage_find(pathname))
		sendlog(name(), __FUNCTION__, pathname);
	return rv;
}
Exemplo n.º 12
0
void
openlog(const char* ident, int flags, int facility)
{
	int		n;

	if (ident)
	{
		n = strlen(ident);
		if (n >= sizeof(log.ident))
			n = sizeof(log.ident) - 1;
		memcpy(log.ident, ident, n);
		log.ident[n] = 0;
	}
	else
		log.ident[0] = 0;
	log.facility = facility;
	log.flags = flags;
	if (!(log.flags & LOG_ODELAY))
		sendlog(NiL);
}
Exemplo n.º 13
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;
}