Exemplo n.º 1
0
void decode_time(pTHX_ unsigned char *input, STRLEN len, struct cc_type *type, SV *output)
{
    int64_t nano, seconds, hours, minutes;
    STRLEN pvlen;
    char *result;

    union {
        unsigned char bytes[8];
        int64_t bigint;
    } bytes_or_bigint;

    if (UNLIKELY(len != 8))
        croak("decode_time: len != 8");

    memcpy(bytes_or_bigint.bytes, input, 8);
    bswap8(bytes_or_bigint.bytes);

    if (UNLIKELY(bytes_or_bigint.bigint < 0 || bytes_or_bigint.bigint > 86399999999999))
        croak("decode_time: invalid value");

    nano =    bytes_or_bigint.bigint % 1000000000;
    seconds = bytes_or_bigint.bigint / 1000000000;
    hours =   seconds / 3600;
    minutes = (seconds % 3600) / 60;
    seconds = seconds % 60;

    sv_setpvf(output, "%lld:%.2lld:%.2lld.%lld", hours, minutes, seconds, nano);
    result = SvPV(output, pvlen);
    while (result[pvlen-1] == '0')
        pvlen--;
    if (result[pvlen-1] == '.')
        pvlen--;
    SvCUR_set(output, pvlen);
}
Exemplo n.º 2
0
static int
set_record(struct _std_event *ev_ptr, char *response,struct _firewall_info *fw_info){

	if(fw_info){
		/* equals to NULL means its a key value firewall
 		*  else a regular expression firewall
 		*/
		if(fw_info->fw_regex == NULL) {
			//printf(" key value type log \n");
			if(parse_keyvalue(ev_ptr,response,fw_info->un.kv)<0){
				//printf("Not able to parse kv_pair\n");	
				return -1;
			}
		}else{
#ifdef REGEX
			if( regex_event_count++ < MAX_REGEX_EVENTS ){
				char logid[50];
				//int i_log_id;
				struct _log_info *found_log_info=NULL;
				//printf(" regex type log $log=%s\n",response);
				sv_setpvf(sv , "$log='%s'" , response);
				eval_sv(sv , G_SCALAR);

				/* Apply fw_info->regex and get log id
				* use that log id to get log_info struct from log_info_hash
				*/ 
				if(SvIV(eval_pv(fw_info->fw_regex,TRUE))){
					strncpy(logid,SvPV(get_sv("logtype" , FALSE) , n_a), sizeof(logid)-1);
					//printf(" logtype = -%s-\n" , logid);
					//i_log_id=atoi(logid);	
					HASH_FIND_STR(fw_info->un.log_hash, logid , found_log_info);

					if(found_log_info==NULL){
						printf(" no log info found for logid %s\n",logid);
						return -1;
					}
					if(  parse_regex( ev_ptr, response, found_log_info )<0  ){
						printf(" parsing regex error  %s\n",logid);
						return -1;
					}
				}else{
					printf("fw_regex did not work \n");
				}
			}else{
				regex_event_count=0;
				perl_reset();
			}
#endif
		}
		
	}else{
		printf("fw_info for given ip address is blank.%s\n",response);
		return -1;
	} 
	return 1;
	
	
}
Exemplo n.º 3
0
void decode_uuid(pTHX_ unsigned char *input, STRLEN len, struct cc_type *type, SV *output)
{
    if (UNLIKELY(len != 16))
        croak("decode_uuid: len != 16");

    sv_setpvf(output, "%.2x%.2x%.2x%.2x-%.2x%.2x-%.2x%.2x-%.2x%.2x-%.2x%.2x%.2x%.2x%.2x%.2x",
        input[0],  input[1],  input[2],  input[3],
        input[4],  input[5],  input[6],  input[7],
        input[8],  input[9],  input[10], input[11],
        input[12], input[13], input[14], input[15]);
}
Exemplo n.º 4
0
/* 32bit compat */
void decode_time(pTHX_ unsigned char *input, STRLEN len, struct cc_type *type, SV *output)
{
    int32_t nano, seconds, hours, minutes;
    char *txt;
    char workbuf[20];
    STRLEN txt_len;

    decode_varint(aTHX_ input, len, type, output);
    /* output now contains a string represending the ns since midnight */

    txt = SvPV(output, txt_len);
    if (txt_len > 14) {
        croak("decode_time: invalid value");
    }

    if (txt_len <= 9) {
        memset(workbuf, 0, 20);
        memcpy(workbuf, txt, txt_len);
        seconds = 0;
        nano = atoi(workbuf);
    } else {
        memset(workbuf, 0, 20);
        memcpy(workbuf, txt+txt_len-9, 9);
        nano = atoi(workbuf);
        memset(workbuf, 0, 20);
        memcpy(workbuf, txt, txt_len-9);
        seconds = atoi(workbuf);
    }

    hours   = seconds / 3600;
    minutes = (seconds % 3600) / 60;
    seconds = seconds % 60;

    sv_setpvf(output, "%d:%.2d:%.2d.%d", hours, minutes, seconds, nano);
    txt = SvPV(output, txt_len);
    while (txt[txt_len-1] == '0')
        txt_len--;
    if (txt[txt_len-1] == '.')
        txt_len--;
    SvCUR_set(output, txt_len);
}
Exemplo n.º 5
0
void decode_date(pTHX_ unsigned char *input, STRLEN len, struct cc_type *type, SV *output)
{
    uint32_t ind;
    double f, e, J, h, g, Y, M, D;

    if (UNLIKELY(len != 4))
        croak("decode_date: len != 4");

    ind = ntohl(*(uint32_t*)input);

    /* This is why unit tests exist. :-) */
    J = ind;
    J -= 0x80000000 - 2440588;

    f = J + 1401 + floor((floor((4 * J + 274277) / 146097) * 3) / 4) - 38;
    e = (4 * f) + 3;
    g = floor(fmod_properly(e, 1461) / 4);
    h = 5 * g + 2;
    D = floor(fmod_properly(h, 153) / 5) + 1;
    M = fmod_properly((floor(h / 153) + 2), 12) + 1;
    Y = floor(e / 1461) - 4716 + floor((12 + 2 - M) / 12);

    sv_setpvf(output, "%.0lf-%02.0lf-%02.0lf", Y, M, D);
}
Exemplo n.º 6
0
int
perl_math_int64_load(int required_version) {
    dTHX;
    SV **svp;
    eval_pv("require Math::Int64", TRUE);
    if (SvTRUE(ERRSV)) return 0;

   math_int64_c_api_hash = get_hv("Math::Int64::C_API", 0);
    if (!math_int64_c_api_hash) {
        sv_setpv(ERRSV, "Unable to load Math::Int64 C API");
        SvSETMAGIC(ERRSV);
        return 0;
    }

    svp = hv_fetch(math_int64_c_api_hash, "min_version", 11, 0);
    if (!svp) svp = hv_fetch(math_int64_c_api_hash, "version", 7, 1);
    if (!svp || !*svp) {
        sv_setpv(ERRSV, "Unable to retrieve C API version for Math::Int64");
        SvSETMAGIC(ERRSV);
        return 0;
    }
    math_int64_c_api_min_version = SvIV(*svp);

    svp = hv_fetch(math_int64_c_api_hash, "max_version", 11, 0);
    if (!svp) svp = hv_fetch(math_int64_c_api_hash, "version", 7, 1);
    if (!svp || !*svp) {
        sv_setpv(ERRSV, "Unable to retrieve C API version for Math::Int64");
        SvSETMAGIC(ERRSV);
        return 0;
    }
    math_int64_c_api_max_version = SvIV(*svp);

    if ((required_version < math_int64_c_api_min_version) ||
        (required_version > math_int64_c_api_max_version)) {
        sv_setpvf(ERRSV,
                  "Math::Int64 C API version mismatch. "
                  "The installed module supports versions %d to %d but %d is required",
                  math_int64_c_api_min_version,
                  math_int64_c_api_max_version,
                  required_version);
        SvSETMAGIC(ERRSV);
        return 0;
    }

    svp = hv_fetch(math_int64_c_api_hash, "SvI64", 5, 0);
    if (!svp || !*svp) {
        sv_setpv(ERRSV, "Unable to fetch pointer 'SvI64' C function from Math::Int64");
        SvSETMAGIC(ERRSV);
        return 0;
    }
    math_int64_c_api_SvI64 = INT2PTR(void *, SvIV(*svp));
    svp = hv_fetch(math_int64_c_api_hash, "SvI64OK", 7, 0);
    if (!svp || !*svp) {
        sv_setpv(ERRSV, "Unable to fetch pointer 'SvI64OK' C function from Math::Int64");
        SvSETMAGIC(ERRSV);
        return 0;
    }
    math_int64_c_api_SvI64OK = INT2PTR(void *, SvIV(*svp));
    svp = hv_fetch(math_int64_c_api_hash, "SvU64", 5, 0);
    if (!svp || !*svp) {
        sv_setpv(ERRSV, "Unable to fetch pointer 'SvU64' C function from Math::Int64");
        SvSETMAGIC(ERRSV);
        return 0;
    }
    math_int64_c_api_SvU64 = INT2PTR(void *, SvIV(*svp));
    svp = hv_fetch(math_int64_c_api_hash, "SvU64OK", 7, 0);
    if (!svp || !*svp) {
        sv_setpv(ERRSV, "Unable to fetch pointer 'SvU64OK' C function from Math::Int64");
        SvSETMAGIC(ERRSV);
        return 0;
    }
    math_int64_c_api_SvU64OK = INT2PTR(void *, SvIV(*svp));
    svp = hv_fetch(math_int64_c_api_hash, "newSVi64", 8, 0);
    if (!svp || !*svp) {
        sv_setpv(ERRSV, "Unable to fetch pointer 'newSVi64' C function from Math::Int64");
        SvSETMAGIC(ERRSV);
        return 0;
    }
    math_int64_c_api_newSVi64 = INT2PTR(void *, SvIV(*svp));
    svp = hv_fetch(math_int64_c_api_hash, "newSVu64", 8, 0);
    if (!svp || !*svp) {
        sv_setpv(ERRSV, "Unable to fetch pointer 'newSVu64' C function from Math::Int64");
        SvSETMAGIC(ERRSV);
        return 0;
    }
    math_int64_c_api_newSVu64 = INT2PTR(void *, SvIV(*svp));
    svp = hv_fetch(math_int64_c_api_hash, "randU64", 7, 0);
    if (!svp || !*svp) {
        sv_setpv(ERRSV, "Unable to fetch pointer 'randU64' C function from Math::Int64");
        SvSETMAGIC(ERRSV);
        return 0;
    }
    math_int64_c_api_randU64 = INT2PTR(void *, SvIV(*svp));

    return 1;
}
Exemplo n.º 7
0
void set_perl_var(char *string, double value) {
	sv_setpvf(perlBuf, "%f", value);
}