int pf_tbladdr(struct snmp_context __unused *ctx, struct snmp_value __unused *val, u_int __unused sub, u_int __unused vindex, enum snmp_op __unused op) { asn_subid_t which = val->var.subs[sub - 1]; struct pfa_entry *e = NULL; if ((time(NULL) - pfa_table_age) > PFA_TABLE_MAXAGE) pfa_refresh(); switch (op) { case SNMP_OP_SET: return (SNMP_ERR_NOT_WRITEABLE); case SNMP_OP_GETNEXT: if ((e = NEXT_OBJECT_INT(&pfa_table, &val->var, sub)) == NULL) return (SNMP_ERR_NOSUCHNAME); val->var.len = sub + 1; val->var.subs[sub] = e->index; break; case SNMP_OP_GET: if (val->var.len - sub != 1) return (SNMP_ERR_NOSUCHNAME); if ((e = pfa_table_find(val->var.subs[sub])) == NULL) return (SNMP_ERR_NOSUCHNAME); break; case SNMP_OP_COMMIT: case SNMP_OP_ROLLBACK: default: abort(); } switch (which) { case LEAF_pfTablesAddrNetType: if (e->pfas.pfras_a.pfra_af == AF_INET) val->v.integer = pfTablesAddrNetType_ipv4; else if (e->pfas.pfras_a.pfra_af == AF_INET6) val->v.integer = pfTablesAddrNetType_ipv6; else return (SNMP_ERR_GENERR); break; case LEAF_pfTablesAddrNet: if (e->pfas.pfras_a.pfra_af == AF_INET) { return (string_get(val, (u_char *)&e->pfas.pfras_a.pfra_ip4addr, 4)); } else if (e->pfas.pfras_a.pfra_af == AF_INET6) return (string_get(val, (u_char *)&e->pfas.pfras_a.pfra_ip6addr, 16)); else return (SNMP_ERR_GENERR); break; case LEAF_pfTablesAddrPrefix: val->v.integer = (int32_t) e->pfas.pfras_a.pfra_net; break; case LEAF_pfTablesAddrTZero: val->v.uint32 = (time(NULL) - e->pfas.pfras_tzero) * 100; break; case LEAF_pfTablesAddrBytesInPass: val->v.counter64 = e->pfas.pfras_bytes[PFR_DIR_IN][PFR_OP_PASS]; break; case LEAF_pfTablesAddrBytesInBlock: val->v.counter64 = e->pfas.pfras_bytes[PFR_DIR_IN][PFR_OP_BLOCK]; break; case LEAF_pfTablesAddrBytesOutPass: val->v.counter64 = e->pfas.pfras_bytes[PFR_DIR_OUT][PFR_OP_PASS]; break; case LEAF_pfTablesAddrBytesOutBlock: val->v.counter64 = e->pfas.pfras_bytes[PFR_DIR_OUT][PFR_OP_BLOCK]; break; case LEAF_pfTablesAddrPktsInPass: val->v.counter64 = e->pfas.pfras_packets[PFR_DIR_IN][PFR_OP_PASS]; break; case LEAF_pfTablesAddrPktsInBlock: val->v.counter64 = e->pfas.pfras_packets[PFR_DIR_IN][PFR_OP_BLOCK]; break; case LEAF_pfTablesAddrPktsOutPass: val->v.counter64 = e->pfas.pfras_packets[PFR_DIR_OUT][PFR_OP_PASS]; break; case LEAF_pfTablesAddrPktsOutBlock: val->v.counter64 = e->pfas.pfras_packets[PFR_DIR_OUT][PFR_OP_BLOCK]; break; default: return (SNMP_ERR_NOSUCHNAME); } return (SNMP_ERR_NOERROR); }
/* Walk all references for an ObjectIndex and construct the hprof CLASS dump. */ static void dump_class_and_supers(JNIEnv *env, ObjectIndex object_index, RefIndex list) { SiteIndex site_index; SerialNumber trace_serial_num; RefIndex index; ClassIndex super_cnum; ObjectIndex super_index; LoaderIndex loader_index; ObjectIndex signers_index; ObjectIndex domain_index; FieldInfo *fields; jvalue *fvalues; jint n_fields; jlong size; ClassIndex cnum; char *sig; ObjectKind kind; TraceIndex trace_index; Stack *cpool_values; ConstantPoolValue *cpool; jint cpool_count; jboolean skip_fields; HPROF_ASSERT(object_index!=0); kind = object_get_kind(object_index); if ( kind != OBJECT_CLASS ) { return; } site_index = object_get_site(object_index); HPROF_ASSERT(site_index!=0); cnum = site_get_class_index(site_index); HPROF_ASSERT(cnum!=0); if ( class_get_status(cnum) & CLASS_DUMPED ) { return; } class_add_status(cnum, CLASS_DUMPED); size = (jlong)object_get_size(object_index); super_index = 0; super_cnum = class_get_super(cnum); if ( super_cnum != 0 ) { super_index = class_get_object_index(super_cnum); if ( super_index != 0 ) { dump_class_and_supers(env, super_index, object_get_references(super_index)); } } trace_index = site_get_trace_index(site_index); HPROF_ASSERT(trace_index!=0); trace_serial_num = trace_get_serial_number(trace_index); sig = string_get(class_get_signature(cnum)); n_fields = 0; fields = NULL; fvalues = NULL; skip_fields = JNI_TRUE; if ( class_get_all_fields(env, cnum, &n_fields, &fields) == 0 ) { if ( n_fields > 0 ) { skip_fields = JNI_FALSE; fvalues = (jvalue*)HPROF_MALLOC(n_fields*(int)sizeof(jvalue)); (void)memset(fvalues, 0, n_fields*(int)sizeof(jvalue)); } } /* We use a Stack just because it will automatically expand as needed */ cpool_values = stack_init(16, 16, sizeof(ConstantPoolValue)); cpool = NULL; cpool_count = 0; loader_index = class_get_loader(cnum); signers_index = 0; domain_index = 0; index = list; while ( index != 0 ) { RefInfo *info; info = get_info(index); /* Process reference objects, many not used right now. */ switch ( info->kind ) { case JVMTI_REFERENCE_STATIC_FIELD: /* If the class_tag is 0, it is possible for * info->element_index to be >= n_fields * and when this happens we just skip this field ref * for now. We probably have a java.lang.Object class * with n_fields==0, which is probably the wrong class. */ if (info->class_tag == (jlong)0 || skip_fields == JNI_TRUE ) { break; } HPROF_ASSERT(info->element_index < n_fields); if (info->element_index < n_fields) { ObjectIndex field_object_index; /* Field index is referrer_index from referrer_tag */ field_object_index = tag_to_object_index(info->object_tag); fvalues[info->element_index].i = field_object_index; } break; case JVMTI_REFERENCE_CONSTANT_POOL: { ConstantPoolValue cpv; ObjectIndex cp_object_index; SiteIndex cp_site_index; ClassIndex cp_cnum; cp_object_index = tag_to_object_index(info->object_tag); HPROF_ASSERT(cp_object_index!=0); cp_site_index = object_get_site(cp_object_index); HPROF_ASSERT(cp_site_index!=0); cp_cnum = site_get_class_index(cp_site_index); cpv.constant_pool_index = info->element_index; cpv.sig_index = class_get_signature(cp_cnum); cpv.value.i = cp_object_index; stack_push(cpool_values, (void*)&cpv); cpool_count++; break; } default: break; } index = info->next; } /* FIXUP: Fill rest of static primitive fields? If requested? */ /* Use: value = getStaticFieldValue(env, klass, field, field_sig); ? */ HPROF_ASSERT(cpool_count==stack_depth(cpool_values)); if ( cpool_count > 0 ) { cpool = (ConstantPoolValue*)stack_element(cpool_values, 0); } io_heap_class_dump(cnum, sig, object_index, trace_serial_num, super_index, loader_index, signers_index, domain_index, (jint)size, cpool_count, cpool, n_fields, fields, fvalues); stack_term(cpool_values); if ( fvalues != NULL ) { HPROF_FREE(fvalues); } }
static int modregex_split (INSTANCE * my, int * params) { const char * reg = string_get(params[0]); const char * str = string_get(params[1]); int * result_array = (int *)params[2]; int result_array_size = params[3]; int count = 0; int pos, lastpos = 0; struct re_pattern_buffer pb; struct re_registers re; int start[16]; int end[16]; /* Alloc the pattern resources */ memset (&pb, 0, sizeof(pb)); memset (&re, 0, sizeof(re)); pb.buffer = malloc(4096); pb.allocated = 4096; pb.fastmap = malloc(256); pb.regs_allocated = 16; re.num_regs = 16; re.start = start; re.end = end; re_syntax_options = RE_SYNTAX_POSIX_MINIMAL_EXTENDED; /* Match the regex */ if (re_compile_pattern (reg, strlen(reg), &pb) == 0) { for (;;) { pos = re_search (&pb, str, strlen(str), lastpos, strlen(str), &re); if (pos == -1) break; *result_array = string_newa (str + lastpos, pos-lastpos); string_use(*result_array); result_array++; count++; result_array_size--; if (result_array_size == 0) break; lastpos = pos + re_match (&pb, str, strlen(str), pos, 0); if (lastpos < pos) break; if (lastpos == pos) lastpos++; } if (result_array_size > 0) { *result_array = string_new (str + lastpos); string_use (*result_array); count++; } } /* Free the resources */ free (pb.buffer); free (pb.fastmap); string_discard(params[0]); string_discard(params[1]); return count; }
static int moddir_open( INSTANCE * my, int * params ) { int result = ( int ) dir_open( string_get( params[ 0 ] ) ); string_discard( params[ 0 ] ); return result; }
int pf_iftable(struct snmp_context __unused *ctx, struct snmp_value *val, u_int sub, u_int __unused vindex, enum snmp_op op) { asn_subid_t which = val->var.subs[sub - 1]; struct pfi_entry *e = NULL; if ((time(NULL) - pfi_table_age) > PFI_TABLE_MAXAGE) pfi_refresh(); switch (op) { case SNMP_OP_SET: return (SNMP_ERR_NOT_WRITEABLE); case SNMP_OP_GETNEXT: if ((e = NEXT_OBJECT_INT(&pfi_table, &val->var, sub)) == NULL) return (SNMP_ERR_NOSUCHNAME); val->var.len = sub + 1; val->var.subs[sub] = e->index; break; case SNMP_OP_GET: if (val->var.len - sub != 1) return (SNMP_ERR_NOSUCHNAME); if ((e = pfi_table_find(val->var.subs[sub])) == NULL) return (SNMP_ERR_NOSUCHNAME); break; case SNMP_OP_COMMIT: case SNMP_OP_ROLLBACK: default: abort(); } switch (which) { case LEAF_pfInterfacesIfDescr: return (string_get(val, e->pfi.pfik_name, -1)); case LEAF_pfInterfacesIfType: val->v.integer = PFI_IFTYPE_INSTANCE; break; case LEAF_pfInterfacesIfTZero: val->v.uint32 = (time(NULL) - e->pfi.pfik_tzero) * 100; break; case LEAF_pfInterfacesIfRefsRule: val->v.uint32 = e->pfi.pfik_rulerefs; break; case LEAF_pfInterfacesIf4BytesInPass: val->v.counter64 = e->pfi.pfik_bytes[IPV4][IN][PASS]; break; case LEAF_pfInterfacesIf4BytesInBlock: val->v.counter64 = e->pfi.pfik_bytes[IPV4][IN][BLOCK]; break; case LEAF_pfInterfacesIf4BytesOutPass: val->v.counter64 = e->pfi.pfik_bytes[IPV4][OUT][PASS]; break; case LEAF_pfInterfacesIf4BytesOutBlock: val->v.counter64 = e->pfi.pfik_bytes[IPV4][OUT][BLOCK]; break; case LEAF_pfInterfacesIf4PktsInPass: val->v.counter64 = e->pfi.pfik_packets[IPV4][IN][PASS]; break; case LEAF_pfInterfacesIf4PktsInBlock: val->v.counter64 = e->pfi.pfik_packets[IPV4][IN][BLOCK]; break; case LEAF_pfInterfacesIf4PktsOutPass: val->v.counter64 = e->pfi.pfik_packets[IPV4][OUT][PASS]; break; case LEAF_pfInterfacesIf4PktsOutBlock: val->v.counter64 = e->pfi.pfik_packets[IPV4][OUT][BLOCK]; break; case LEAF_pfInterfacesIf6BytesInPass: val->v.counter64 = e->pfi.pfik_bytes[IPV6][IN][PASS]; break; case LEAF_pfInterfacesIf6BytesInBlock: val->v.counter64 = e->pfi.pfik_bytes[IPV6][IN][BLOCK]; break; case LEAF_pfInterfacesIf6BytesOutPass: val->v.counter64 = e->pfi.pfik_bytes[IPV6][OUT][PASS]; break; case LEAF_pfInterfacesIf6BytesOutBlock: val->v.counter64 = e->pfi.pfik_bytes[IPV6][OUT][BLOCK]; break; case LEAF_pfInterfacesIf6PktsInPass: val->v.counter64 = e->pfi.pfik_packets[IPV6][IN][PASS]; break; case LEAF_pfInterfacesIf6PktsInBlock: val->v.counter64 = e->pfi.pfik_packets[IPV6][IN][BLOCK]; break; case LEAF_pfInterfacesIf6PktsOutPass: val->v.counter64 = e->pfi.pfik_packets[IPV6][OUT][PASS]; break; case LEAF_pfInterfacesIf6PktsOutBlock: val->v.counter64 = e->pfi.pfik_packets[IPV6][OUT][BLOCK]; break; default: return (SNMP_ERR_NOSUCHNAME); } return (SNMP_ERR_NOERROR); }
/* Walk all references for an ObjectIndex and construct the hprof INST dump. */ static void dump_instance(JNIEnv *env, ObjectIndex object_index, RefIndex list) { jvmtiPrimitiveType primType; SiteIndex site_index; SerialNumber trace_serial_num; RefIndex index; ObjectIndex class_index; jlong size; ClassIndex cnum; char *sig; void *elements; jint num_elements; jint num_bytes; ObjectIndex *values; FieldInfo *fields; jvalue *fvalues; jint n_fields; jboolean skip_fields; jint n_fields_set; ObjectKind kind; TraceIndex trace_index; jboolean is_array; jboolean is_prim_array; HPROF_ASSERT(object_index!=0); kind = object_get_kind(object_index); if ( kind == OBJECT_CLASS ) { return; } site_index = object_get_site(object_index); HPROF_ASSERT(site_index!=0); cnum = site_get_class_index(site_index); HPROF_ASSERT(cnum!=0); size = (jlong)object_get_size(object_index); trace_index = site_get_trace_index(site_index); HPROF_ASSERT(trace_index!=0); trace_serial_num = trace_get_serial_number(trace_index); sig = string_get(class_get_signature(cnum)); class_index = class_get_object_index(cnum); values = NULL; elements = NULL; num_elements = 0; num_bytes = 0; n_fields = 0; skip_fields = JNI_FALSE; n_fields_set = 0; fields = NULL; fvalues = NULL; index = list; is_array = JNI_FALSE; is_prim_array = JNI_FALSE; if ( sig[0] != JVM_SIGNATURE_ARRAY ) { if ( class_get_all_fields(env, cnum, &n_fields, &fields) == 1 ) { /* Trouble getting all the fields, can't trust field index values */ skip_fields = JNI_TRUE; /* It is assumed that the reason why we didn't get the fields * was because the class is not prepared. */ if ( gdata->debugflags & DEBUGFLAG_UNPREPARED_CLASSES ) { if ( list != 0 ) { dump_ref_list(list); debug_message("Instance of unprepared class with refs: %s\n", sig); } else { debug_message("Instance of unprepared class without refs: %s\n", sig); } HPROF_ERROR(JNI_FALSE, "Big Trouble with unprepared class instances"); } } if ( n_fields > 0 ) { fvalues = (jvalue*)HPROF_MALLOC(n_fields*(int)sizeof(jvalue)); (void)memset(fvalues, 0, n_fields*(int)sizeof(jvalue)); } } else { is_array = JNI_TRUE; if ( sig[0] != 0 && sigToPrimSize(sig+1) != 0 ) { is_prim_array = JNI_TRUE; } } while ( index != 0 ) { RefInfo *info; jvalue ovalue; static jvalue empty_value; info = get_info(index); /* Process reference objects, many not used right now. */ switch ( info->flavor ) { case INFO_OBJECT_REF_DATA: switch ( info->refKind ) { case JVMTI_HEAP_REFERENCE_SIGNERS: case JVMTI_HEAP_REFERENCE_PROTECTION_DOMAIN: case JVMTI_HEAP_REFERENCE_CLASS_LOADER: case JVMTI_HEAP_REFERENCE_INTERFACE: case JVMTI_HEAP_REFERENCE_STATIC_FIELD: case JVMTI_HEAP_REFERENCE_CONSTANT_POOL: /* Should never be seen on an instance dump */ HPROF_ASSERT(0); break; case JVMTI_HEAP_REFERENCE_FIELD: if ( skip_fields == JNI_TRUE ) { break; } HPROF_ASSERT(is_array!=JNI_TRUE); ovalue = empty_value; ovalue.i = info->object_index; fill_in_field_value(list, fields, fvalues, n_fields, info->index, ovalue, 0); n_fields_set++; HPROF_ASSERT(n_fields_set <= n_fields); break; case JVMTI_HEAP_REFERENCE_ARRAY_ELEMENT: /* We get each object element one at a time. */ HPROF_ASSERT(is_array==JNI_TRUE); HPROF_ASSERT(is_prim_array!=JNI_TRUE); if ( num_elements <= info->index ) { int nbytes; if ( values == NULL ) { num_elements = info->index + 1; nbytes = num_elements*(int)sizeof(ObjectIndex); values = (ObjectIndex*)HPROF_MALLOC(nbytes); (void)memset(values, 0, nbytes); } else { void *new_values; int new_size; int obytes; obytes = num_elements*(int)sizeof(ObjectIndex); new_size = info->index + 1; nbytes = new_size*(int)sizeof(ObjectIndex); new_values = (void*)HPROF_MALLOC(nbytes); (void)memcpy(new_values, values, obytes); (void)memset(((char*)new_values)+obytes, 0, nbytes-obytes); HPROF_FREE(values); num_elements = new_size; values = new_values; } } HPROF_ASSERT(values[info->index]==0); values[info->index] = info->object_index; break; default: /* Ignore, not needed */ break; } break; case INFO_PRIM_FIELD_DATA: if ( skip_fields == JNI_TRUE ) { break; } HPROF_ASSERT(info->primType!=0); HPROF_ASSERT(info->length==-1); HPROF_ASSERT(info->refKind==JVMTI_HEAP_REFERENCE_FIELD); HPROF_ASSERT(is_array!=JNI_TRUE); ovalue = get_key_value(index); fill_in_field_value(list, fields, fvalues, n_fields, info->index, ovalue, info->primType); n_fields_set++; HPROF_ASSERT(n_fields_set <= n_fields); break; case INFO_PRIM_ARRAY_DATA: /* Should only be one, and it's handled below */ HPROF_ASSERT(info->refKind==0); /* We assert that nothing else was saved with this array */ HPROF_ASSERT(index==list&&info->next==0); HPROF_ASSERT(is_array==JNI_TRUE); HPROF_ASSERT(is_prim_array==JNI_TRUE); primType = info->primType; elements = get_key_elements(index, primType, &num_elements, &num_bytes); HPROF_ASSERT(info->length==num_elements); size = num_bytes; break; default: HPROF_ASSERT(0); break; } index = info->next; } if ( is_array == JNI_TRUE ) { if ( is_prim_array == JNI_TRUE ) { HPROF_ASSERT(values==NULL); io_heap_prim_array(object_index, trace_serial_num, (jint)size, num_elements, sig, elements); } else { HPROF_ASSERT(elements==NULL); io_heap_object_array(object_index, trace_serial_num, (jint)size, num_elements, sig, values, class_index); } } else { io_heap_instance_dump(cnum, object_index, trace_serial_num, class_index, (jint)size, sig, fields, fvalues, n_fields); } if ( values != NULL ) { HPROF_FREE(values); } if ( fvalues != NULL ) { HPROF_FREE(fvalues); } if ( elements != NULL ) { /* Do NOT free elements, it's a key in the table, leave it be */ } }
/* * prototype of this function was genrated by gensnmptree tool in header file * hostres_tree.h * Returns SNMP_ERR_NOERROR on success */ int op_hrSystem(struct snmp_context *ctx, struct snmp_value *value, u_int sub, u_int iidx __unused, enum snmp_op curr_op) { int err; u_char *str; switch (curr_op) { case SNMP_OP_GET: switch (value->var.subs[sub - 1]) { case LEAF_hrSystemUptime: return (OS_getSystemUptime(&value->v.uint32)); case LEAF_hrSystemDate: return (OS_getSystemDate(value)); case LEAF_hrSystemInitialLoadDevice: value->v.uint32 = 0; /* FIXME */ return (SNMP_ERR_NOERROR); case LEAF_hrSystemInitialLoadParameters: if ((err = OS_getSystemInitialLoadParameters(&str)) != SNMP_ERR_NOERROR) return (err); return (string_get(value, str, -1)); case LEAF_hrSystemNumUsers: return (OS_getSystemNumUsers(&value->v.uint32)); case LEAF_hrSystemProcesses: return (OS_getSystemProcesses(&value->v.uint32)); case LEAF_hrSystemMaxProcesses: return (OS_getSystemMaxProcesses(&value->v.uint32)); } abort(); case SNMP_OP_SET: switch (value->var.subs[sub - 1]) { case LEAF_hrSystemDate: if ((ctx->scratch->ptr1 = OS_checkSystemDateInput(value->v.octetstring.octets, value->v.octetstring.len)) == NULL) return (SNMP_ERR_WRONG_VALUE); return (SNMP_ERR_NOERROR); case LEAF_hrSystemInitialLoadDevice: case LEAF_hrSystemInitialLoadParameters: return (SNMP_ERR_NOT_WRITEABLE); } abort(); case SNMP_OP_ROLLBACK: switch (value->var.subs[sub - 1]) { case LEAF_hrSystemDate: free(ctx->scratch->ptr1); return (SNMP_ERR_NOERROR); case LEAF_hrSystemInitialLoadDevice: case LEAF_hrSystemInitialLoadParameters: abort(); } abort(); case SNMP_OP_COMMIT: switch (value->var.subs[sub - 1]) { case LEAF_hrSystemDate: (void)OS_setSystemDate(ctx->scratch->ptr1); free(ctx->scratch->ptr1); return (SNMP_ERR_NOERROR); case LEAF_hrSystemInitialLoadDevice: case LEAF_hrSystemInitialLoadParameters: abort(); } abort(); case SNMP_OP_GETNEXT: abort(); } abort(); }
static int modtime_ftime( INSTANCE * my, int * params ) { char buffer[128] ; char * format ; struct tm * t ; int ret ; time_t tim ; char * base ; #ifdef _WIN32 /* aux buffer to make all changes... */ char aux[128] ; unsigned char pos ; #endif format = base = strdup( string_get( params[0] ) ) ; string_discard( params[0] ) ; #ifdef _WIN32 /* Addapting win32 strftime formats to linux formats */ /* HEAVY PATCH... :( */ pos = 0 ; while ( *format && pos < 127 ) { switch ( *format ) { case '%': /* MIGHT NEED CONVERSION... */ aux[pos] = *format ; pos++ ; format++ ; switch ( *format ) { case 'e': aux[pos++] = '#' ; aux[pos] = 'd' ; break ; case 'l': aux[pos++] = '#' ; aux[pos] = 'I' ; break ; case 'k': aux[pos++] = '#' ; aux[pos] = 'H' ; break ; case 'P': aux[pos] = 'p' ; break ; case 'C': aux[pos++] = '%' ; aux[pos++] = *format ; aux[pos++] = '%' ; aux[pos] = 'Y' ; break ; case 'u': aux[pos++] = '%' ; aux[pos++] = *format ; aux[pos++] = '%' ; aux[pos] = 'w' ; break ; case '%': //MUST BE %%%% TO KEEP 2 IN POSTPROCESS aux[pos++] = '%' ; aux[pos++] = '%' ; aux[pos] = '%' ; break ; default: aux[pos] = *format ; break ; } break ; default: aux[pos] = *format ; break ; } format++ ; pos++ ; } aux[pos] = 0 ; format = aux ; #endif tim = ( time_t ) params[1] ; t = localtime( &tim ) ; strftime( buffer, sizeof( buffer ), format, t ) ; #ifdef _WIN32 /* win32 postprocess */ aux[0] = '\0' ; format = buffer ; pos = 0 ; while ( *format ) { switch ( *format ) { case '%': format++ ; switch ( *format ) { case 'u': format++ ; if ( *format == '0' ) *format = '7' ; aux[pos] = *format ; break ; case 'C': format++ ; aux[pos++] = *format ; format++ ; aux[pos] = *format ; format++ ; format++ ; break ; default: aux[pos] = *format ; break ; } break ; default: aux[pos] = *format ; break ; } format++ ; pos++; } aux[pos] = '\0' ; strcpy( buffer, aux ) ; #endif ret = string_new( buffer ) ; string_use( ret ) ; free( base ) ; return ret ; }
static int modfile_remove( INSTANCE * my, int * params ) { int r = file_remove( string_get( params[0] ) ) ; string_discard( params[0] ) ; return r ; }
lista_t* conta_inclui(lista_t *contas, lista_t *agencias, lista_t *clientes) { conta_t *conta = NULL; agencia_t *agencia = NULL; cliente_t *cliente = NULL; bool done = false; bool conta_numero_ok = false; bool agencia_ok = false; bool cliente_ok = false; char *str = NULL; conta = (conta_t*)malloc(sizeof(conta_t)); agencia = (agencia_t*)malloc(sizeof(agencia_t)); cliente = (cliente_t*)malloc(sizeof(cliente_t)); printf("--- Inserindo nova Conta ---\n"); while (!done) { if (!conta_numero_ok) { printf("Numero: "); str = string_get(CONTA_NUMERO_MAX_LEN); if (check_cancelar(str)) { free(str); return contas; } conta->numero = (unsigned int)atoi(str);; free(str); str = NULL; if (lista_busca(contas, conta, compara_conta)) { printf("A conta ja de numero %d ja existe. Use um numero diferente.\n", conta->numero); continue; } conta_numero_ok = true; } if (!agencia_ok) { printf("Agencia codigo: "); str = string_get(AGENCIA_CODIGO_MAX_LEN); if (check_cancelar(str)) { free(str); return contas; } agencia->codigo = (unsigned int)atoi(str); free(str); str = NULL; if (!lista_busca(agencias, agencia, compara_agencia)) { printf("A agencia de codigo %d nao existe.\n", agencia->codigo); continue; } agencia_ok = true; } if (!cliente_ok) { printf("Cliente CPF: "); cliente->cpf = string_get(CLIENTE_CPF_MAX_LEN); if (check_cancelar(cliente->cpf)) { free(cliente); return contas; } if (!lista_busca(clientes, cliente, compara_cliente)) { printf("O cliente de CPF %s nao existe.\n", cliente->cpf); continue; } if (conta_busca_cliente_agencia(contas, cliente, agencia)) { printf("O cliente de CPF %s ja tem uma conta na Agencia de codigo %d.\n", cliente->cpf, agencia->codigo); agencia_ok = false; continue; } cliente_ok = true; } printf("Saldo: "); str = string_get(CONTA_SALDO_MAX_LEN); conta->saldo = (double)atof(str); free(str); str = NULL; printf("Limite: "); str = string_get(CONTA_LIMITE_MAX_LEN); conta->limite = (double)atof(str); free(str); str = NULL; conta->data_criacao = get_time(); printf("---\nDados fornecidos:\n"); printf("Conta numero: %d\n", conta->numero); printf("Agencia codigo: %d\n", agencia->codigo); printf("Cliente CPF: %s\n", cliente->cpf); printf("Data de criacao: %s\n", conta->data_criacao); printf("Saldo: %.2lf\n", conta->saldo); printf("Limite: %.2lf\n", conta->limite); if (true == confirmar_opcao()) { done = true; } else { done = false; conta_numero_ok = false; agencia_ok = false; cliente_ok = false; } } conta->cliente_cpf = cliente->cpf; conta->agencia_codigo = agencia->codigo; return lista_insere(contas, conta); }
static const char * get_text( TEXT * text ) { static char buffer[64]; switch ( text->on ) { case TEXT_TEXT: return text->text; case TEXT_STRING: return string_get( *( int* )text->var ) ; case TEXT_INT: _string_ntoa( buffer, *( int * )text->var ) ; return buffer ; case TEXT_DWORD: _string_utoa( buffer, *( int * )text->var ) ; return buffer ; case TEXT_FLOAT: { char * aux; sprintf( buffer, "%f", *( float * )text->var ) ; aux = buffer + 1; // We know that buffer contain at least 2 chars, skip first while ( *( aux + 1 ) ) aux++; // We can test for pointer + 1 because we know that buffer contain at least 2 chars while ( *aux == '0' && *( aux - 1 ) != '.' ) *aux-- = '\0'; return buffer ; } case TEXT_BYTE: _string_utoa( buffer, *( uint8_t * )text->var ) ; return buffer ; case TEXT_SBYTE: _string_ntoa( buffer, *( int8_t * )text->var ) ; return buffer ; case TEXT_CHAR: *buffer = *( uint8_t * )text->var ; *( buffer + 1 ) = '\0'; return buffer ; case TEXT_WORD: _string_utoa( buffer, *( uint16_t * )text->var ) ; return buffer ; case TEXT_SHORT: _string_ntoa( buffer, *( int16_t * )text->var ) ; return buffer ; case TEXT_CHARARRAY: return ( const char * )( text->var ); case TEXT_POINTER: _string_ptoa( buffer, *( void ** ) text->var ); return buffer ; } return NULL; }
/************************************************************* * * System group */ int op_system_group(struct snmp_context *ctx, struct snmp_value *value, u_int sub, u_int iidx __unused, enum snmp_op op) { asn_subid_t which = value->var.subs[sub - 1]; switch (op) { case SNMP_OP_GETNEXT: abort(); case SNMP_OP_GET: break; case SNMP_OP_SET: switch (which) { case LEAF_sysDescr: if (community != COMM_INITIALIZE) return (SNMP_ERR_NOT_WRITEABLE); return (string_save(value, ctx, -1, &systemg.descr)); case LEAF_sysObjectId: if (community != COMM_INITIALIZE) return (SNMP_ERR_NOT_WRITEABLE); return (oid_save(value, ctx, &systemg.object_id)); case LEAF_sysContact: return (string_save(value, ctx, -1, &systemg.contact)); case LEAF_sysName: return (string_save(value, ctx, -1, &systemg.name)); case LEAF_sysLocation: return (string_save(value, ctx, -1, &systemg.location)); } return (SNMP_ERR_NO_CREATION); case SNMP_OP_ROLLBACK: switch (which) { case LEAF_sysDescr: string_rollback(ctx, &systemg.descr); return (SNMP_ERR_NOERROR); case LEAF_sysObjectId: oid_rollback(ctx, &systemg.object_id); return (SNMP_ERR_NOERROR); case LEAF_sysContact: string_rollback(ctx, &systemg.contact); return (SNMP_ERR_NOERROR); case LEAF_sysName: string_rollback(ctx, &systemg.name); return (SNMP_ERR_NOERROR); case LEAF_sysLocation: string_rollback(ctx, &systemg.location); return (SNMP_ERR_NOERROR); } abort(); case SNMP_OP_COMMIT: switch (which) { case LEAF_sysDescr: string_commit(ctx); return (SNMP_ERR_NOERROR); case LEAF_sysObjectId: oid_commit(ctx); return (SNMP_ERR_NOERROR); case LEAF_sysContact: string_commit(ctx); return (SNMP_ERR_NOERROR); case LEAF_sysName: string_commit(ctx); return (SNMP_ERR_NOERROR); case LEAF_sysLocation: string_commit(ctx); return (SNMP_ERR_NOERROR); } abort(); } /* * Come here for GET. */ switch (which) { case LEAF_sysDescr: return (string_get(value, systemg.descr, -1)); case LEAF_sysObjectId: return (oid_get(value, &systemg.object_id)); case LEAF_sysUpTime: value->v.uint32 = get_ticks() - start_tick; break; case LEAF_sysContact: return (string_get(value, systemg.contact, -1)); case LEAF_sysName: return (string_get(value, systemg.name, -1)); case LEAF_sysLocation: return (string_get(value, systemg.location, -1)); case LEAF_sysServices: value->v.integer = systemg.services; break; case LEAF_sysORLastChange: value->v.uint32 = systemg.or_last_change; break; } return (SNMP_ERR_NOERROR); }
bool ar_extract(struct string *archive, char *membername, struct string *result) { ssize_t len; char *pos; struct ar_hdr *arh; ssize_t memberlen; string_free(result); // clear result buffer at the start len = string_length(archive); if (len < SARMAG) { log_warn("ar_extract: buffer contents too short\n"); return false; } pos = string_get(archive); if (strncmp(pos, ARMAG, sizeof(ARMAG)-1) != 0) { log_warn("ar_extract: no .ar header at the beginning\n"); return false; } pos += sizeof(ARMAG)-1; len -= sizeof(ARMAG)-1; for (;;) { if (len < sizeof(struct ar_hdr)) { log_warn("ar_extract: buffer contents too short\n"); return false; } arh = (struct ar_hdr *)pos; pos += sizeof(struct ar_hdr); len -= sizeof(struct ar_hdr); if (memcmp(arh->ar_fmag,ARFMAG,sizeof(arh->ar_fmag))) { log_warn("ar_extract: buffer corrupt - bad magic at end of header\n"); return false; } memberlen = ar_parseheaderlength(arh->ar_size, sizeof(arh->ar_size)); if (memberlen < 0) { log_warn("ar_extract: buffer corrupt - invalid length field in header\n"); return false; } if (memberlen+(memberlen&1) > len) { log_warn("ar_extract: buffer corrupt - header length bigger than rest of buffer\n"); return false; } if (ar_compare_name(arh->ar_name, sizeof(arh->ar_name), membername)) { // found! if (!string_concatb(result, pos, memberlen)) { log_warn("ar_extract: extract copy failed\n"); return false; } return true; } pos += memberlen+(memberlen&1); len -= memberlen+(memberlen&1); if (len == 0) { // finished, but not found return 1; } else if (len < 0) { // should not happen log_warn("ar_extract: buffer corrupt - buffer too short\n"); return false; } } }
int op_begemot(struct snmp_context *ctx, struct snmp_value *value, u_int sub, u_int iidx __unused, enum snmp_op op) { switch (op) { case SNMP_OP_GET: switch (value->var.subs[sub - 1]) { case LEAF_begemotHrStorageUpdate: value->v.uint32 = storage_tbl_refresh; return (SNMP_ERR_NOERROR); case LEAF_begemotHrFSUpdate: value->v.uint32 = fs_tbl_refresh; return (SNMP_ERR_NOERROR); case LEAF_begemotHrDiskStorageUpdate: value->v.uint32 = disk_storage_tbl_refresh; return (SNMP_ERR_NOERROR); case LEAF_begemotHrNetworkUpdate: value->v.uint32 = network_tbl_refresh; return (SNMP_ERR_NOERROR); case LEAF_begemotHrSWInstalledUpdate: value->v.uint32 = swins_tbl_refresh; return (SNMP_ERR_NOERROR); case LEAF_begemotHrSWRunUpdate: value->v.uint32 = swrun_tbl_refresh; return (SNMP_ERR_NOERROR); case LEAF_begemotHrPkgDir: return (string_get(value, pkg_dir, -1)); } abort(); case SNMP_OP_GETNEXT: abort(); case SNMP_OP_SET: switch (value->var.subs[sub - 1]) { case LEAF_begemotHrStorageUpdate: ctx->scratch->int1 = storage_tbl_refresh; storage_tbl_refresh = value->v.uint32; return (SNMP_ERR_NOERROR); case LEAF_begemotHrFSUpdate: ctx->scratch->int1 = fs_tbl_refresh; fs_tbl_refresh = value->v.uint32; return (SNMP_ERR_NOERROR); case LEAF_begemotHrDiskStorageUpdate: ctx->scratch->int1 = disk_storage_tbl_refresh; disk_storage_tbl_refresh = value->v.uint32; return (SNMP_ERR_NOERROR); case LEAF_begemotHrNetworkUpdate: ctx->scratch->int1 = network_tbl_refresh; network_tbl_refresh = value->v.uint32; return (SNMP_ERR_NOERROR); case LEAF_begemotHrSWInstalledUpdate: ctx->scratch->int1 = swins_tbl_refresh; swins_tbl_refresh = value->v.uint32; return (SNMP_ERR_NOERROR); case LEAF_begemotHrSWRunUpdate: ctx->scratch->int1 = swrun_tbl_refresh; swrun_tbl_refresh = value->v.uint32; return (SNMP_ERR_NOERROR); case LEAF_begemotHrPkgDir: return (string_save(value, ctx, -1, &pkg_dir)); } abort(); case SNMP_OP_COMMIT: switch (value->var.subs[sub - 1]) { case LEAF_begemotHrStorageUpdate: case LEAF_begemotHrFSUpdate: case LEAF_begemotHrDiskStorageUpdate: case LEAF_begemotHrNetworkUpdate: case LEAF_begemotHrSWInstalledUpdate: case LEAF_begemotHrSWRunUpdate: return (SNMP_ERR_NOERROR); case LEAF_begemotHrPkgDir: string_commit(ctx); return (SNMP_ERR_NOERROR); } abort(); case SNMP_OP_ROLLBACK: switch (value->var.subs[sub - 1]) { case LEAF_begemotHrStorageUpdate: storage_tbl_refresh = ctx->scratch->int1; return (SNMP_ERR_NOERROR); case LEAF_begemotHrFSUpdate: fs_tbl_refresh = ctx->scratch->int1; return (SNMP_ERR_NOERROR); case LEAF_begemotHrDiskStorageUpdate: disk_storage_tbl_refresh = ctx->scratch->int1; return (SNMP_ERR_NOERROR); case LEAF_begemotHrNetworkUpdate: network_tbl_refresh = ctx->scratch->int1; return (SNMP_ERR_NOERROR); case LEAF_begemotHrSWInstalledUpdate: swins_tbl_refresh = ctx->scratch->int1; return (SNMP_ERR_NOERROR); case LEAF_begemotHrSWRunUpdate: swrun_tbl_refresh = ctx->scratch->int1; return (SNMP_ERR_NOERROR); case LEAF_begemotHrPkgDir: string_rollback(ctx, &pkg_dir); return (SNMP_ERR_NOERROR); } abort(); } abort(); }
void SipRedirectorGateway::processForm(const HttpRequestContext& requestContext, const HttpMessage& request, HttpMessage*& response) { UtlString string_get("get"); UtlString string_set("set"); UtlString string_prefix("prefix"); UtlString string_destination("destination"); OsSysLog::add(FAC_SIP, PRI_DEBUG, "%s::processForm entered", mLogName.data()); UtlString* user; // Process the request. // Get the body of the request. const HttpBody* request_body = request.getBody(); OsSysLog::add(FAC_SIP, PRI_DEBUG, "%s::processForm A *** request body is '%s'", mLogName.data(), request_body->getBytes()); // Get the values from the form. if (request_body->isMultipart()) { // Extract the values from the form data. UtlHashMap values; int c = request_body->getMultipartCount(); for (int i = 0; i < c; i++) { UtlString* name = new UtlString; if (request_body->getMultipart(i)->getPartHeaderValue("name", *name)) { const char* v; int l; request_body->getMultipartBytes(i, &v, &l); // Strip leading and trailing whitespace from values. UtlString* value = new UtlString(v, l); value->strip(UtlString::both); OsSysLog::add(FAC_SIP, PRI_CRIT, "%s::processForm " "form value '%s' = '%s'", mLogName.data(), name->data(), value->data()); // 'name' and 'value' are now owned by 'values'. values.insertKeyAndValue(name, value); } else { // 'name' is not owned by 'values' and we have to delete it. delete name; } } if (values.findValue(&string_get)) { // This is a "get gateway" request. // Insert the HTML into the response. HttpBody* response_body = new HttpBody(form, -1, CONTENT_TYPE_TEXT_HTML); response->setBody(response_body); } else if (values.findValue(&string_set)) { // This is a "set gateway" request. // Validate the routing prefix. UtlString* prefix = dynamic_cast <UtlString*> (values.findValue(&string_prefix)); if (prefixIsValid(*prefix)) { // Validate the destination. UtlString* destination = dynamic_cast <UtlString*> (values.findValue(&string_destination)); if (destination_is_valid(destination)) { OsSysLog::add(FAC_SIP, PRI_CRIT, "%s::processForm " "add mapping '%s' -> '%s'", mLogName.data(), prefix->data(), destination->data()); mMapLock.acquire(); // Insert the mapping. mMapUserToContacts.insertKeyAndValue(prefix, destination); mMapContactsToUser.insertKeyAndValue(destination, prefix); mMapLock.release(); writeMappings(); } } // Insert the HTML into the response. HttpBody* response_body = new HttpBody(form, -1, CONTENT_TYPE_TEXT_HTML); response->setBody(response_body); } else { // Incomprehensible request. // Insert the HTML into the response. HttpBody* response_body = new HttpBody(form, -1, CONTENT_TYPE_TEXT_HTML); response->setBody(response_body); } } else { // Incomprehensible request. // Insert the default HTML into the response. HttpBody* response_body = new HttpBody(form, -1, CONTENT_TYPE_TEXT_HTML); response->setBody(response_body); } #if 0 #if 0 // This is quite a chore, because getMultipartBytes gets the entire // multipart section, including the trailing delimiter, rather than just // the body, which is what we need. const char* value; int length; request_body->getMultipartBytes(0, &value, &length); #if 0 OsSysLog::add(FAC_SIP, PRI_DEBUG, "%s::processForm A *** seeing '%.*s'", mLogName.data(), length, value); #endif // Advance 'value' over the first \r\n\r\n, which ends the headers. const char* s = strstr(value, "\r\n\r\n"); if (s) { s += 4; // Allow for length of \r\n\r\n. length -= s - value; value = s; } OsSysLog::add(FAC_SIP, PRI_DEBUG, "%s::processForm B *** seeing '%.*s'", mLogName.data(), length, value); #if 0 // Search backward for the last \r, excepting the one in the second-to-last // position, which marks the end of the contents. if (length >= 3) { for (s = value + length - 3; !(s == value || *s == '\r'); s--) { /* empty */ } length = s - value; } OsSysLog::add(FAC_SIP, PRI_DEBUG, "%s::processForm seeing '%.*s'", mLogName.data(), length, value); #endif // Add the mappings. const char* error_msg; int error_location; UtlBoolean success = addMappings(value, length, user, error_msg, error_location); // Construct the response. response = new HttpMessage(); // Send 200 OK reply. response->setResponseFirstHeaderLine(HTTP_PROTOCOL_VERSION, HTTP_OK_CODE, HTTP_OK_TEXT); // Construct the HTML. char buffer1[100]; #if 0 OsSysLog::add(FAC_SIP, PRI_DEBUG, "%s::processForm *** domain '%s'", mLogName.data(), Gatewayredirector->mDomainName.data()); #endif if (success) { OsSysLog::add(FAC_SIP, PRI_DEBUG, "%s::processForm success user '%s'", mLogName.data(), user->data()); sprintf(buffer1, "<code>sip:<font size=\"+1\">%s</font>@%s:65070</code> redirects to:<br />", user->data(), Gatewayredirector->mDomainName.data()); } else { OsSysLog::add(FAC_SIP, PRI_DEBUG, "%s::processForm failure error_msg '%s', error_location %d", mLogName.data(), error_msg, error_location); strcpy(buffer1, "<i>Error:</i>"); } // Transcribe the input value into buffer2. char buffer2[FORM_SIZE]; char* p; int i; if (success) { // An impossible location. error_location = -1; } for (p = buffer2, i = 0; ; i++) { // If this is the error location, insert the error message. if (i == error_location) { *p++ = '!'; *p++ = '-'; *p++ = '-'; strcpy(p, error_msg); p += strlen(error_msg); *p++ = '-'; *p++ = '-'; *p++ = '!'; } // Test for ending the loop after testing to insert the error message, // because the error message may be after the last character. if (i >= length) { break; } switch (value[i]) { case '<': *p++ = '&'; *p++ = 'l'; *p++ = 't'; *p++ = ';'; break; case '>': *p++ = '&'; *p++ = 'g'; *p++ = 't'; *p++ = ';'; break; case '&': *p++ = '&'; *p++ = 'a'; *p++ = 'm'; *p++ = 'p'; *p++ = ';'; break; default: *p++ = value[i]; break; } } *p++ = '\0'; #endif #endif }
int pf_altqq(struct snmp_context __unused *ctx, struct snmp_value *val, u_int sub, u_int __unused vindex, enum snmp_op op) { asn_subid_t which = val->var.subs[sub - 1]; struct pfq_entry *e = NULL; if (!altq_enabled) return (SNMP_ERR_NOSUCHNAME); if ((time(NULL) - pfq_table_age) > PFQ_TABLE_MAXAGE) pfq_refresh(); switch (op) { case SNMP_OP_SET: return (SNMP_ERR_NOT_WRITEABLE); case SNMP_OP_GETNEXT: if ((e = NEXT_OBJECT_INT(&pfq_table, &val->var, sub)) == NULL) return (SNMP_ERR_NOSUCHNAME); val->var.len = sub + 1; val->var.subs[sub] = e->index; break; case SNMP_OP_GET: if (val->var.len - sub != 1) return (SNMP_ERR_NOSUCHNAME); if ((e = pfq_table_find(val->var.subs[sub])) == NULL) return (SNMP_ERR_NOSUCHNAME); break; case SNMP_OP_COMMIT: case SNMP_OP_ROLLBACK: default: abort(); } switch (which) { case LEAF_pfAltqQueueDescr: return (string_get(val, e->altq.qname, -1)); case LEAF_pfAltqQueueParent: return (string_get(val, e->altq.parent, -1)); case LEAF_pfAltqQueueScheduler: val->v.integer = e->altq.scheduler; break; case LEAF_pfAltqQueueBandwidth: val->v.uint32 = (e->altq.bandwidth > UINT_MAX) ? UINT_MAX : (u_int32_t)e->altq.bandwidth; break; case LEAF_pfAltqQueuePriority: val->v.integer = e->altq.priority; break; case LEAF_pfAltqQueueLimit: val->v.integer = e->altq.qlimit; break; default: return (SNMP_ERR_NOSUCHNAME); } return (SNMP_ERR_NOERROR); }
/* Walk all references for an ObjectIndex and construct the hprof CLASS dump. */ static void dump_class_and_supers(JNIEnv *env, ObjectIndex object_index, RefIndex list) { SiteIndex site_index; SerialNumber trace_serial_num; RefIndex index; ClassIndex super_cnum; ObjectIndex super_index; LoaderIndex loader_index; ObjectIndex signers_index; ObjectIndex domain_index; FieldInfo *fields; jvalue *fvalues; jint n_fields; jboolean skip_fields; jint n_fields_set; jlong size; ClassIndex cnum; char *sig; ObjectKind kind; TraceIndex trace_index; Stack *cpool_values; ConstantPoolValue *cpool; jint cpool_count; HPROF_ASSERT(object_index!=0); kind = object_get_kind(object_index); if ( kind != OBJECT_CLASS ) { return; } site_index = object_get_site(object_index); HPROF_ASSERT(site_index!=0); cnum = site_get_class_index(site_index); HPROF_ASSERT(cnum!=0); if ( class_get_status(cnum) & CLASS_DUMPED ) { return; } class_add_status(cnum, CLASS_DUMPED); size = (jlong)object_get_size(object_index); super_index = 0; super_cnum = class_get_super(cnum); if ( super_cnum != 0 ) { super_index = class_get_object_index(super_cnum); if ( super_index != 0 ) { dump_class_and_supers(env, super_index, object_get_references(super_index)); } } trace_index = site_get_trace_index(site_index); HPROF_ASSERT(trace_index!=0); trace_serial_num = trace_get_serial_number(trace_index); sig = string_get(class_get_signature(cnum)); loader_index = class_get_loader(cnum); signers_index = 0; domain_index = 0; /* Get field information */ n_fields = 0; skip_fields = JNI_FALSE; n_fields_set = 0; fields = NULL; fvalues = NULL; if ( class_get_all_fields(env, cnum, &n_fields, &fields) == 1 ) { /* Problems getting all the fields, can't trust field index values */ skip_fields = JNI_TRUE; /* Class with no references at all? (ok to be unprepared if list==0?) */ if ( list != 0 ) { /* It is assumed that the reason why we didn't get the fields * was because the class is not prepared. */ if ( gdata->debugflags & DEBUGFLAG_UNPREPARED_CLASSES ) { dump_ref_list(list); debug_message("Unprepared class with references: %s\n", sig); } HPROF_ERROR(JNI_FALSE, "Trouble with unprepared classes"); } /* Why would an unprepared class contain references? */ } if ( n_fields > 0 ) { fvalues = (jvalue*)HPROF_MALLOC(n_fields*(int)sizeof(jvalue)); (void)memset(fvalues, 0, n_fields*(int)sizeof(jvalue)); } /* We use a Stack just because it will automatically expand as needed */ cpool_values = stack_init(16, 16, sizeof(ConstantPoolValue)); cpool = NULL; cpool_count = 0; index = list; while ( index != 0 ) { RefInfo *info; jvalue ovalue; static jvalue empty_value; info = get_info(index); switch ( info->flavor ) { case INFO_OBJECT_REF_DATA: switch ( info->refKind ) { case JVMTI_HEAP_REFERENCE_FIELD: case JVMTI_HEAP_REFERENCE_ARRAY_ELEMENT: /* Should never be seen on a class dump */ HPROF_ASSERT(0); break; case JVMTI_HEAP_REFERENCE_STATIC_FIELD: if ( skip_fields == JNI_TRUE ) { break; } ovalue = empty_value; ovalue.i = info->object_index; fill_in_field_value(list, fields, fvalues, n_fields, info->index, ovalue, 0); n_fields_set++; HPROF_ASSERT(n_fields_set <= n_fields); break; case JVMTI_HEAP_REFERENCE_CONSTANT_POOL: { ConstantPoolValue cpv; ObjectIndex cp_object_index; SiteIndex cp_site_index; ClassIndex cp_cnum; cp_object_index = info->object_index; HPROF_ASSERT(cp_object_index!=0); cp_site_index = object_get_site(cp_object_index); HPROF_ASSERT(cp_site_index!=0); cp_cnum = site_get_class_index(cp_site_index); cpv.constant_pool_index = info->index; cpv.sig_index = class_get_signature(cp_cnum); cpv.value.i = cp_object_index; stack_push(cpool_values, (void*)&cpv); cpool_count++; break; } case JVMTI_HEAP_REFERENCE_SIGNERS: signers_index = info->object_index; break; case JVMTI_HEAP_REFERENCE_PROTECTION_DOMAIN: domain_index = info->object_index; break; case JVMTI_HEAP_REFERENCE_CLASS_LOADER: case JVMTI_HEAP_REFERENCE_INTERFACE: default: /* Ignore, not needed */ break; } break; case INFO_PRIM_FIELD_DATA: if ( skip_fields == JNI_TRUE ) { break; } HPROF_ASSERT(info->primType!=0); HPROF_ASSERT(info->length==-1); HPROF_ASSERT(info->refKind==JVMTI_HEAP_REFERENCE_STATIC_FIELD); ovalue = get_key_value(index); fill_in_field_value(list, fields, fvalues, n_fields, info->index, ovalue, info->primType); n_fields_set++; HPROF_ASSERT(n_fields_set <= n_fields); break; case INFO_PRIM_ARRAY_DATA: default: /* Should never see these */ HPROF_ASSERT(0); break; } index = info->next; } /* Get constant pool data if we have any */ HPROF_ASSERT(cpool_count==stack_depth(cpool_values)); if ( cpool_count > 0 ) { cpool = (ConstantPoolValue*)stack_element(cpool_values, 0); } io_heap_class_dump(cnum, sig, object_index, trace_serial_num, super_index, loader_object_index(env, loader_index), signers_index, domain_index, (jint)size, cpool_count, cpool, n_fields, fields, fvalues); stack_term(cpool_values); if ( fvalues != NULL ) { HPROF_FREE(fvalues); } }
bool crypto_aes_decrypt(struct string *ciphertext, struct string *aes_key, struct string *aes_iv, struct string *decrypted) { bool retval = false; EVP_CIPHER_CTX ctx; int decryptspace; int decryptdone; EVP_CIPHER_CTX_init(&ctx); if (!EVP_DecryptInit_ex(&ctx, EVP_aes_256_cbc(), NULL, (unsigned char *)string_get(aes_key), (unsigned char *)string_get(aes_iv))) { log_err("crypto_aes_decrypt: init failed\n"); ERR_print_errors_fp(stderr); goto bail_out; } EVP_CIPHER_CTX_set_padding(&ctx, 1); if (string_length(aes_key) != EVP_CIPHER_CTX_key_length(&ctx)) { log_err("crypto_aes_decrypt: invalid key size (%" PRIuPTR " vs expected %d)\n", string_length(aes_key), EVP_CIPHER_CTX_key_length(&ctx)); goto bail_out; } if (string_length(aes_iv) != EVP_CIPHER_CTX_iv_length(&ctx)) { log_err("crypto_aes_decrypt: invalid iv size (%" PRIuPTR " vs expected %d)\n", string_length(aes_iv), EVP_CIPHER_CTX_iv_length(&ctx)); goto bail_out; } decryptspace = string_length(ciphertext) + EVP_MAX_BLOCK_LENGTH; string_free(decrypted); /* free previous buffer */ string_init(decrypted, decryptspace, 1024); if (string_size(decrypted) < decryptspace) { log_err("crypto_aes_decrypt: decrypt buffer malloc error\n"); goto bail_out; } if (EVP_DecryptUpdate(&ctx, (unsigned char*)string_get(decrypted), &decryptdone, (unsigned char*)string_get(ciphertext), string_length(ciphertext))) { /* TODO: need cleaner way: */ decrypted->_u._s.length = decryptdone; } else { log_err("crypto_aes_decrypt: decrypt failed\n"); ERR_print_errors_fp(stderr); goto bail_out; } if (EVP_DecryptFinal_ex(&ctx, (unsigned char*)string_get(decrypted)+string_length(decrypted), &decryptdone)) { /* TODO: need cleaner way: */ decrypted->_u._s.length += decryptdone; } else { log_err("crypto_aes_decrypt: decrypt final failed\n"); ERR_print_errors_fp(stderr); goto bail_out; } retval = true; bail_out: EVP_CIPHER_CTX_cleanup(&ctx); return retval; }
void String__split(caStack* stack) { string_split(circa_input(stack, 0), string_get(circa_input(stack, 1), 0), circa_output(stack, 0)); }
void sysproc_init() { SYSPROC * proc = sysprocs ; void * library = NULL ; const char * filename ; unsigned int n ; DLVARFIXUP * globals_fixup = NULL ; DLVARFIXUP * locals_fixup = NULL ; DLSYSFUNCS * functions_exports = NULL ; FN_HOOK module_initialize ; FN_HOOK module_finalize ; INSTANCE_HOOK instance_create_hook ; INSTANCE_HOOK instance_destroy_hook ; INSTANCE_HOOK instance_pre_execute_hook ; INSTANCE_HOOK instance_pos_execute_hook ; INSTANCE_HOOK process_exec_hook ; HOOK * handler_hooks = NULL ; int maxcode = 0 ; char soname[ __MAX_PATH ], fullsoname[ __MAX_PATH ], **spath ; #if defined( WIN32 ) #define DLLEXT ".dll" #elif defined(TARGET_MAC) #define DLLEXT ".dylib" #else #define DLLEXT ".so" #endif for ( n = 0; n < dcb.data.NImports; n++ ) { filename = string_get( dcb.imports[n] ) ; snprintf( soname, __MAX_PATH, "%s" DLLEXT, filename ); filename = soname ; /* Load library */ if ( debug ) printf ("Loading... %s\n", filename ); fullsoname[0] = '\0'; library = NULL; spath = dlsearchpath; while( !library && spath && *spath ) { sprintf( fullsoname, "%s%s/%s", appexepath, *spath, filename ); library = dlibopen( fullsoname ) ; spath++; } if ( !library ) library = dlibopen( filename ) ; if ( !library ) { printf( dliberror() ) ; exit( 0 ); } globals_fixup = ( DLVARFIXUP * ) _dlibaddr( library, "globals_fixup" ) ; locals_fixup = ( DLVARFIXUP * ) _dlibaddr( library, "locals_fixup" ) ; functions_exports = ( DLSYSFUNCS * ) _dlibaddr( library, "functions_exports" ) ; module_initialize = ( FN_HOOK ) _dlibaddr( library, "module_initialize" ) ; module_finalize = ( FN_HOOK ) _dlibaddr( library, "module_finalize" ) ; instance_create_hook = ( INSTANCE_HOOK ) _dlibaddr( library, "instance_create_hook" ) ; instance_destroy_hook = ( INSTANCE_HOOK ) _dlibaddr( library, "instance_destroy_hook" ) ; instance_pre_execute_hook = ( INSTANCE_HOOK ) _dlibaddr( library, "instance_pre_execute_hook" ) ; instance_pos_execute_hook = ( INSTANCE_HOOK ) _dlibaddr( library, "instance_pos_execute_hook" ) ; process_exec_hook = ( INSTANCE_HOOK ) _dlibaddr( library, "process_exec_hook" ) ; handler_hooks = ( HOOK * ) _dlibaddr( library, "handler_hooks" ) ; /* Fixups */ if ( globals_fixup ) { while ( globals_fixup->var ) { get_var_info( globals_fixup, dcb.glovar, dcb.data.NGloVars, globaldata ); globals_fixup++; } } if ( locals_fixup ) { while ( locals_fixup->var ) { get_var_info( locals_fixup, dcb.locvar, dcb.data.NLocVars, NULL ); locals_fixup++; } } sysproc_add_tab( functions_exports ) ; if ( module_initialize ) hook_add( module_initialize, module_initialize_list, module_initialize_allocated, module_initialize_count ) ; if ( module_finalize ) hook_add( module_finalize, module_finalize_list, module_finalize_allocated, module_finalize_count ) ; if ( instance_create_hook ) hook_add( instance_create_hook, instance_create_hook_list, instance_create_hook_allocated, instance_create_hook_count ) ; if ( instance_destroy_hook ) hook_add( instance_destroy_hook, instance_destroy_hook_list, instance_destroy_hook_allocated, instance_destroy_hook_count ) ; if ( instance_pre_execute_hook ) hook_add( instance_pre_execute_hook, instance_pre_execute_hook_list, instance_pre_execute_hook_allocated, instance_pre_execute_hook_count ) ; if ( instance_pos_execute_hook ) hook_add( instance_pos_execute_hook, instance_pos_execute_hook_list, instance_pos_execute_hook_allocated, instance_pos_execute_hook_count ) ; if ( process_exec_hook ) hook_add( process_exec_hook, process_exec_hook_list, process_exec_hook_allocated, process_exec_hook_count ) ; while ( handler_hooks && handler_hooks->hook ) { hook_add( *handler_hooks, handler_hook_list, handler_hook_allocated, handler_hook_count ) ; handler_hooks++; } } if ( debug ) printf ("\n"); /* System Procs FixUp */ sysprocs_fixup(); proc = sysprocs ; while ( proc->func ) { if ( maxcode < proc->code ) maxcode = proc->code ; proc++ ; } sysproc_tab = calloc( maxcode + 1 , sizeof( SYSPROC * ) ); proc = sysprocs ; while ( proc->func ) { if ( proc->code > -1 ) sysproc_tab[proc->code] = proc ; proc++ ; } /* Sort handler_hooks */ if ( handler_hook_list ) qsort( handler_hook_list, handler_hook_count, sizeof( handler_hook_list[0] ), ( int ( * )( const void *, const void * ) ) compare_priority ) ; /* Initialize all modules */ if ( module_initialize_count ) for ( n = 0; n < module_initialize_count; n++ ) module_initialize_list[n](); }
/** * Fetch a URL * @param url URL to fetch * @param buffer buffer to fetch data into * @param ifmodifiedsince * @param useragent * @param servererror * @param errormessage * @return zero on success, else errval (see HTTP_*-consts) */ int http_get(struct string* url, struct string* buffer, time_t ifmodifiedsince, struct string* useragent, int* servererror, struct string* /* unused - TBI */ errormessage) { struct string hostname; struct string path; struct string request; int port; int sfd; int retval = HTTP_EOK; struct addrinfo hints, *res, *rp; struct string ims; char s_port[16]; struct timeval tv; tv.tv_sec = GENERIC_SOCKET_TIMEOUT; tv.tv_usec = 0; string_init(&hostname, 4096, 4096); string_init(&path, 4096, 4096); if ((retval = http_parseurl(url, &hostname, &port, &path))) { goto bail_out_free_hostname; } memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; hints.ai_flags = 0; hints.ai_protocol = 0; if (!string_ensurez(&hostname)) { retval = HTTP_ENOMEM; goto bail_out_free_hostname; } snprintf(s_port, 16, "%d", port); if (getaddrinfo(string_get(&hostname), s_port, &hints, &res)) { retval = HTTP_ENETERR; goto bail_out_free_hostname; } for (rp = res; rp != NULL; rp = rp->ai_next) { sfd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); if (sfd == -1) { continue; } (void)setsockopt(sfd, SOL_SOCKET, SO_SNDTIMEO, (char*) &tv, sizeof(tv)); (void)setsockopt(sfd, SOL_SOCKET, SO_RCVTIMEO, (char*) &tv, sizeof(tv)); if (connect(sfd, rp->ai_addr, rp->ai_addrlen) != -1) { break; } close(sfd); } freeaddrinfo (res); if (rp == NULL) { retval = HTTP_ENETERR; goto bail_out_free_hostname; } string_init(&request, 4096, 4096); string_concat_sprintf(&request, "GET %S HTTP/1.1\r\nHost: %S\r\nUser-Agent: %S\r\n", &path, &hostname, useragent); if (ifmodifiedsince) { string_init(&ims, 512, 512); if (epoch2http(&ims, ifmodifiedsince)) { string_free(&ims); retval = HTTP_ENOMEM; goto bail_out; } if (!string_concat_sprintf(&request, "If-Modified-Since: %S\r\n", &ims)) { string_free(&ims); retval = HTTP_ENOMEM; goto bail_out; } string_free(&ims); } if (!string_concat(&request, "Connection: close\r\n")) { retval=HTTP_ENOMEM; goto bail_out; }; if (!string_concat(&request, "\r\n")) { retval=HTTP_ENOMEM; goto bail_out; } if (sendall(sfd, request.s, request.length, 0)) { retval = HTTP_ENETERR; goto bail_out; } if ((retval = httprecv(sfd, buffer, servererror))) { goto bail_out; } bail_out: close (sfd); string_free(&request); bail_out_free_hostname: string_free(&hostname); string_free(&path); return retval; }
/* function: cat_alloc_string_array * * Concatenates n string arrays along the k:th dimension. * allocates space in dest array * k is one based */ void cat_alloc_string_array(int k, string_array_t* dest, int n, string_array_t* first,...) { va_list ap; int i, j, r, c; int n_sub = 1, n_super = 1; int new_k_dim_size = 0; string_array_t **elts = (string_array_t**)malloc(sizeof(string_array_t *) * n); assert(elts); /* collect all array ptrs to simplify traversal.*/ va_start(ap, first); elts[0] = first; for(i = 1; i < n; i++) { elts[i] = va_arg(ap,string_array_t*); } va_end(ap); /* check dim sizes of all inputs */ assert(elts[0]->ndims >= k); new_k_dim_size = elts[0]->dim_size[k-1]; for(i = 1; i < n; i++) { assert(elts[0]->ndims == elts[i]->ndims); for(j = 0; j < (k - 1); j++) { assert(elts[0]->dim_size[j] == elts[i]->dim_size[j]); } new_k_dim_size += elts[i]->dim_size[k-1]; for(j = k; j < elts[0]->ndims; j++) { assert(elts[0]->dim_size[j] == elts[i]->dim_size[j]); } } /* calculate size of sub and super structure in 1-dim data representation */ for(i = 0; i < (k - 1); i++) { n_super *= elts[0]->dim_size[i]; } for(i = k; i < elts[0]->ndims; i++) { n_sub *= elts[0]->dim_size[i]; } /* allocate dest structure */ dest->data = string_alloc( n_super * new_k_dim_size * n_sub); dest->ndims = elts[0]->ndims; dest->dim_size = size_alloc(dest->ndims); for(j = 0; j < dest->ndims; j++) { dest->dim_size[j] = elts[0]->dim_size[j]; } dest->dim_size[k-1] = new_k_dim_size; /* concatenation along k-th dimension */ j = 0; for(i = 0; i < n_super; i++) { for(c = 0; c < n; c++) { int n_sub_k = n_sub * elts[c]->dim_size[k-1]; for(r = 0; r < n_sub_k; r++) { string_set(dest, j, string_get(*elts[c], r + (i * n_sub_k))); j++; } } } free(elts); }
int pf_logif(struct snmp_context __unused *ctx, struct snmp_value *val, u_int sub, u_int __unused vindex, enum snmp_op op) { asn_subid_t which = val->var.subs[sub - 1]; unsigned char str[IFNAMSIZ]; if (op == SNMP_OP_SET) return (SNMP_ERR_NOT_WRITEABLE); if (op == SNMP_OP_GET) { if (pfs_refresh() == -1) return (SNMP_ERR_GENERR); switch (which) { case LEAF_pfLogInterfaceName: strlcpy(str, pfs.ifname, sizeof str); return (string_get(val, str, strlen(str))); case LEAF_pfLogInterfaceIp4BytesIn: val->v.counter64 = pfs.bcounters[IPV4][IN]; break; case LEAF_pfLogInterfaceIp4BytesOut: val->v.counter64 = pfs.bcounters[IPV4][OUT]; break; case LEAF_pfLogInterfaceIp4PktsInPass: val->v.counter64 = pfs.pcounters[IPV4][IN][PF_PASS]; break; case LEAF_pfLogInterfaceIp4PktsInDrop: val->v.counter64 = pfs.pcounters[IPV4][IN][PF_DROP]; break; case LEAF_pfLogInterfaceIp4PktsOutPass: val->v.counter64 = pfs.pcounters[IPV4][OUT][PF_PASS]; break; case LEAF_pfLogInterfaceIp4PktsOutDrop: val->v.counter64 = pfs.pcounters[IPV4][OUT][PF_DROP]; break; case LEAF_pfLogInterfaceIp6BytesIn: val->v.counter64 = pfs.bcounters[IPV6][IN]; break; case LEAF_pfLogInterfaceIp6BytesOut: val->v.counter64 = pfs.bcounters[IPV6][OUT]; break; case LEAF_pfLogInterfaceIp6PktsInPass: val->v.counter64 = pfs.pcounters[IPV6][IN][PF_PASS]; break; case LEAF_pfLogInterfaceIp6PktsInDrop: val->v.counter64 = pfs.pcounters[IPV6][IN][PF_DROP]; break; case LEAF_pfLogInterfaceIp6PktsOutPass: val->v.counter64 = pfs.pcounters[IPV6][OUT][PF_PASS]; break; case LEAF_pfLogInterfaceIp6PktsOutDrop: val->v.counter64 = pfs.pcounters[IPV6][OUT][PF_DROP]; break; default: return (SNMP_ERR_NOSUCHNAME); } return (SNMP_ERR_NOERROR); } abort(); }
static int modregex_regex_replace (INSTANCE * my, int * params) { const char * reg = string_get(params[0]); const char * rep = string_get(params[1]); const char * str = string_get(params[2]); unsigned reg_len = strlen(reg); unsigned str_len = strlen(str); unsigned rep_len = strlen(rep); char * replacement; unsigned replacement_len; int fixed_replacement = strchr(rep, '\\') ? 0:1; struct re_pattern_buffer pb; struct re_registers re; int start[16]; int end[16]; unsigned startpos = 0; unsigned nextpos; int regex_filled = 0; char * result = 0; unsigned result_allocated = 0; int result_string = 0; unsigned n; int * regex_reg; /* Alloc a buffer for the resulting string */ result = malloc(128); result_allocated = 128; *result = 0; /* Alloc the pattern resources */ memset (&pb, 0, sizeof(pb)); memset (&re, 0, sizeof(re)); pb.buffer = malloc(4096); pb.allocated = 4096; pb.used = 0; pb.fastmap = malloc(256); pb.translate = NULL; pb.fastmap_accurate = 0; pb.regs_allocated = 16; re.start = start; re.end = end; re_syntax_options = RE_SYNTAX_POSIX_MINIMAL_EXTENDED; /* Run the regex */ if (re_compile_pattern (reg, reg_len, &pb) == 0) { startpos = 0; while (startpos < str_len) { nextpos = re_search (&pb, str, str_len, startpos, str_len - startpos, &re); if ((int)nextpos < 0) break; /* Fill the REGEX_REG global variables */ if (regex_filled == 0) { regex_filled = 1; regex_reg = (int *)&GLODWORD( mod_regex, REGEX_REG); for (n = 0 ; n < 16 && n <= pb.re_nsub ; n++) { string_discard (regex_reg[n]); regex_reg[n] = string_newa (str + re.start[n], re.end[n] - re.start[n]); string_use (regex_reg[n]); } } /* Prepare the replacement string */ if (fixed_replacement == 0) { int total_length = rep_len; const char * bptr; char * ptr; /* Count the size */ ptr = strchr(rep, '\\'); while (ptr) { if (ptr[1] >= '0' && ptr[1] <= '9') total_length += re.end[ptr[1]-'0'] - re.start[ptr[1]-'0'] - 2; ptr = strchr(ptr+1, '\\'); } /* Fill the replacement string */ replacement = calloc (total_length+1, 1); bptr = rep; ptr = strchr(rep, '\\'); while (ptr) { if (ptr[1] >= '0' && ptr[1] <= '9') { strncpy (replacement+strlen(replacement), bptr, ptr-bptr); strncpy (replacement+strlen(replacement), str + re.start[ptr[1]-'0'], re.end[ptr[1]-'0'] - re.start[ptr[1]-'0']); bptr = ptr+2; } ptr = strchr (ptr+1, '\\'); } strcat (replacement, bptr); replacement_len = strlen(replacement); } else { replacement = (char *)rep; replacement_len = rep_len; } /* Fill the resulting string */ if (result_allocated < strlen(result)+(nextpos-startpos)+1+replacement_len) { result_allocated += ((nextpos-startpos+1+replacement_len) & ~127) + 128; result = realloc(result, result_allocated); } result[strlen(result)+(nextpos-startpos)] = 0; memcpy (result + strlen(result), str+startpos, nextpos-startpos); strcat (result, replacement); if (fixed_replacement == 0) free (replacement); /* Continue the search */ startpos = nextpos+re_match(&pb, str, str_len, nextpos, 0); if (startpos < nextpos) break; if (startpos == nextpos) startpos++; } } /* Copy remaining characters */ nextpos = str_len; if (result_allocated < strlen(result)+(nextpos-startpos)+1) { result_allocated += ((nextpos-startpos+1) & ~127) + 128; result = realloc(result, result_allocated); } result[strlen(result)+(nextpos-startpos)] = 0; memcpy (result + strlen(result), str+startpos, nextpos-startpos); /* Free resources */ free (pb.buffer); free (pb.fastmap); string_discard(params[0]); string_discard(params[1]); string_discard(params[2]); /* Return the new string */ result_string = string_new(result); string_use(result_string); free(result); return result_string; }
int pf_tbltable(struct snmp_context __unused *ctx, struct snmp_value *val, u_int sub, u_int __unused vindex, enum snmp_op op) { asn_subid_t which = val->var.subs[sub - 1]; struct pft_entry *e = NULL; if ((time(NULL) - pft_table_age) > PFT_TABLE_MAXAGE) pft_refresh(); switch (op) { case SNMP_OP_SET: return (SNMP_ERR_NOT_WRITEABLE); case SNMP_OP_GETNEXT: if ((e = NEXT_OBJECT_INT(&pft_table, &val->var, sub)) == NULL) return (SNMP_ERR_NOSUCHNAME); val->var.len = sub + 1; val->var.subs[sub] = e->index; break; case SNMP_OP_GET: if (val->var.len - sub != 1) return (SNMP_ERR_NOSUCHNAME); if ((e = pft_table_find(val->var.subs[sub])) == NULL) return (SNMP_ERR_NOSUCHNAME); break; case SNMP_OP_COMMIT: case SNMP_OP_ROLLBACK: default: abort(); } switch (which) { case LEAF_pfTablesTblDescr: return (string_get(val, e->pft.pfrts_name, -1)); case LEAF_pfTablesTblCount: val->v.integer = e->pft.pfrts_cnt; break; case LEAF_pfTablesTblTZero: val->v.uint32 = (time(NULL) - e->pft.pfrts_tzero) * 100; break; case LEAF_pfTablesTblRefsAnchor: val->v.integer = e->pft.pfrts_refcnt[PFR_REFCNT_ANCHOR]; break; case LEAF_pfTablesTblRefsRule: val->v.integer = e->pft.pfrts_refcnt[PFR_REFCNT_RULE]; break; case LEAF_pfTablesTblEvalMatch: val->v.counter64 = e->pft.pfrts_match; break; case LEAF_pfTablesTblEvalNoMatch: val->v.counter64 = e->pft.pfrts_nomatch; break; case LEAF_pfTablesTblBytesInPass: val->v.counter64 = e->pft.pfrts_bytes[PFR_DIR_IN][PFR_OP_PASS]; break; case LEAF_pfTablesTblBytesInBlock: val->v.counter64 = e->pft.pfrts_bytes[PFR_DIR_IN][PFR_OP_BLOCK]; break; case LEAF_pfTablesTblBytesInXPass: val->v.counter64 = e->pft.pfrts_bytes[PFR_DIR_IN][PFR_OP_XPASS]; break; case LEAF_pfTablesTblBytesOutPass: val->v.counter64 = e->pft.pfrts_bytes[PFR_DIR_OUT][PFR_OP_PASS]; break; case LEAF_pfTablesTblBytesOutBlock: val->v.counter64 = e->pft.pfrts_bytes[PFR_DIR_OUT][PFR_OP_BLOCK]; break; case LEAF_pfTablesTblBytesOutXPass: val->v.counter64 = e->pft.pfrts_bytes[PFR_DIR_OUT][PFR_OP_XPASS]; break; case LEAF_pfTablesTblPktsInPass: val->v.counter64 = e->pft.pfrts_packets[PFR_DIR_IN][PFR_OP_PASS]; break; case LEAF_pfTablesTblPktsInBlock: val->v.counter64 = e->pft.pfrts_packets[PFR_DIR_IN][PFR_OP_BLOCK]; break; case LEAF_pfTablesTblPktsInXPass: val->v.counter64 = e->pft.pfrts_packets[PFR_DIR_IN][PFR_OP_XPASS]; break; case LEAF_pfTablesTblPktsOutPass: val->v.counter64 = e->pft.pfrts_packets[PFR_DIR_OUT][PFR_OP_PASS]; break; case LEAF_pfTablesTblPktsOutBlock: val->v.counter64 = e->pft.pfrts_packets[PFR_DIR_OUT][PFR_OP_BLOCK]; break; case LEAF_pfTablesTblPktsOutXPass: val->v.counter64 = e->pft.pfrts_packets[PFR_DIR_OUT][PFR_OP_XPASS]; break; default: return (SNMP_ERR_NOSUCHNAME); } return (SNMP_ERR_NOERROR); }
/* Walk all references for an ObjectIndex and construct the hprof INST dump. */ static void dump_instance(JNIEnv *env, ObjectIndex object_index, RefIndex list) { SiteIndex site_index; SerialNumber trace_serial_num; RefIndex index; ObjectIndex class_index; jlong size; ClassIndex cnum; char *sig; jint num_elements; jvalue *values; FieldInfo *fields; jvalue *fvalues; jint n_fields; ObjectKind kind; TraceIndex trace_index; jboolean skip_fields; HPROF_ASSERT(object_index!=0); kind = object_get_kind(object_index); if ( kind == OBJECT_CLASS ) { return; } site_index = object_get_site(object_index); HPROF_ASSERT(site_index!=0); cnum = site_get_class_index(site_index); HPROF_ASSERT(cnum!=0); size = (jlong)object_get_size(object_index); trace_index = site_get_trace_index(site_index); HPROF_ASSERT(trace_index!=0); trace_serial_num = trace_get_serial_number(trace_index); sig = string_get(class_get_signature(cnum)); class_index = class_get_object_index(cnum); values = NULL; num_elements = 0; n_fields = 0; fields = NULL; fvalues = NULL; index = list; skip_fields = JNI_TRUE; if ( sig[0] != JVM_SIGNATURE_ARRAY ) { if ( class_get_all_fields(env, cnum, &n_fields, &fields) == 0 ) { if ( n_fields > 0 ) { skip_fields = JNI_FALSE; fvalues = (jvalue*)HPROF_MALLOC(n_fields*(int)sizeof(jvalue)); (void)memset(fvalues, 0, n_fields*(int)sizeof(jvalue)); } } } while ( index != 0 ) { ObjectIndex field_object_index; RefInfo *info; info = get_info(index); /* Process reference objects, many not used right now. */ switch ( info->kind ) { case JVMTI_REFERENCE_FIELD: /* If the class_tag is 0, it is possible for * info->element_index to be >= n_fields * and when this happens we just skip this field ref * for now. We probably have a java.lang.Object class * with n_fields==0, which is probably the wrong class. */ if (info->class_tag == (jlong)0 || skip_fields == JNI_TRUE ) { break; } HPROF_ASSERT(info->element_index < n_fields); if (info->element_index < n_fields) { /* Field index is referrer_index from referrer_tag */ field_object_index = tag_to_object_index(info->object_tag); fvalues[info->element_index].i = field_object_index; } break; case JVMTI_REFERENCE_ARRAY_ELEMENT: /* Array element index is referrer_index in referrer_tag */ if ( num_elements <= info->element_index ) { int nbytes; if ( values == NULL ) { num_elements = info->element_index + 1; nbytes = num_elements*(int)sizeof(jvalue); values = (jvalue*)HPROF_MALLOC(nbytes); (void)memset(values, 0, nbytes); } else { void *new_values; int new_size; int obytes; obytes = num_elements*(int)sizeof(jvalue); new_size = info->element_index + 1; nbytes = new_size*(int)sizeof(jvalue); new_values = (jvalue*)HPROF_MALLOC(nbytes); (void)memcpy(new_values, values, obytes); (void)memset(((char*)new_values)+obytes, 0, nbytes-obytes); HPROF_FREE(values); num_elements = new_size; values = new_values; } } field_object_index = tag_to_object_index(info->object_tag); HPROF_ASSERT(values[info->element_index].i==0); values[info->element_index].i = field_object_index; break; default: break; } index = info->next; } if ( sig[0] == JVM_SIGNATURE_ARRAY ) { /* FIXUP: Fill primitive arrays? If requested? */ switch ( sig[1] ) { case JVM_SIGNATURE_CLASS: case JVM_SIGNATURE_ENUM: case JVM_SIGNATURE_ARRAY: io_heap_object_array(object_index, trace_serial_num, (jint)size, num_elements, class_index, values, sig); break; case JVM_SIGNATURE_BYTE: case JVM_SIGNATURE_BOOLEAN: io_heap_prim_array(object_index, (jint)size, trace_serial_num, num_elements, sig, values); break; case JVM_SIGNATURE_CHAR: case JVM_SIGNATURE_SHORT: io_heap_prim_array(object_index, (jint)size, trace_serial_num, num_elements, sig, values); break; case JVM_SIGNATURE_INT: case JVM_SIGNATURE_FLOAT: io_heap_prim_array(object_index, (jint)size, trace_serial_num, num_elements, sig, values); break; case JVM_SIGNATURE_DOUBLE: case JVM_SIGNATURE_LONG: io_heap_prim_array(object_index, (jint)size, trace_serial_num, num_elements, sig, values); break; default: HPROF_ASSERT(0); break; } } else { /* FIXUP: Fill rest of primitive fields? If requested? */ io_heap_instance_dump(cnum, object_index, trace_serial_num, class_index, (jint)size, sig, fields, fvalues, n_fields); } if ( values != NULL ) { HPROF_FREE(values); } if ( fvalues != NULL ) { HPROF_FREE(fvalues); } }