Exemple #1
0
// takes over the GString
int homer_send(struct homer_sender *hs, GString *s, const str *id, const endpoint_t *src,
		const endpoint_t *dst, const struct timeval *tv)
{
	if (!hs)
		goto out;
	if (!s)
		goto out;
	if (!s->len) // empty write, shouldn't happen
		goto out;

	ilog(LOG_DEBUG, "JSON to send to Homer: '"STR_FORMAT"'", G_STR_FMT(s));

	if (send_hepv3(s, id, hs->capture_id, src, dst, tv))
		goto out;

	mutex_lock(&hs->lock);
	if (hs->send_queue.length < SEND_QUEUE_LIMIT) {
		g_queue_push_tail(&hs->send_queue, s);
		s = NULL;
	}
	else
		ilog(LOG_ERR, "Send queue length limit (%i) reached, dropping Homer message", SEND_QUEUE_LIMIT);
	hs->state(hs);
	mutex_unlock(&hs->lock);

out:
	if (s)
		g_string_free(s, TRUE);
	return 0;
}
Exemple #2
0
int send_hep_basic (rc_info_t *rcinfo, unsigned char *data, unsigned int len) {

	unsigned char *zipData = NULL;
        int sendzip = 0;

#ifdef USE_ZLIB
        int status = 0;
        unsigned long dlen;

        if(pl_compress && hep_version == 3) {
                //dlen = len/1000+len*len+13;

                dlen = compressBound(len);

                zipData  = malloc(dlen); /* give a little bit memmory */

                /* do compress */
                status = compress( zipData, &dlen, data, len );
                if( status != Z_OK ){
                      LERR( "data couldn't be compressed\n");
                      sendzip = 0;
                      if(zipData) free(zipData); /* release */
                }                   
                else {              
                        sendzip = 1;
                        len = dlen;
                }
        }

#endif /* USE_ZLIB */

        switch(hep_version) {
        
            case 3:
		return send_hepv3(rcinfo, sendzip  ? zipData : data , len, sendzip);
                break;
                
            case 2:            
            case 1:        
                return send_hepv2(rcinfo, data, len);                    
                break;
                
            default:
                LERR( "Unsupported HEP version [%d]\n", hep_version);                
                break;
        }

	if(zipData) free(zipData);
        
        return 0;
}