Пример #1
0
int main(int argc, char **argv) {

	signal(SIGINT, ctrlc);

	redis = connect_redis(db_dynamic);
	if(!redis) {
		err("Dowse is not running");
		exit(1);
	}

	reply = cmd_redis(redis,"SUBSCRIBE %s", CHAN);
	freeReplyObject(reply);

	if(redisGetReply(redis,(void**)&reply) == REDIS_OK) {

		// func("reply type: %u", reply->type);
		if(reply->type == REDIS_REPLY_ARRAY
		   && reply->elements == 3) {
			redisReply *r;
			// channels return arrays
			// 1st 2 arrays: message command-fifo-pipe
			// so we are interested only in the 3rd csv string
			r = reply->element[2];
			fprintf(stdout, "%s\n", r->str);
			fflush(stdout);
		}

		freeReplyObject(reply);
		reply = NULL;
	}
	if(reply) freeReplyObject(reply);
	if(redis) redisFree(redis);
	return(0);
}
Пример #2
0
int
dowse_start(logerr_t *a_logerr) {
    /*
     * The "start" function is called once, when the program
     * starts.  It is used to initialize the plugin.  If the
     * plugin wants to write debugging and or error messages,
     * it should save the a_logerr pointer passed from the
     * parent code.
     */

    logerr = a_logerr;
    if (filepfx) {
        logerr("Logging to file: %s\n", filepfx);
        fileout = fopen(filepfx, "a");
        if (0 == fileout) {
            logerr("%s: %s\n", filepfx, strerror(errno));
            exit(1);
        }
    }

    // get own hostname
    gethostname(hostname,(size_t)MAX_DOMAIN);

    visited = hashmap_new();

    // load the domain-list path if there
    if(listpath) load_domainlist(listpath);

    connect_redis();

    return 0;
}
Пример #3
0
//定时检查资源的长连接
void handle_time_check(worker_t pworker)
{
    connector_t pconredis = pworker->redis;

    if (pconredis->state == CONN_STATE_NONE || pconredis->state == CONN_STATE_CLOSED)
        connect_redis(pconredis);
    else
        reids_heartbeat(pconredis);

    //增加对list结构中的元素的遍历,keycount是不是存在没有删除的情况??
}
Пример #4
0
int main(int argc, char **argv) {
    
    char *dns, *ip, *action, *epoch, *domain, *tld, *group;
    long long int hits;

    redis = connect_redis(db_dynamic);

    signal(SIGINT, ctrlc);

    reply = cmd_redis(redis,"SUBSCRIBE dns-query-channel");
    freeReplyObject(reply);
    while(redisGetReply(redis,(void**)&reply) == REDIS_OK) {
        if(quit) break;

        dns = strtok(reply->element[2]->str,",");
        if(!dns) continue;
        ip = strtok(NULL,",");
        if(!ip) continue;
        action = strtok(NULL,",");
        if(!action) continue;
        epoch = strtok(NULL,",");
        if(!epoch) continue;
        domain = strtok(NULL,",");
        if(!domain) continue;
        tld = strtok(NULL,",");
        if(!tld) continue;
        group = strtok(NULL,","); // optional
        

        hits = atoll(action);

        // render
        if(!group)
            snprintf(output,MAX_OUTPUT,"%s|%s|%c|%s/%s",
                     epoch,ip,(hits==1)?'A':'M',tld,domain);
        else
            snprintf(output,MAX_OUTPUT,"%s|%s|%c|%s/%s/%s",
                     epoch,ip,(hits==1)?'A':'M',tld,group,domain);
            
        fprintf(stdout,"%s\n",output);
        fflush(stdout);

        freeReplyObject(reply);
    }

    exit(0);
}