/* Try to find a class. If 'module' is NULL, then search through both the current module AND the builtin module. In all other cases, search just the module given. */ lily_class *lily_find_class(lily_symtab *symtab, lily_module_entry *module, const char *name) { uint64_t shorthash = shorthash_for_name(name); lily_class *result; if (module == NULL) { if (name[1] != '\0') { result = find_class(symtab->builtin_module->class_chain, name, shorthash); if (result == NULL) result = find_class(symtab->active_module->class_chain, name, shorthash); } else { lily_type *generic_type = lookup_generic(symtab, name); if (generic_type) { /* It's rather silly to make a different class for each generic type. Instead, write out whatever generic type was found as the default type. The generic class is written to have no subtypes, so this is okay. ts and other modules always special case the generic class, and won't be bothered by this little trick. */ result = symtab->generic_class; result->type = generic_type; } else result = NULL; } } else result = find_class(module->class_chain, name, shorthash); return result; }
static int class_info_register(const char *class_name, HINSTANCE hInstance) { struct class_info *p = *find_class(class_name); if (NULL == p) { WNDCLASS wc; ZeroMemory(&wc,sizeof(wc)); wc.lpfnWndProc = BBP_WndProc; // our window procedure wc.hInstance = hInstance; // hInstance of .dll wc.lpszClassName = class_name; // our window class name wc.style = CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW;// | CS_DROPSHADOW; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.cbWndExtra = sizeof (void*); if (FALSE == RegisterClass(&wc)) { //dbg_printf("failed to register %s", wc.lpszClassName); return 0; } p = (struct class_info*)m_alloc(sizeof(struct class_info)); p->next = CI; CI = p; p->refc = 0; strcpy(p->name, class_name); p->hInstance = hInstance; //dbg_printf("registered class <%s> %x", wc.lpszClassName, wc.hInstance); } p->refc ++; return 1; }
gboolean gtk_css_node_declaration_has_class (const GtkCssNodeDeclaration *decl, GQuark class_quark) { guint pos; GQuark *classes = get_classes (decl); switch (decl->n_classes) { case 3: if (classes[2] == class_quark) return TRUE; case 2: if (classes[1] == class_quark) return TRUE; case 1: if (classes[0] == class_quark) return TRUE; case 0: return FALSE; default: return find_class (decl, class_quark, &pos); } }
/* * Insert a free block to suitable class, * notes: 1. it's independent at first, that is to say, we have already destroy_relationship(cur_blk) * 2. it'll be the first free block in its class */ static void insert(char *cur_blk, size_t asize) { // FIRST find the class to insert in int class_index = 0; class_index = find_class(asize); // see if there has already been any free block in this class // if there is, we need to modify the relationship of the old first free block char *old_first = REAL_ADDR((char *)GET(heap_listp + class_index * HSIZE)); int to_change_old_fisrt = 0; if (old_first != (char *)base_addr) { to_change_old_fisrt = 1; } // here we modify cur_blk's info PUT(HDRP(cur_blk), PACK(asize, 0)); PUT(FTRP(cur_blk), PACK(asize, 0)); PUT(heap_listp + class_index * HSIZE, (unsigned int)((unsigned long)cur_blk - base_addr)); PUT(PRED(cur_blk), 0); PUT(SUCC(cur_blk), 0); // here we modify the relationship of the old first free block if (to_change_old_fisrt == 1) { PUT(PRED(old_first), (unsigned int)((unsigned long)cur_blk - base_addr)); PUT(SUCC(cur_blk), (unsigned int)((unsigned long)old_first - base_addr)); } }
void push (umlclassnode *node, batch *b) { umlclasslist used_classes, tmpnode; module *m; declaration *d; namelist l_tmp; if (node == NULL || find_class (node) != NULL) { return; } l_tmp = NEW (namenode); l_tmp->name = strdup (node->key->name); l_tmp->next = tmp_classes; tmp_classes = l_tmp; used_classes = list_classes (node, b); /* Make sure all classes that this one depends on are already pushed. */ tmpnode = used_classes; while (tmpnode != NULL) { /* don't push this class !*/ if (! eq (node->key->name, tmpnode->key->name) && ! (is_present (tmp_classes, tmpnode->key->name) ^ b->mask)) { push (tmpnode, b); } tmpnode = tmpnode->next; } if (node->key->package != NULL) { umlpackagelist pkglist = make_package_list (node->key->package); m = find_or_add_module (&decls, pkglist); if (m->contents == NULL) { m->contents = NEW (declaration); d = m->contents; d->prev = NULL; } else { /* We can simply append because all classes that we depend on are already pushed. */ d = append_decl (m->contents); } } else { if (decls == NULL) { decls = NEW (declaration); d = decls; d->prev = NULL; } else { d = append_decl (decls); /* We can simply append because all classes that we depend on are already pushed. */ } } d->decl_kind = dk_class; d->next = NULL; d->u.this_class = NEW (umlclassnode); memcpy (d->u.this_class, node, sizeof(umlclassnode)); if (strncmp (node->key->stereotype, "CORBA", 5) == 0) use_corba = 1; }
PSERVICE_API create_api(PFOOBAR2000_API *p_api, GUID *serv_guid) { PSERVICE_API *tmp=0; // !!!Must be 0!!! SERVICE_CLASS_REF api_class = find_class(p_api, serv_guid); if(get_count(p_api, api_class)==1) if(create(p_api, &tmp, api_class, 0)) return *tmp; return 0; }
JNIEXPORT void JNICALL Java_go_Seq_initSeq(JNIEnv *env, jclass clazz) { memptr_id = find_field(env, "go/Seq", "memptr", "J"); receive_refnum_id = find_field(env, "go/Seq$Receive", "refnum", "I"); receive_handle_id = find_field(env, "go/Seq$Receive", "handle", "I"); receive_code_id = find_field(env, "go/Seq$Receive", "code", "I"); jclass bclazz = find_class(env, "[B"); jbytearray_clazz = (*env)->NewGlobalRef(env, bclazz); }
static void class_info_decref(const char *name) { struct class_info *p, **pp = find_class(name); if (NULL != (p = *pp) && --p->refc <= 0) { UnregisterClass(p->name, p->hInstance); //dbg_printf("unregistered class <%s> %x", p->name, p->hInstance); *pp = p->next; m_free(p); } }
jint JNI_OnLoad(JavaVM* vm, void* reserved) { JNIEnv* env; if ((*vm)->GetEnv(vm, (void**)&env, JNI_VERSION_1_6) != JNI_OK) { return -1; } // Load classes here, which uses the correct ClassLoader. current_ctx_clazz = find_class(env, "org/golang/app/GoNativeActivity"); current_ctx_clazz = (jclass)(*env)->NewGlobalRef(env, current_ctx_clazz); return JNI_VERSION_1_6; }
/*ARGSUSED*/ JNIEXPORT jobject JNICALL Java_com_sun_dhcpmgr_bridge_Bridge_getDataStore( JNIEnv *env, jobject obj, jstring jresource) { jclass ds_class; jmethodID ds_cons; jobject dsObject; jboolean avail; jint version; dsvc_datastore_t datastore; char *resource; /* Make sure we have the classes & methods we need */ ds_class = find_class(env, DS_CLASS); if (ds_class == NULL) { /* exception thrown */ return (NULL); } ds_cons = get_methodID(env, ds_class, DS_CONS); if (ds_cons == NULL) { /* exception thrown */ return (NULL); } /* Retrieve the resource argument */ if (!dd_jstring_to_UTF(env, jresource, &resource)) { /* exception thrown */ return (NULL); } datastore.d_conver = DSVC_CUR_CONVER; datastore.d_resource = resource; datastore.d_location = NULL; avail = JNI_FALSE; if (status_dd(&datastore) == DSVC_SUCCESS) { avail = JNI_TRUE; version = datastore.d_conver; } dsObject = (*env)->NewObject(env, ds_class, ds_cons, jresource, version, avail); free(resource); return (dsObject); }
gboolean gtk_css_node_declaration_remove_class (GtkCssNodeDeclaration **decl, GQuark class_quark) { guint pos; if (!find_class (*decl, class_quark, &pos)) return FALSE; gtk_css_node_declaration_make_writable_resize (decl, (char *) &get_classes (*decl)[pos] - (char *) *decl, 0, sizeof (GQuark)); (*decl)->n_classes--; return TRUE; }
// REVIEW static Layout * structure_class_layout() { // Value instance_slots = NIL; // instance_slots = make_cons(S_direct_methods, instance_slots); // instance_slots = make_cons(S_class_prototype, instance_slots); // instance_slots = make_cons(S_name, instance_slots); // instance_slots = make_cons(S_layout, instance_slots); // instance_slots = make_cons(S_precedence_list, instance_slots); // instance_slots = make_cons(S_direct_superclasses, instance_slots); // instance_slots = make_cons(S_direct_subclasses, instance_slots); // instance_slots = make_cons(S_direct_slots, instance_slots); // instance_slots = make_cons(S_slots, instance_slots); return new Layout(check_class(find_class(S_structure_class)), // CL_nreverse(instance_slots), structure_class_instance_slots(), NIL // no shared slots ); }
Value StandardObject::type_of() const { // "For objects of metaclass STRUCTURE-CLASS or STANDARD-CLASS, and for // conditions, TYPE-OF returns the proper name of the class returned by // CLASS-OF if it has a proper name, and otherwise returns the class itself." if (_layout) { LispClass * c = _layout->lisp_class(); if (c) { Value name = c->name(); if (name != NIL && find_class(name) == make_value(c)) return name; else return make_value(c); } } return S_standard_object; }
bool run_main(PFOOBAR2000_API *p_api, GUID *p_guid) { PMAINMENU_COMMANDS *api=0; int index=0, count, i; GUID m_guid; bool ret; SERVICE_CLASS_REF api_class = find_class(p_api, &mainmenu_commands); while(create(p_api, (PSERVICE_API **)&api, api_class, index)) { for(i=0, count = get_command_count(api); i<count; i++) if(IsEqualGUID(p_guid, get_command(api, &m_guid, i))) {execute(api, i, 0), ret=true; goto ex;} index++; } ret=false; ex: __asm mov ecx, api; (*api)->base.service_release(); return ret; }
/** Create a struct Motd and initialize it. * @param[in] hostmask Hostmask (or connection class name) to filter on. * @param[in] path Path to MOTD file. * @param[in] maxcount Maximum number of lines permitted for MOTD. */ static struct Motd * motd_create(const char *hostmask, const char *path, int maxcount, int type) { struct Motd* tmp; assert(0 != path); /* allocate memory and initialize the structure */ if (MotdList.freelist) { tmp = MotdList.freelist; MotdList.freelist = tmp->next; } else tmp = (struct Motd *)MyMalloc(sizeof(struct Motd)); tmp->next = 0; if (hostmask == NULL) tmp->type = MOTD_UNIVERSAL; else if (type == MOTD_COUNTRY) tmp->type = MOTD_COUNTRY; else if (type == MOTD_CONTINENT) tmp->type = MOTD_CONTINENT; else if (find_class(hostmask)) tmp->type = MOTD_CLASS; else if (ipmask_parse(hostmask, &tmp->address, &tmp->addrbits)) tmp->type = MOTD_IPMASK; else tmp->type = MOTD_HOSTMASK; if (hostmask != NULL) DupString(tmp->hostmask, hostmask); else tmp->hostmask = NULL; DupString(tmp->path, path); tmp->maxcount = maxcount; tmp->cache = 0; return tmp; }
// ### make-structure-class name include slots => class Value SYS_make_structure_class(Value name, Value slots, Value include) { if (!symbolp(name)) return signal_type_error(name, S_symbol); if (!listp(slots)) return signal_type_error(name, S_list); StructureClass * c = new StructureClass(name, slots); if (include != NIL) { Value included_class = find_class(include); if (included_class == NULL_VALUE) { String * message = new String(::prin1_to_string(include)); message->append(" does not name a class."); return signal_lisp_error(message); } c->set_cpl(make_cons(make_value(c), the_class(included_class)->cpl())); } else c->set_cpl(make_cons(make_value(c), the_class(C_structure_object)->cpl())); return add_class(name, make_value(c)); }
/* * Destroy cur_blk's relationship with -1.heap_listp -2.pred -3.succ * note: cur_blk is a free block */ static void destroy_relationship(char *cur_blk) { char *pred = (char *)(REAL_ADDR(GET(PRED(cur_blk)))); char *succ = (char *)(REAL_ADDR(GET(SUCC(cur_blk)))); // when cur_blk is the first free block if (pred == (char *)base_addr) { int cur_index = 0; size_t cur_size = GET_SIZE(HDRP(cur_blk)); cur_index = find_class(cur_size); PUT(heap_listp + cur_index * HSIZE, (unsigned int)((unsigned long)succ - base_addr)); if (succ != (char *)base_addr) { PUT(PRED(succ), 0); } PUT(PRED(cur_blk), 0); PUT(SUCC(cur_blk), 0); } // when cur_blk is not the first free block else { PUT(SUCC(pred), (unsigned int)(unsigned long)succ - base_addr); if (succ != (char *)base_addr) { PUT(PRED(succ), (unsigned int)(unsigned long)pred - base_addr); } PUT(PRED(cur_blk), 0); PUT(SUCC(cur_blk), 0); } }
struct ast* eval_class_native_method(struct method_call_node* m){ if (m != NULL) { // new if (!strcmp(m->method_name, NEW)) { //creo objeto struct class* class_ptr = find_class(string_value(m->left_ast)); struct sym* sym_list = copy_instance_variables_for_class(class_ptr); struct ast* new_object = new_object_node(class_ptr, sym_list); struct sym* s = find_method_for_class(string_value(m->left_ast), "initialize"); // initialize está definido if (s != NULL) { // llamo a initialize sobre el objeto eval_and_push_args_and_object_info(s->args, m->args, new_object); struct ast* eval = eval_ast(s->ast); //eval initialize update_instance(new_object); //Antes de hacer pop, salvo en la instancia los cambios en sus variables de instancia pop_scope(); // pop del scope pusheado }; return new_object; }; }; };
virtual Value class_of() const { return find_class(xcar(_types)); }
int main (int argc, char** argv) { JCF jcf[1]; int argi, opt; /* Unlock the stdio streams. */ unlock_std_streams (); gcc_init_libintl (); if (argc <= 1) { fprintf (stderr, _("jcf-dump: no classes specified\n")); usage (); } jcf_path_init (); /* We use getopt_long_only to allow single `-' long options. For some of our options this is more natural. */ while ((opt = getopt_long_only (argc, argv, "o:I:vc", options, NULL)) != -1) { switch (opt) { case 0: /* Already handled. */ break; case 'o': output_file = optarg; break; case 'I': jcf_path_include_arg (optarg); break; case 'v': verbose++; break; case 'c': flag_disassemble_methods = 1; break; case OPT_classpath: jcf_path_classpath_arg (optarg); break; case OPT_bootclasspath: jcf_path_bootclasspath_arg (optarg); break; case OPT_extdirs: jcf_path_extdirs_arg (optarg); break; case OPT_HELP: help (); break; case OPT_VERSION: version (); break; case OPT_JAVAP: flag_javap_compatible++; flag_print_constant_pool = 0; flag_print_attributes = 0; break; default: usage (); } } if (verbose && ! flag_javap_compatible) flag_print_constant_pool = 1; if (optind == argc) { fprintf (stderr, _("jcf-dump: no classes specified\n")); usage (); } jcf_path_seal (verbose); if (flag_print_main) { flag_print_fields = 0; flag_print_methods = 0; flag_print_constant_pool = 0; flag_print_attributes = 0; flag_print_class_info = 0; } if (output_file) { out = fopen (output_file, "w"); if (! out) { fprintf (stderr, _("Cannot open '%s' for output.\n"), output_file); return FATAL_EXIT_CODE; } } else out = stdout; if (optind >= argc) { fprintf (out, "Reading .class from <standard input>.\n"); open_class ("<stdio>", jcf, 0, NULL); process_class (jcf); } else { for (argi = optind; argi < argc; argi++) { char *arg = argv[argi]; const char *class_filename = find_class (arg, strlen (arg), jcf, 0); if (class_filename == NULL) class_filename = find_classfile (arg, jcf, NULL); if (class_filename == NULL) { perror ("Could not find class"); return FATAL_EXIT_CODE; } JCF_FILL (jcf, 4); if (GET_u4 (jcf->read_ptr) == ZIPMAGIC) { long compressed_size, member_size; int compression_method, filename_length, extra_length; int general_purpose_bits; const char *filename; int total_length; if (flag_print_class_info) fprintf (out, "Reading classes from archive %s.\n", class_filename); for (;;) { int skip = 0; jcf_filbuf_t save_filbuf = jcf->filbuf; long magic = JCF_readu4_le (jcf); if (magic == 0x02014b50 || magic == 0x06054b50) break; /* got to central directory */ if (magic != 0x04034b50) /* ZIPMAGIC (little-endian) */ { fprintf (stderr, _("bad format of .zip/.jar archive\n")); return FATAL_EXIT_CODE; } JCF_FILL (jcf, 26); JCF_SKIP (jcf, 2); general_purpose_bits = JCF_readu2_le (jcf); compression_method = JCF_readu2_le (jcf); JCF_SKIP (jcf, 8); compressed_size = JCF_readu4_le (jcf); member_size = JCF_readu4_le (jcf); filename_length = JCF_readu2_le (jcf); extra_length = JCF_readu2_le (jcf); total_length = filename_length + extra_length + compressed_size; if (jcf->read_end - jcf->read_ptr < total_length) jcf_trim_old_input (jcf); JCF_FILL (jcf, total_length); filename = (const char *) jcf->read_ptr; JCF_SKIP (jcf, filename_length); JCF_SKIP (jcf, extra_length); if (filename_length > 0 && filename[filename_length-1] == '/') { if (flag_print_class_info) fprintf (out, "[Skipping directory %.*s]\n", filename_length, filename); skip = 1; } else if (compression_method != 0) { if (flag_print_class_info) fprintf (out, "[Skipping compressed file %.*s]\n", filename_length, filename); skip = 1; } else if (member_size < 4 || GET_u4 (jcf->read_ptr) != 0xcafebabe) { if (flag_print_class_info) fprintf (out, "[Skipping non-.class member %.*s]\n", filename_length, filename); skip = 1; } else { if (flag_print_class_info) fprintf (out, "Reading class member: %.*s.\n", filename_length, filename); } if (skip) { JCF_SKIP (jcf, compressed_size); } else { unsigned char *save_end; jcf->filbuf = jcf_unexpected_eof; save_end = jcf->read_end; jcf->read_end = jcf->read_ptr + compressed_size; process_class (jcf); jcf->filbuf = save_filbuf; jcf->read_end = save_end; } } } else { if (flag_print_class_info) fprintf (out, "Reading .class from %s.\n", class_filename); process_class (jcf); } JCF_FINISH(jcf); } } return SUCCESS_EXIT_CODE; }
inline void jthrow(JNIEnv *env, char const *clsname, char const *what) {jthrow(find_class(env, clsname), what);}
inline jhclass find_class(const char *clsname) { return find_class(jnienv(), clsname); }
/*ARGSUSED*/ JNIEXPORT jobjectArray JNICALL Java_com_sun_dhcpmgr_bridge_Bridge_getIPOption( JNIEnv *env, jobject obj, jshort code, jstring jarg) { jclass ip_class; jmethodID ip_cons; jobjectArray jlist = NULL; jobject jaddr; jstring jstr; struct dhcp_option *opt; ushort_t scode = (ushort_t)code; int i; const char *arg; /* Get classes and methods we need */ ip_class = find_class(env, IP_CLASS); if (ip_class == NULL) { /* exception thrown */ return (NULL); } ip_cons = get_methodID(env, ip_class, IP_CONS); if (ip_cons == NULL) { /* exception thrown */ return (NULL); } /* Retrieve option to generate value for */ arg = (*env)->GetStringUTFChars(env, jarg, NULL); if (arg == NULL) { /* exception thrown */ return (NULL); } /* Go get the default value */ opt = dd_getopt(scode, arg, NULL); (*env)->ReleaseStringUTFChars(env, jarg, arg); if (opt == NULL) { throw_memory_exception(env); return (NULL); } if (opt->error_code != 0) { throw_bridge_exception(env, opt->u.msg); dd_freeopt(opt); return (NULL); } /* Construct the array */ jlist = (*env)->NewObjectArray(env, opt->u.ret.count, ip_class, NULL); if (jlist == NULL) { /* exception thrown */ dd_freeopt(opt); return (NULL); } /* For each address, create an object and add it to the array */ for (i = 0; i < opt->u.ret.count; ++i) { jstr = (*env)->NewStringUTF(env, inet_ntoa(*opt->u.ret.data.addrs[i])); if (jstr == NULL) { /* exception thrown */ break; } jaddr = (*env)->NewObject(env, ip_class, ip_cons, jstr); if (jaddr == NULL) { /* exception thrown */ break; } (*env)->SetObjectArrayElement(env, jlist, i, jaddr); if ((*env)->ExceptionOccurred(env) != NULL) { break; } } dd_freeopt(opt); return (jlist); }
void handle_native_exception(JNIEnv *env, std::exception &e) { const char *what = e.what(); jclass clazz = find_class(env, "com/asakusafw/m3bp/mirror/jni/NativeException"); env->ThrowNew(clazz, what ? what : "(unknown reason)"); }
static void load_roots (const char* filename) { FILE *file; char buf [2048]; char *p, *s; int line = 0; MonoImage *image = NULL; MonoClass *klass = NULL; MonoClassField *field; MonoMethodDesc *mdesc; MonoMethod *method; if (!(file = fopen (filename, "r"))) return; while (fgets (buf, sizeof (buf), file)) { /* FIXME: * decide on the format to use to express types, fields, methods, * maybe the same used on output from the tool, but with explicit * names and signatures instead of token indexes * add wildcard support */ ++line; s = buf; while (*s && g_ascii_isspace (*s)) ++s; switch (*s) { case 0: case '#': continue; /* comment */ case '[': p = strchr (s, ']'); if (!p) g_error ("invalid assembly format at line %d\n", line); *p = 0; p = s + 1; image = find_image (p); if (!image) g_error ("image not loaded: %s\n", p); klass = NULL; break; case 'T': if (s [1] != ':') g_error ("invalid type format at line %d\n", line); if (!image) break; klass = find_class (image, s + 2); break; case 'F': if (s [1] != ':') g_error ("invalid field format at line %d\n", line); if (!image || !klass) break; p = s + 2; if (*p == '*') { handle_type (klass, TYPE_FIELDS); break; } field = mono_class_get_field_from_name (klass, p); if (!field) g_warning ("no field '%s' at line %d\n", p, line); else add_field (field); break; case 'M': if (s [1] != ':') g_error ("invalid method format at line %d\n", line); if (!image || !klass) break; p = s + 2; if (*p == '*') { handle_type (klass, TYPE_METHODS); break; } mdesc = mono_method_desc_new (p, FALSE); if (!mdesc) { g_error ("invalid method desc at line %d\n", line); } method = mono_method_desc_search_in_class (mdesc, klass); if (!method) g_warning ("no method '%s' at line %d\n", p, line); else add_types_from_method (method); mono_method_desc_free (mdesc); break; default: g_error ("invalid format at line %d\n", line); } } fclose (file); }
/*ARGSUSED*/ JNIEXPORT jobject JNICALL Java_com_sun_dhcpmgr_bridge_Bridge_readDefaults( JNIEnv *env, jobject obj) { jclass cfg_class; jmethodID cfg_cons; jmethodID cfg_set; jobject cfgobj = NULL; dhcp_confopt_t *cfgs, *tcfgs; /* Make sure we have the classes & methods we need */ cfg_class = find_class(env, CFG_CLASS); if (cfg_class == NULL) { /* exception thrown */ return (NULL); } cfg_cons = get_methodID(env, cfg_class, CFG_CONS); if (cfg_cons == NULL) { /* exception thrown */ return (NULL); } cfg_set = get_methodID(env, cfg_class, CFG_SET); if (cfg_set == NULL) { /* exception thrown */ return (NULL); } /* Get the data */ if (read_dsvc_conf(&cfgs) != 0) { throw_bridge_exception(env, strerror(errno)); } else { /* Construct returned options object */ cfgobj = (*env)->NewObject(env, cfg_class, cfg_cons); if (cfgobj == NULL) { /* exception thrown */ free_dsvc_conf(cfgs); return (NULL); } /* Load the option settings into the options object */ tcfgs = cfgs; for (;;) { if (cfgs->co_type == DHCP_COMMENT) { (*env)->CallVoidMethod(env, cfgobj, cfg_set, (*env)->NewStringUTF(env, cfgs->co_key), (*env)->NewStringUTF(env, ""), JNI_TRUE); } else { if (cfgs->co_key == NULL) { break; } (*env)->CallVoidMethod(env, cfgobj, cfg_set, (*env)->NewStringUTF(env, cfgs->co_key), (*env)->NewStringUTF(env, cfgs->co_value), JNI_FALSE); } if ((*env)->ExceptionOccurred(env) != NULL) { free_dsvc_conf(tcfgs); return (NULL); } ++cfgs; } free_dsvc_conf(tcfgs); } return (cfgobj); }
/*ARGSUSED*/ JNIEXPORT void JNICALL Java_com_sun_dhcpmgr_bridge_Bridge_writeDefaults( JNIEnv *env, jobject obj, jobject jcfgs) { jclass cfg_class; jmethodID cfg_getall; jclass res_class; jmethodID res_getkey; jmethodID res_getval; jmethodID res_iscom; jobjectArray resArray; jsize reslen; jobject jobj, resobj; dhcp_confopt_t *cfgs; int i; jboolean comment; const char *tmpstr; /* Make sure we can get at the classes we need */ cfg_class = find_class(env, CFG_CLASS); if (cfg_class == NULL) { /* exception thrown */ return; } cfg_getall = get_methodID(env, cfg_class, CFG_GETALL); if (cfg_getall == NULL) { /* exception thrown */ return; } res_class = find_class(env, RES_CLASS); if (res_class == NULL) { /* exception thrown */ return; } res_getkey = get_methodID(env, res_class, RES_GETKEY); res_getval = get_methodID(env, res_class, RES_GETVAL); res_iscom = get_methodID(env, res_class, RES_ISCOM); if (res_getkey == NULL || res_getval == NULL || res_iscom == NULL) { /* exception thrown */ return; } /* Get the resource array from the config object */ resArray = (*env)->CallObjectMethod(env, jcfgs, cfg_getall); if ((*env)->ExceptionOccurred(env) != NULL) { return; } reslen = (*env)->GetArrayLength(env, resArray); /* Allocate array to convert into; extra zero'd item to signal end */ cfgs = calloc(reslen+1, sizeof (dhcp_confopt_t)); if (cfgs == NULL) { throw_memory_exception(env); return; } /* Now copy data into local array */ for (i = 0; i < reslen; ++i) { jobj = (*env)->GetObjectArrayElement(env, resArray, i); if (jobj == NULL) { /* exception thrown */ free_dsvc_conf(cfgs); return; } /* Set record type */ comment = (*env)->CallBooleanMethod(env, jobj, res_iscom); if ((*env)->ExceptionOccurred(env) != NULL) { return; } if (comment == JNI_TRUE) { cfgs[i].co_type = DHCP_COMMENT; } else { cfgs[i].co_type = DHCP_KEY; } /* * Get the key from the object, convert to a char *, * and then duplicate into the cfgs array so that * free_dsvc_conf can be used correctly. * Do the same thing for the value. */ resobj = (*env)->CallObjectMethod(env, jobj, res_getkey); tmpstr = (*env)->GetStringUTFChars(env, resobj, NULL); if (tmpstr == NULL) { /* exception thrown */ free_dsvc_conf(cfgs); throw_bridge_exception(env, gettext("Error converting key")); return; } cfgs[i].co_key = strdup(tmpstr); (*env)->ReleaseStringUTFChars(env, resobj, tmpstr); if (cfgs[i].co_key == NULL) { /* Out of memory, fail */ free_dsvc_conf(cfgs); throw_memory_exception(env); return; } resobj = (*env)->CallObjectMethod(env, jobj, res_getval); tmpstr = (*env)->GetStringUTFChars(env, resobj, NULL); if (tmpstr == NULL) { free_dsvc_conf(cfgs); throw_bridge_exception(env, gettext("Error converting value")); return; } cfgs[i].co_value = strdup(tmpstr); (*env)->ReleaseStringUTFChars(env, resobj, tmpstr); if (cfgs[i].co_value == NULL) { /* Out of memory, fail */ free_dsvc_conf(cfgs); throw_memory_exception(env); return; } } /* Now write the new data */ if (write_dsvc_conf(cfgs, CONFOPT_MODE) != 0) { throw_bridge_exception(env, strerror(errno)); } free_dsvc_conf(cfgs); }
/*ARGSUSED*/ JNIEXPORT jobjectArray JNICALL Java_com_sun_dhcpmgr_bridge_Bridge_getDataStores( JNIEnv *env, jobject obj) { jclass ds_class; jmethodID ds_cons; jobjectArray jlist = NULL; jobject jobj; jstring jstr; jboolean avail; jint version; char **list; dsvc_datastore_t datastore; int i, len; /* Make sure we have the classes & methods we need */ ds_class = find_class(env, DS_CLASS); if (ds_class == NULL) { /* exception thrown */ return (NULL); } ds_cons = get_methodID(env, ds_class, DS_CONS); if (ds_cons == NULL) { /* exception thrown */ return (NULL); } /* Get the list */ list = dd_data_stores(env); if ((*env)->ExceptionOccurred(env) != NULL) { return (NULL); } /* Compute the length of the array, store in len */ ARRAY_LENGTH(list, len); /* Construct the array */ jlist = (*env)->NewObjectArray(env, len, ds_class, NULL); if (jlist == NULL) { /* exception thrown */ dd_free_data_stores(list); return (NULL); } /* For each store, create an object and add it to the array */ for (i = 0; i < len; ++i) { jstr = (*env)->NewStringUTF(env, list[i]); if (jstr == NULL) { /* exception thrown */ break; } datastore.d_conver = DSVC_CUR_CONVER; datastore.d_resource = list[i]; datastore.d_location = NULL; avail = JNI_FALSE; if (status_dd(&datastore) == DSVC_SUCCESS) { avail = JNI_TRUE; version = datastore.d_conver; } jobj = (*env)->NewObject(env, ds_class, ds_cons, jstr, version, avail); if (jobj == NULL) { /* exception thrown */ break; } (*env)->SetObjectArrayElement(env, jlist, i, jobj); if ((*env)->ExceptionOccurred(env) != NULL) { break; } } dd_free_data_stores(list); return (jlist); }
/*ARGSUSED*/ JNIEXPORT jobjectArray JNICALL Java_com_sun_dhcpmgr_bridge_Bridge_getInterfaces( JNIEnv *env, jobject obj) { jclass ipif_class; jmethodID ipif_cons; jobjectArray jlist = NULL; jobject jobj; jsize len; struct ip_interface **list; int i; /* Locate the class and constructor we need */ ipif_class = find_class(env, IPIF_CLASS); if (ipif_class == NULL) { /* exception thrown */ return (NULL); } ipif_cons = get_methodID(env, ipif_class, IPIF_CONS); if (ipif_cons == NULL) { return (NULL); } /* Retrieve interface list */ list = dd_get_interfaces(); if (list == NULL) { throw_bridge_exception(env, gettext("Error in dd_get_interfaces")); return (NULL); } /* Compute length of list */ ARRAY_LENGTH(list, len); /* Construct the array */ jlist = (*env)->NewObjectArray(env, len, ipif_class, NULL); if (jlist == NULL) { /* exception thrown */ for (i = 0; i < len; i++) { free(list[i]); } free(list); return (NULL); } /* For each interface, construct an object and add to the array */ for (i = 0; i < len; ++i) { jobj = (*env)->NewObject(env, ipif_class, ipif_cons, (*env)->NewStringUTF(env, list[i]->name), (*env)->NewStringUTF(env, inet_ntoa(list[i]->addr)), (*env)->NewStringUTF(env, inet_ntoa(list[i]->mask))); if (jobj == NULL) { /* exception thrown */ break; } (*env)->SetObjectArrayElement(env, jlist, i, jobj); if ((*env)->ExceptionOccurred(env) != NULL) { break; } } for (i = 0; i < len; i++) { free(list[i]); } free(list); return (jlist); }