Example #1
0
int main()
{
    printf( "EXCOK: start\n" );
    set_terminate( &no_handler );
    test_basics();
    test_scalars();
    init_class();
    test_class();
    test_cl_ptrs();
    test_passthru();
    test_rethrow();
    try {
        ++throws;
        set_unexpected( &unexp );
        test_unexpected();
    } catch( long l ) {
        ++catches;
        if( l != 675L ) {
            printf( "unexpected failure %l\n", l );
        }
    }
    if( throws != catches ) {
        printf( "catches != throws\n" );
    }
    set_terminate( &my_term );
    test_term();

    printf( "terminate did not abort\n" );
    return( 0 );
}
Example #2
0
 frame::frame():_hwnd(0),_next(0),_prev(0)
 {
   sync::critical_section _(_guard);
   init_class();
   if(_first) 
     _first->_prev = this;
   _next = _first;
   _first = this;
   add_ref();
 }
Example #3
0
static void set_up(void) {
  if (p == NULL) {
    p = permanent_pool = make_sub_pool(NULL);
  }

  main_server = pcalloc(p, sizeof(server_rec));
  main_server->pool = p;

  init_class();
  init_netaddr();
}
Example #4
0
tl_procession *init_procession(void){

  tl_procession *x = malloc(sizeof(tl_procession));
  x->class_head = init_class();
  x->ctl_head = init_ctl(TL_HEAD_CTL);
  x->lvl_stck = init_lvl_stck();
  x->ab_in = init_audio_buff(TL_MAXCHANNS);
  x->ab_out = init_audio_buff(TL_MAXCHANNS);
  return x;

}
Example #5
0
/*! \fn ctor
 *  \param val - the value state
 *  \param num_type - the type of the Number created
 *  \return a pointer to a new Number object
 *  \brief an helping function for the two constructors
 *
 *  This is actually a constructor by itself.
 *  By dividing the construction into two functions, I hid the
 *  	implementation from the user
 */
Number* ctor(state val, int num_type)
{
	Number* to_return = init_class(NUMBER_RTTI,number_method,&Object,NUMBER_NUM_OF_STATE);

	add_state(to_return,val,NUMBER_VALUE);

	state type;
	type.value.uint = num_type;

	add_state(to_return,type,NUMBER_TYPE);

	return to_return;
}
Example #6
0
JsExecutionContext::JsExecutionContext(JsParser *jsParser)
{
  parser = jsParser;
  /* Create a new runtime environment. */
  rt = JS_NewRuntime(8L * 1024L * 1024L);
  if (!rt) {
    error("JsParser :: error creating runtime");
    return; /* XXX should return int or ptr! */
  }

  /* Create a new context. */
  cx = JS_NewContext(rt, STACK_CHUNK_SIZE);
  /* if global_context does not have a value, end the program here */
  if (cx == NULL) {
    error("JsParser :: error creating context");
    return;
  }

  JS_BeginRequest(cx);
  // Store a reference to ourselves in the context ...
  JS_SetContextPrivate(cx, parser);

  /* Set a more strict error checking */
  JS_SetOptions(cx, JSOPTION_VAROBJFIX); // | JSOPTION_STRICT);

  /* Set the branch callback */
#if defined JSOPTION_NATIVE_BRANCH_CALLBACK
  JS_SetBranchCallback(cx, js_static_branch_callback);
#else
  JS_SetOperationCallback(cx, js_static_branch_callback);
#endif

  /* Set the error reporter */
  JS_SetErrorReporter(cx, js_error_reporter);

  /* Create the global object here */
  //  JS_SetGlobalObject(global_context, global_object);
  //  this is done in init_class / JS_InitStandardClasses.
  obj = JS_NewObject(cx, &global_class, NULL, NULL);
  init_class();
  JS_EndRequest(cx);
  // deassociate this context from the creating thread
  // so that it can be used in other threads
  // https://developer.mozilla.org/en/SpiderMonkey/JSAPI_Reference/JS_NewContext
  JS_ClearContextThread(cx);
  /** register SIGINT signal */
  //   signal(SIGINT, js_sigint_handler);
}
Example #7
0
END_TEST

START_TEST (expr_eval_class_or_test) {
  pr_netacl_t *acl;
  char *names1[3] = { "foo", "test", NULL }, *names2[2] = { "test", NULL },
    *names3[2] = { "!baz", NULL }, *names4[2] = { "foo", NULL };
  int res;

  res = pr_expr_eval_class_or(NULL);
  fail_unless(res == -1, "Failed to handle null argument");
  fail_unless(errno == EINVAL, "Failed to set errno to EINVAL");

  session.conn_class = NULL;

  res = pr_expr_eval_class_or(names1);
  fail_unless(res == FALSE, "Expected FALSE, got TRUE");

  init_netaddr();
  init_class();

  res = pr_class_open(p, "test");
  fail_unless(res == 0, "Failed to open class: %s", strerror(errno));

  acl = pr_netacl_create(p, "all");
  fail_unless(acl != NULL, "Failed to create ACL: %s", strerror(errno));

  res = pr_class_add_acl(acl);
  fail_unless(res == 0, "Failed to add ACL to class: %s", strerror(errno));

  res = pr_class_close();
  fail_unless(res == 0, "Failed to close class: %s", strerror(errno));

  session.conn_class = pr_class_find("test");
  fail_unless(session.conn_class != NULL, "Failed to find 'test' class: %s",
    strerror(errno));

  res = pr_expr_eval_class_or(names1);
  fail_unless(res == TRUE, "Expected TRUE, got FALSE");

  res = pr_expr_eval_class_or(names2);
  fail_unless(res == TRUE, "Expected TRUE, got FALSE");

  res = pr_expr_eval_class_or(names3);
  fail_unless(res == TRUE, "Expected TRUE, got FALSE");

  res = pr_expr_eval_class_or(names4);
  fail_unless(res == FALSE, "Expected FALSE, got TRUE");
}
Example #8
0
window::window()
{
  init_class();
  _hwnd = CreateWindowEx(
      0,
      WINDOW_CLASS_NAME, 
      L"demo", 
      WS_POPUP, 100, 100, 500, 500, NULL, NULL, ghInstance, this);
  if (!_hwnd)
     return;

  init();

  ShowWindow(_hwnd, SW_SHOW);
  UpdateWindow(_hwnd);
}
Example #9
0
int32_t LevelChecker::get_method_level(DexMethod* method) {
  always_assert_log(s_has_been_init, "must call init first");
  int32_t method_level = method->rstate.get_api_level();
  if (method_level == -1) {
    // must have been created later on by Redex
    DexClass* cls = type_class(method->get_class());
    int32_t class_level = cls->rstate.get_api_level();
    if (class_level == -1) {
      // must have been created later on by Redex
      init_class(cls);
    }

    init_method(method);
    method_level = method->rstate.get_api_level();
  }

  return method_level;
}
Example #10
0
objrtn	PointerArray_initialize(void)
{
	static  CRITICALSECTION  cs;
	static  int volatile once = 0;

	ENTERCRITICALSECTION(_CI_CS_);
	if (!once) {
		INITIALIZECRITICALSECTION(cs);
		once = 1;
	}
	LEAVECRITICALSECTION(_CI_CS_);

	ENTERCRITICALSECTION(cs);

	if (PointerArray_c) {
		LEAVECRITICALSECTION(cs);
		return PointerArray_c;
	}
	INHIBIT_THREADER;
	Array_initialize();
	if (PointerArray_c)  {
		ENABLE_THREADER;
		LEAVECRITICALSECTION(cs);
		return PointerArray_c;
	}
	PointerArray_c = gNewClass(Class, "PointerArray", 0, 0, Array, END);
	cvMethodFor(PointerArray, vNew, PointerArray_cvm_vNew, PointerArray_cfm_vNew);
	ivMethodFor(PointerArray, vChangeValue, PointerArray_ivm_vChangeValue, PointerArray_ifm_vChangeValue);
	ivMethodFor(PointerArray, vPointerValue, PointerArray_ivm_vPointerValue, PointerArray_ifm_vPointerValue);

	init_class();

	ENABLE_THREADER;

	LEAVECRITICALSECTION(cs);

	return PointerArray_c;
}
Example #11
0
int
main (int argc, char *argv[])
{
  /* Check to see if the user is running
   * us as root, which is a nono
   */
  if (geteuid () == 0)
    {
      fprintf (stderr, "Don't run ircd as root!!!\n");
      return (-1);
    }

  /* save server boot time right away, so getrusage works correctly */
  set_time ();

  /* Setup corefile size immediately after boot -kre */
  setup_corefile ();

  /* set initialVMTop before we allocate any memory */
  initialVMTop = get_vm_top ();

  ServerRunning = 0;

  /* It ain't random, but it ought to be a little harder to guess */
  srand (SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid () << 20)));
  memset (&me, 0, sizeof (me));
  memset (&meLocalUser, 0, sizeof (meLocalUser));
  me.localClient = &meLocalUser;
  dlinkAdd (&me, &me.node, &global_client_list);	/* Pointer to beginning
							   of Client list */

  memset (&ServerInfo, 0, sizeof (ServerInfo));

  /* Initialise the channel capability usage counts... */
  init_chcap_usage_counts ();

  ConfigFileEntry.dpath = DPATH;
  ConfigFileEntry.configfile = CPATH;	/* Server configuration file */
  ConfigFileEntry.klinefile = KPATH;	/* Server kline file         */
  ConfigFileEntry.xlinefile = XPATH;	/* Server xline file         */
  ConfigFileEntry.dlinefile = DLPATH;	/* dline file                */
  ConfigFileEntry.cresvfile = CRESVPATH;	/* channel resv file      */
  ConfigFileEntry.nresvfile = NRESVPATH;	/* nick resv file         */
  myargv = argv;
  umask (077);			/* better safe than sorry --SRB */

  parseargs (&argc, &argv, myopts);

  build_version ();

  if (printVersion)
    {
      printf ("ircd: version %s\n", ircd_version);
      exit (EXIT_SUCCESS);
    }

  if (chdir (ConfigFileEntry.dpath))
    {
      perror ("chdir");
      exit (EXIT_FAILURE);
    }

  if (!server_state.foreground)
    make_daemon ();
  else
    print_startup (getpid ());

#ifdef HAVE_LIBCRYPTO
  dh_init();
  fprintf(stderr, "SSL: Initialize\n");

  SSL_load_error_strings();
  SSLeay_add_ssl_algorithms();
  ServerInfo.ctx = SSL_CTX_new(SSLv23_server_method());

  if (!ServerInfo.ctx) {
       ERR_print_errors_fp(stderr);
       return 0;
  }

  fprintf(stderr, "SSL: Client based SSL connections are enabled.\n");
#endif

  setup_signals ();
  /* We need this to initialise the fd array before anything else */
  fdlist_init ();

  if (!server_state.foreground)
    close_all_connections ();	/* this needs to be before init_netio()! */
  else
    check_can_use_v6 ();	/* Done in close_all_connections normally */

  init_log (logFileName);
  init_netio ();		/* This needs to be setup early ! -- adrian */
  /* Check if there is pidfile and daemon already running */
  check_pidfile (pidFileName);
  /* Init the event subsystem */
  eventInit ();
  init_sys ();

#ifndef NOBALLOC
  initBlockHeap ();
#endif
  init_dlink_nodes ();
  init_slink_nodes ();
  initialize_message_files ();
  dbuf_init ();
  init_hash ();
  init_ip_hash_table ();	/* client host ip hash table */
  init_host_hash ();		/* Host-hashtable. */
  clear_hash_parse ();
  init_client ();
  init_user ();
  init_channels ();
  init_class ();
  init_whowas ();
  init_stats ();
  init_hooks ();
  read_conf_files (1);		/* cold start init conf files */
  initServerMask ();
  init_uid ();
  init_auth ();			/* Initialise the auth code */
  init_resolver ();		/* Needs to be setup before the io loop */
  init_reject ();               /* Set up the reject code. */
  init_umodes ();               /* Set up the usermode system. */

  initialize_foundation_signals(); /* register things that modules need */

#ifdef HAVE_LIBCRYPTO
  bio_spare_fd = save_spare_fd ("SSL private key validation");
#endif /* HAVE_LIBCRYPTO */

  initialize_server_capabs ();	/* Set up default_server_capabs */
  initialize_global_set_options ();

  if (ServerInfo.name == NULL)
    {
      fprintf (stderr,
	       "ERROR: No server name specified in serverinfo block.\n");
      ilog (L_CRIT, "No server name specified in serverinfo block.");
      exit (EXIT_FAILURE);
    }
  strlcpy (me.name, ServerInfo.name, sizeof (me.name));

  /* serverinfo{} description must exist.  If not, error out. */
  if (ServerInfo.description == NULL)
    {
      fprintf (stderr,
	       "ERROR: No server description specified in serverinfo block.\n");
      ilog (L_CRIT,
	    "ERROR: No server description specified in serverinfo block.");
      exit (EXIT_FAILURE);
    }
  strlcpy (me.info, ServerInfo.description, sizeof (me.info));

  me.from = &me;
  me.servptr = &me;

  SetMe (&me);
  make_server (&me);

  strlcpy (me.serv->up, me.name, sizeof (me.serv->up));
  me.lasttime = me.since = me.firsttime = CurrentTime;
  hash_add_client (&me);

  /* add ourselves to global_serv_list */
  dlinkAdd (&me, make_dlink_node (), &global_serv_list);

  check_class ();

#ifndef STATIC_MODULES
  if (chdir (MODPATH))
    {
      ilog (L_CRIT, "Could not load core modules. Terminating!");
      exit (EXIT_FAILURE);
    }
  mod_set_base ();
  load_all_modules (1);
  load_core_modules (1);
  /* Go back to DPATH after checking to see if we can chdir to MODPATH */
  chdir (ConfigFileEntry.dpath);
#else
  load_all_modules (1);
#endif

  write_pidfile (pidFileName);

  ilog (L_NOTICE, "Server Ready");

  eventAddIsh ("cleanup_tklines", cleanup_tklines, NULL,
	       CLEANUP_TKLINES_TIME);

  /* We want try_connections to be called as soon as possible now! -- adrian */
  /* No, 'cause after a restart it would cause all sorts of nick collides */
  eventAddIsh ("try_connections", try_connections, NULL,
	       STARTUP_CONNECTIONS_TIME);

  eventAddIsh ("collect_zipstats", collect_zipstats, NULL, ZIPSTATS_TIME);

  /* Setup the timeout check. I'll shift it later :)  -- adrian */
  eventAddIsh ("comm_checktimeouts", comm_checktimeouts, NULL, 1);

  if (splitmode)
    eventAddIsh ("check_splitmode", check_splitmode, NULL, 60);

  ServerRunning = 1;
  io_loop ();
  return (0);
}
Example #12
0
int main(int argc, char *argv[]) {
  pool *p;
  const char *remote_name;
  pr_netaddr_t *remote_addr;
  conn_t *client_conn, *ctrl_conn, *data_conn;
  unsigned int connect_timeout, remote_port;
  struct proxy_ftp_client *ftp;
  int res, timerno;
  char buf[1024];

  /* Seed the random number generator. */
  /* XXX Use random(3) in the future? */
  srand((unsigned int) (time(NULL) * getpid()));

  init_pools();
  init_privs();
  init_log();
  init_regexp();
  init_inet();
  init_netio();
  init_netaddr();
  init_fs();
  init_class();
  init_config();
  init_stash();

  pr_log_setdebuglevel(10);
  log_stderr(TRUE);
  pr_trace_use_stderr(TRUE);
  pr_trace_set_levels("DEFAULT", 1, 20);

  p = make_sub_pool(permanent_pool);
  pr_pool_tag(p, "FTP Client Pool");

  remote_name = "ftp.proftpd.org";

  remote_addr = pr_netaddr_get_addr(p, remote_name, NULL);
  if (remote_addr == NULL) {
    fprintf(stderr, "Failed to get addr for '%s': %s\n", remote_name,
      strerror(errno));
    destroy_pool(p);
    return 1;
  } 

  fprintf(stdout, "Resolved name '%s' to IP address '%s'\n", remote_name,
    pr_netaddr_get_ipstr(remote_addr));

  remote_port = 21;
  connect_timeout = 5;
  ftp = proxy_ftp_connect(p, remote_addr, remote_port, connect_timeout, NULL);
  if (ftp == NULL) {
    fprintf(stderr, "Error connecting to FTP server: %s\n", strerror(errno));
    destroy_pool(p);
    return 1;
  }

  fprintf(stdout, "Successfully connected to %s:%d from %s:%d\n", remote_name,
    remote_port, pr_netaddr_get_ipstr(client_conn->local_addr),
    ntohs(pr_netaddr_get_port(client_conn->local_addr)));

  res = proxy_ftp_disconnect(ftp);
  if (res < 0) {
    fprintf(stderr, "Error disconnecting from FTP server: %s\n",
      strerror(errno));
    destroy_pool(p);
    return 1;
  }

  ctrl_conn = pr_inet_openrw(p, client_conn, NULL, PR_NETIO_STRM_OTHR,
    -1, -1, -1, FALSE);
  if (ctrl_conn == NULL) {
    fprintf(stderr, "Error opening control connection: %s\n", strerror(errno));

    pr_inet_close(p, client_conn);
    destroy_pool(p);
    return 1;
  }

  fprintf(stdout, "Reading response from %s:%d\n", remote_name, remote_port);

  /* Read the response */
  memset(buf, '\0', sizeof(buf));

  /* XXX We need to write our own version of netio_telnet_gets(), with
   * the buffering to handle reassembly of a full FTP response out of
   * multiple TCP packets.  Not sure why the existing netio_telnet_gets()
   * is not sufficient.  But we don't need the handling of Telnet codes
   * in our reading.  But DO generate the 'core.ctrl-read' event, so that
   * any event listeners get a chance to process the data we've received.
   * (Or maybe use 'mod_proxy.server-read', and differentiate between
   * client and server reads/writes?)
   */
  if (pr_netio_read(ctrl_conn->instrm, buf, sizeof(buf)-1, 5) < 0) {
    fprintf(stderr, "Error reading response from server: %s\n",
      strerror(errno));

  } else {
    fprintf(stdout, "Response: \"%s\"\n", buf);
  }

  /* Disconnect */
  res = pr_netio_printf(ctrl_conn->outstrm, "%s\r\n", C_QUIT);
  if (res < 0) {
    fprintf(stderr, "Error writing command to server: %s", strerror(errno));
  }

  pr_inet_close(p, ctrl_conn);
  pr_inet_close(p, client_conn);
  destroy_pool(p);
  return 0;
}
Example #13
0
tl_class *tl_load_module(tl_procession *procession, const char *arg_str){

  tl_arglist arglist;
  tl_name mod_name;
  tl_class *x;
  void *handle;
  char *init_name;
  char *kill_name;
  char *dsp_name;
  char *ctls_name;
  void* (*ctls_func)(void);
  const char *init_affix = "tl_init_";
  const char *kill_affix = "tl_kill_";
  const char *dsp_affix  = "tl_dsp_";
  const char *ctls_affix  = "tl_reveal_ctls_";
  int mod_name_len;
  int i;

  // we *ALWAYS* pass the procession as the first argument
  // so plug it into the arglist
  arglist.argc = 1;
  arglist.argv[0] = (tl_arg *)malloc(sizeof(tl_arg));
  arglist.argv[0]->procession = procession;
  arglist.argv[0]->type = TL_PROCESSION;
 
 // parse the creation string into arguments
  tl_parse_args(&arglist, arg_str);
  
  // first arg is the full path to the module
  mod_name = cpy_file_name_no_path(arglist.argv[1]->str_val);
  printf("module name copied: %s\n%s\n",arglist.argv[1]->str_val, mod_name);

  // concoct the init function name
  mod_name_len = strlen(mod_name);
 
  init_name = malloc(sizeof(char) * (strlen(init_affix) + mod_name_len +1));
  strcpy(init_name, init_affix);
  init_name[strlen(init_affix)]='\0';
  strcat(init_name, mod_name);// correct?

  kill_name = malloc( sizeof(char) *(strlen(kill_affix) + mod_name_len));
  strcpy(kill_name, kill_affix);
  strcat(kill_name, mod_name);// correct?
  
  dsp_name = malloc(sizeof(char)*(strlen(dsp_affix) + mod_name_len));
  strcpy(dsp_name, dsp_affix);
  strcat(dsp_name, mod_name);// correct?

  ctls_name = malloc(sizeof(char)*(strlen(ctls_affix) + mod_name_len));
  strcpy(ctls_name, ctls_affix);
  strcat(ctls_name, mod_name);// correct?


  // dlopen the module
  handle = dlopen(arglist.argv[1]->str_val, RTLD_LAZY | RTLD_GLOBAL);
  if(!handle)
    {
      printf("error: tl_load_module: dlopen did return valid file handle\n");
      goto fail;// TODO: check this
    }
  x = init_class();

  // get the functions we want
  if(!(x->init_func = (tl_init_func)dlsym(handle, init_name)))
    {
      printf("error: tl_load_module: %s has invalid init function\n",mod_name);
goto fail;
    }
  if(!(x->kill_func = (tl_init_func)dlsym(handle, kill_name)))
    {
      printf("error: tl_load_module: %s has invalid kill function\n",mod_name);
      goto fail;
    }
  if(!(x->dsp_func = (tl_init_func)dlsym(handle, dsp_name)))
    {
      printf("error: tl_load_module: %s has invalid dsp function\n",mod_name);
      goto fail;
    }
  int *ptr;


  // get the ctls, if any
  if(!(ctls_func = (tl_init_func)dlsym(handle, ctls_name)))
    {
      printf("warning: tl_load_module: %s has no ctls revelation\n",mod_name);
      ctls_func = NULL;
    }


  // TODO: othis needs a more elegant solution:

  if(!(ptr = dlsym(handle, "in_cnt")))
    printf("warning tl_load_module: %s has no symbol 'in_cnt'\n",mod_name);
  else
    x->in_cnt = *ptr;

  if(!(ptr=dlsym(handle, "out_cnt")))
    printf("warning tl_load_module: %s has no symbol 'out_cnt'\n",mod_name);
  else
    x->out_cnt = *ptr;
 printf("ins %d outs %d\n",x->in_cnt, x->out_cnt);
    
  // printf("ins %d outs %d\n",x->in_cnt, x->out_cnt);
     
  if(!(x->mod = (void *)dlsym(handle, "this")))
      printf("warning: tl_load_module: %s has no self-reference\n",mod_name);

  /* if(!(tmp = (void *)dlsym(handle, "name"))) */
  /*     printf("warning: tl_load_module: %s has no name\n",mod_name); */
  /* else x->name = tmp(x); */

  // intialize the module
  x->args = &arglist;
  // TODO: check to see that args are properly destroyed

  // this installs the class onto the procession class stack
  // it also initializes the module itself
  tl_install_class(procession->class_head, x);

  // install ctls if any
  if(ctls_func != NULL)
    install_onto_ctl_list(procession->ctl_head, (tl_ctl *)ctls_func());

  // free memory
  free(init_name);
  free(kill_name);
  free(dsp_name);
  free(ctls_name);

  // free the args we created (this doesn't destroy the procession that we use in the first arg, just the container that points to it)
  for(i=0;i<arglist.argc;i++)
    free(arglist.argv[i]);

  return x;
 fail:
  printf("error: tl_load_module: module was invalid\n");
  return NULL;

}
Example #14
0
int setup(void){

  int i, cnt = 5000;
  tl_class *class_list;

  // initialize globals ... rethink this
  tl_set_samplerate(44100);
  tl_set_block_len(64);

  set_g_lvl_stck(init_lvl_stck());
  set_g_ctl_head(init_ctl(TL_HEAD_CTL));

  // TODO: attach these to modules, I can't see
  // any reason not to do this and automate this whole process
  ctl_l_freq = init_ctl(TL_LIN_CTL);
  ctl_r_freq = init_ctl(TL_LIN_CTL);

  ctl_l_freq->is_verbose = 0;
  ctl_r_freq->is_verbose = 0;

  ctl_l_amp = init_ctl(TL_LIN_CTL);
  ctl_r_amp = init_ctl(TL_LIN_CTL);

  ctl_l_amp->is_verbose = 1;
  ctl_r_amp->is_verbose = 1;

  install_onto_ctl_list(get_g_ctl_head(), ctl_l_freq);
  install_onto_ctl_list(get_g_ctl_head(), ctl_r_freq);
  install_onto_ctl_list(get_g_ctl_head(), ctl_l_amp);
  install_onto_ctl_list(get_g_ctl_head(), ctl_r_amp);

  // initialize portaudio
  pa_initialize(0,0,2,2,.25);

  // setup the modules
  dac = (tl_dac *)tl_init_dac(2,1);
  // dac will initialize the global output buffer
  tbl_l = (tl_table *)tl_init_table(1000, 1);
  tbl_r = (tl_table *)tl_init_table(1000, 1);
  lkup_l = (tl_lookup *)tl_init_lookup(1);
  lkup_r = (tl_lookup *)tl_init_lookup(1);

  osc_l = init_osc(tbl_l, lkup_l, ctl_l_freq->outlet, ctl_l_amp->outlet);
  osc_r = init_osc(tbl_r, lkup_r, ctl_r_freq->outlet, ctl_r_amp->outlet);


  // this part needs to be done explicitly
  // first, register the ctls
  set_ctl_kr(ctl_l_freq, &l_freq_val);
  set_ctl_kr(ctl_r_freq, &r_freq_val);
  set_ctl_kr(ctl_l_amp, &l_amp_val);
  set_ctl_kr(ctl_r_amp, &r_amp_val);

  // now register the classes
  set_g_class_head(init_class());

  tl_install_class(get_g_class_head(), (void *)osc_l, osc_l->dsp_func, osc_l->kill_func);
  tl_install_class(get_g_class_head(), (void *)osc_r, osc_r->dsp_func, osc_r->kill_func);
  tl_install_class(get_g_class_head(), (void *)dac, dac->dsp_func, dac->kill_func);

  // connect to the dac
  dac->inlets[0] = osc_l->tbl->outlets[0];
  dac->inlets[1] = osc_r->tbl->outlets[0];

  return 0;

}
Example #15
0
END_TEST

START_TEST (class_match_addr_test) {
  const pr_netaddr_t *addr;
  const pr_class_t *class;
  pr_netacl_t *acl;
  int res;

  class = pr_class_match_addr(NULL);
  fail_unless(class == NULL, "Failed to handle NULL argument");
  fail_unless(errno == EINVAL, "Failed to set errno to EINVAL");

  addr = pr_netaddr_get_addr(p, "localhost", FALSE);
  fail_unless(addr != NULL, "Failed to get addr: %s", strerror(errno));

  class = pr_class_match_addr(addr);
  fail_unless(class == NULL, "Failed to handle empty class list");
  fail_unless(errno == ENOENT, "Failed to set errno to ENOENT");

  res = pr_class_open(p, "localhost");
  fail_unless(res == 0, "Failed to open class: %s", strerror(errno));

  acl = pr_netacl_create(p, "127.0.0.1");
  fail_unless(acl != NULL, "Failed to create ACL: %s", strerror(errno));

  res = pr_class_add_acl(acl);
  fail_unless(res == 0, "Failed to add ACL to class: %s", strerror(errno));

  res = pr_class_close();
  fail_unless(res == 0, "Failed to close class: %s", strerror(errno));

  res = pr_class_open(p, "!localhost");
  fail_unless(res == 0, "Failed to open class: %s", strerror(errno));

  acl = pr_netacl_create(p, "!127.0.0.1");
  fail_unless(acl != NULL, "Failed to create ACL: %s", strerror(errno));

  res = pr_class_add_acl(acl);
  fail_unless(res == 0, "Failed to add ACL to class: %s", strerror(errno));

  res = pr_class_close();
  fail_unless(res == 0, "Failed to close class: %s", strerror(errno));

  class = pr_class_match_addr(addr);
  fail_unless(class != NULL, "Failed to match class for addr: %s",
    strerror(errno));
  fail_unless(strcmp(class->cls_name, "localhost") == 0,
    "Expected '%s', got '%s'", "localhost", class->cls_name);

  /* Reset the class list, add classes in a different order, and try again. */
  init_class();

  res = pr_class_open(p, "!localhost");
  fail_unless(res == 0, "Failed to open class: %s", strerror(errno));

  acl = pr_netacl_create(p, "!127.0.0.1");
  fail_unless(acl != NULL, "Failed to create ACL: %s", strerror(errno));

  res = pr_class_add_acl(acl);
  fail_unless(res == 0, "Failed to add ACL to class: %s", strerror(errno));

  res = pr_class_close();
  fail_unless(res == 0, "Failed to close class: %s", strerror(errno));

  res = pr_class_open(p, "localhost");
  fail_unless(res == 0, "Failed to open class: %s", strerror(errno));

  acl = pr_netacl_create(p, "127.0.0.1");
  fail_unless(acl != NULL, "Failed to create ACL: %s", strerror(errno));

  res = pr_class_add_acl(acl);
  fail_unless(res == 0, "Failed to add ACL to class: %s", strerror(errno));

  res = pr_class_close();
  fail_unless(res == 0, "Failed to close class: %s", strerror(errno));

  class = pr_class_match_addr(addr);
  fail_unless(class != NULL, "Failed to match class for addr: %s",
    strerror(errno));
  fail_unless(strcmp(class->cls_name, "localhost") == 0,
    "Expected '%s', got '%s'", "localhost", class->cls_name);

  /* Reset the class list, and see what happens when we try to match
   * the addr against an impossible set of rules.
   */
  init_class();

  res = pr_class_open(p, "impossible");
  fail_unless(res == 0, "Failed to open class: %s", strerror(errno));

  acl = pr_netacl_create(p, "!127.0.0.1");
  fail_unless(acl != NULL, "Failed to create ACL: %s", strerror(errno));

  res = pr_class_add_acl(acl);
  fail_unless(res == 0, "Failed to add ACL to class: %s", strerror(errno));

  acl = pr_netacl_create(p, "127.0.0.1");
  fail_unless(acl != NULL, "Failed to create ACL: %s", strerror(errno));

  res = pr_class_add_acl(acl);
  fail_unless(res == 0, "Failed to add ACL to class: %s", strerror(errno));

  res = pr_class_set_satisfy(PR_CLASS_SATISFY_ALL);
  fail_unless(res == 0, "Failed to set satisfy value: %s", strerror(errno));

  res = pr_class_close();
  fail_unless(res == 0, "Failed to close class: %s", strerror(errno));

  class = pr_class_match_addr(addr);
  fail_unless(class == NULL, "Unexpectedly matched class for addr");
  fail_unless(errno == ENOENT, "Failed to set errno to ENOENT");

  /* Reset the class list, add two classes with identical rules, and
   * verify that the first matching class wins.
   */
  init_class();

  res = pr_class_open(p, "first");
  fail_unless(res == 0, "Failed to open class: %s", strerror(errno));

  acl = pr_netacl_create(p, "127.0.0.1");
  fail_unless(acl != NULL, "Failed to create ACL: %s", strerror(errno));

  res = pr_class_add_acl(acl);
  fail_unless(res == 0, "Failed to add ACL to class: %s", strerror(errno));

  res = pr_class_close();
  fail_unless(res == 0, "Failed to close class: %s", strerror(errno));

  res = pr_class_open(p, "second");
  fail_unless(res == 0, "Failed to open class: %s", strerror(errno));

  acl = pr_netacl_create(p, "127.0.0.1");
  fail_unless(acl != NULL, "Failed to create ACL: %s", strerror(errno));

  res = pr_class_add_acl(acl);
  fail_unless(res == 0, "Failed to add ACL to class: %s", strerror(errno));

  res = pr_class_close();
  fail_unless(res == 0, "Failed to close class: %s", strerror(errno));

  class = pr_class_match_addr(addr);
  fail_unless(class != NULL, "Failed to match class for addr: %s",
    strerror(errno));
  fail_unless(strcmp(class->cls_name, "first") == 0,
    "Expected '%s', got '%s'", "first", class->cls_name);

  init_class();

  res = pr_class_open(p, "second");
  fail_unless(res == 0, "Failed to open class: %s", strerror(errno));

  acl = pr_netacl_create(p, "127.0.0.1");
  fail_unless(acl != NULL, "Failed to create ACL: %s", strerror(errno));

  res = pr_class_add_acl(acl);
  fail_unless(res == 0, "Failed to add ACL to class: %s", strerror(errno));

  res = pr_class_close();
  fail_unless(res == 0, "Failed to close class: %s", strerror(errno));

  res = pr_class_open(p, "first");
  fail_unless(res == 0, "Failed to open class: %s", strerror(errno));

  acl = pr_netacl_create(p, "127.0.0.1");
  fail_unless(acl != NULL, "Failed to create ACL: %s", strerror(errno));

  res = pr_class_add_acl(acl);
  fail_unless(res == 0, "Failed to add ACL to class: %s", strerror(errno));

  res = pr_class_close();
  fail_unless(res == 0, "Failed to close class: %s", strerror(errno));

  class = pr_class_match_addr(addr);
  fail_unless(class != NULL, "Failed to match class for addr: %s",
    strerror(errno));
  fail_unless(strcmp(class->cls_name, "second") == 0,
    "Expected '%s', got '%s'", "second", class->cls_name);

  init_class();

  res = pr_class_open(p, "match");
  fail_unless(res == 0, "Failed to open class: %s", strerror(errno));

  acl = pr_netacl_create(p, "127.0.0.1");
  fail_unless(acl != NULL, "Failed to create ACL: %s", strerror(errno));

  res = pr_class_add_acl(acl);
  fail_unless(res == 0, "Failed to add ACL to class: %s", strerror(errno));

  res = pr_class_set_satisfy(PR_CLASS_SATISFY_ALL);
  fail_unless(res == 0, "Failed to set satisfy value: %s", strerror(errno));

  res = pr_class_close();
  fail_unless(res == 0, "Failed to close class: %s", strerror(errno));

  class = pr_class_match_addr(addr);
  fail_unless(class != NULL, "Failed to match class for addr: %s",
    strerror(errno));
  fail_unless(strcmp(class->cls_name, "match") == 0,
    "Expected '%s', got '%s'", "match", class->cls_name);

}
Example #16
0
/** Run the daemon.
 * @param[in] argc Number of arguments in \a argv.
 * @param[in] argv Arguments to program execution.
 */
int main(int argc, char **argv) {
  CurrentTime = time(NULL);

  thisServer.argc = argc;
  thisServer.argv = argv;
  thisServer.uid  = getuid();
  thisServer.euid = geteuid();

#ifdef MDEBUG
  mem_dbg_initialise();
#endif

#if defined(HAVE_SETRLIMIT) && defined(RLIMIT_CORE)
  set_core_limit();
#endif

  umask(077);                   /* better safe than sorry --SRB */
  memset(&me, 0, sizeof(me));
  memset(&me_con, 0, sizeof(me_con));
  cli_connect(&me) = &me_con;
  cli_fd(&me) = -1;

  parse_command_line(argc, argv);

  if (chdir(dpath)) {
    fprintf(stderr, "Fail: Cannot chdir(%s): %s, check DPATH\n", dpath, strerror(errno));
    return 2;
  }

  if (!set_userid_if_needed())
    return 3;

  /* Check paths for accessibility */
  if (!check_file_access(SPATH, 'S', X_OK) ||
      !check_file_access(configfile, 'C', R_OK))
    return 4;

  if (!init_connection_limits())
    return 9;

  close_connections(!(thisServer.bootopt & (BOOT_DEBUG | BOOT_TTY | BOOT_CHKCONF)));

  /* daemon_init() must be before event_init() because kqueue() FDs
   * are, perversely, not inherited across fork().
   */
  daemon_init(thisServer.bootopt & BOOT_TTY);

#ifdef DEBUGMODE
  /* Must reserve fd 2... */
  if (debuglevel >= 0 && !(thisServer.bootopt & BOOT_TTY)) {
    int fd;
    if ((fd = open("/dev/null", O_WRONLY)) < 0) {
      fprintf(stderr, "Unable to open /dev/null (to reserve fd 2): %s\n",
	      strerror(errno));
      return 8;
    }
    if (fd != 2 && dup2(fd, 2) < 0) {
      fprintf(stderr, "Unable to reserve fd 2; dup2 said: %s\n",
	      strerror(errno));
      return 8;
    }
  }
#endif

  event_init(MAXCONNECTIONS);

  setup_signals();
  feature_init(); /* initialize features... */
  log_init(*argv);
  set_nomem_handler(outofmemory);

  initload();
  init_list();
  init_hash();
  init_class();
  initwhowas();
  initmsgtree();
  initstats();

  /* we need this for now, when we're modular this 
     should be removed -- hikari */
  ircd_crypt_init();

  motd_init();

  if (!init_conf()) {
    log_write(LS_SYSTEM, L_CRIT, 0, "Failed to read configuration file %s",
	      configfile);
    return 7;
  }

  if (thisServer.bootopt & BOOT_CHKCONF) {
    if (dbg_client)
      conf_debug_iline(dbg_client);
    fprintf(stderr, "Configuration file %s checked okay.\n", configfile);
    return 0;
  }

  debug_init(thisServer.bootopt & BOOT_TTY);
  if (check_pid()) {
    Debug((DEBUG_FATAL, "Failed to acquire PID file lock after fork"));
    exit(2);
  }

  init_server_identity();

  uping_init();

  stats_init();

  IPcheck_init();
  timer_add(timer_init(&connect_timer), try_connections, 0, TT_RELATIVE, 1);
  timer_add(timer_init(&ping_timer), check_pings, 0, TT_RELATIVE, 1);
  timer_add(timer_init(&destruct_event_timer), exec_expired_destruct_events, 0, TT_PERIODIC, 60);
  timer_add(timer_init(&mute_timer), check_expired_mutes, 0, TT_PERIODIC, 30);

  CurrentTime = time(NULL);

  SetMe(&me);
  cli_magic(&me) = CLIENT_MAGIC;
  cli_from(&me) = &me;
  make_server(&me);

  cli_serv(&me)->timestamp = TStime();  /* Abuse own link timestamp as start TS */
  cli_serv(&me)->prot      = atoi(MAJOR_PROTOCOL);
  cli_serv(&me)->up        = &me;
  cli_serv(&me)->down      = NULL;
  cli_handler(&me)         = SERVER_HANDLER;

  SetYXXCapacity(&me, MAXCLIENTS);

  cli_lasttime(&me) = cli_since(&me) = cli_firsttime(&me) = CurrentTime;

  hAddClient(&me);

  write_pidfile();
  init_counters();

  Debug((DEBUG_NOTICE, "Server ready..."));
  log_write(LS_SYSTEM, L_NOTICE, 0, "Server Ready");

  event_loop();

  return 0;
}
Example #17
0
static bool init_ids(JNIEnv* env) {
	// Load NativeObject classes
	init_class(env, "mapnik/NativeObject", CLASS_NATIVEOBJECT);
	init_class(env, "mapnik/MapDefinition", CLASS_MAP);
	init_class(env, "mapnik/Datasource", CLASS_DATASOURCE);
	init_class(env, "mapnik/DatasourceCache", CLASS_DATASOURCE_CACHE);
	init_class(env, "mapnik/Layer", CLASS_LAYER);
	init_class(env, "mapnik/FeatureTypeStyle", CLASS_FEATURE_TYPE_STYLE);
	init_class(env, "mapnik/Projection", CLASS_PROJECTION);
	init_class(env, "mapnik/Query", CLASS_QUERY);
	init_class(env, "mapnik/FeatureSet", CLASS_FEATURESET);
	init_class(env, "mapnik/Geometry", CLASS_GEOMETRY);
	init_class(env, "mapnik/Image", CLASS_IMAGE);
	init_class(env, "mapnik/Grid", CLASS_GRID);

	// Ptr
	CTOR_NATIVEOBJECT=lookup_method(env, CLASS_NATIVEOBJECT, "<init>", "()V");
	FIELD_PTR=lookup_field(env, CLASS_NATIVEOBJECT, "ptr", "J");

	// FeatureSet
	FIELD_FEATURESET_FEATURE_PTR=lookup_field(env, CLASS_FEATURESET, "feature_ptr", "J");

	// String
	init_class(env, "java/lang/String", CLASS_STRING);

	// Integer
	init_class(env, "java/lang/Integer", CLASS_INTEGER);
	METHOD_INTEGER_VALUEOF=lookup_static_method(env, CLASS_INTEGER, "valueOf", "(I)Ljava/lang/Integer;");

	init_class(env, "java/lang/Boolean", CLASS_BOOLEAN);
	METHOD_BOOLEAN_VALUEOF=lookup_static_method(env, CLASS_BOOLEAN, "valueOf", "(Z)Ljava/lang/Boolean;");

	init_class(env, "java/lang/Long", CLASS_LONG);
	METHOD_LONG_VALUEOF=lookup_static_method(env, CLASS_LONG, "valueOf", "(J)Ljava/lang/Long;");

	// Double
	init_class(env, "java/lang/Double", CLASS_DOUBLE);
	METHOD_DOUBLE_VALUEOF=lookup_static_method(env, CLASS_DOUBLE, "valueOf", "(D)Ljava/lang/Double;");

	// Parameters
	init_class(env, "mapnik/Parameters", CLASS_PARAMETERS);
	CTOR_PARAMETERS=lookup_method(env, CLASS_PARAMETERS, "<init>", "()V");
	METHOD_PARAMETERS_SET_STRING=lookup_method(env, CLASS_PARAMETERS, "setString", "(Ljava/lang/String;Ljava/lang/String;)V");
	METHOD_PARAMETERS_SET_BOOLEAN=lookup_method(env, CLASS_PARAMETERS, "setBool", "(Ljava/lang/String;Z)V");
	METHOD_PARAMETERS_SET_INT=lookup_method(env, CLASS_PARAMETERS, "setInt", "(Ljava/lang/String;I)V");
	METHOD_PARAMETERS_SET_LONG=lookup_method(env, CLASS_PARAMETERS, "setLong", "(Ljava/lang/String;J)V");
	METHOD_PARAMETERS_SET_DOUBLE=lookup_method(env, CLASS_PARAMETERS, "setDouble", "(Ljava/lang/String;D)V");
	METHOD_PARAMETERS_COPY_TO_NATIVE=lookup_method(env, CLASS_PARAMETERS, "copyToNative", "(J)V");

	// HashSet
	init_class(env, "java/util/HashSet", CLASS_HASHSET);
	CTOR_HASHSET=lookup_method(env, CLASS_HASHSET, "<init>", "()V");
	METHOD_HASHSET_ADD=lookup_method(env, CLASS_HASHSET, "add", "(Ljava/lang/Object;)Z");

	// Box2d
	init_class(env, "mapnik/Box2d", CLASS_BOX2D);
	FIELD_BOX2D_MINX=lookup_field(env, CLASS_BOX2D, "minx", "D");
	FIELD_BOX2D_MINY=lookup_field(env, CLASS_BOX2D, "miny", "D");
	FIELD_BOX2D_MAXX=lookup_field(env, CLASS_BOX2D, "maxx", "D");
	FIELD_BOX2D_MAXY=lookup_field(env, CLASS_BOX2D, "maxy", "D");

	// Color
	init_class(env, "mapnik/Color", CLASS_COLOR);
	FIELD_COLOR_RED=lookup_field(env, CLASS_COLOR, "red", "I");
	FIELD_COLOR_GREEN=lookup_field(env, CLASS_COLOR, "green", "I");
	FIELD_COLOR_BLUE=lookup_field(env, CLASS_COLOR, "blue", "I");
	FIELD_COLOR_ALPHA=lookup_field(env, CLASS_COLOR, "alpha", "I");

	// Coord
	init_class(env, "mapnik/Coord", CLASS_COORD);
	FIELD_COORD_X=lookup_field(env, CLASS_COORD, "x", "D");
	FIELD_COORD_Y=lookup_field(env, CLASS_COORD, "y", "D");

	// LayerDescriptor
	init_class(env, "mapnik/LayerDescriptor", CLASS_LAYERDESCRIPTOR);
	CTOR_LAYERDESCRIPTOR=lookup_method(env, CLASS_LAYERDESCRIPTOR, "<init>", "()V");
	FIELD_LAYERDESCRIPTOR_NAME=lookup_field(env, CLASS_LAYERDESCRIPTOR, "name", "Ljava/lang/String;");
	FIELD_LAYERDESCRIPTOR_ENCODING=lookup_field(env, CLASS_LAYERDESCRIPTOR, "encoding", "Ljava/lang/String;");
	METHOD_LAYERDESCRIPTOR_ADDDESCRIPTOR=lookup_method(env, CLASS_LAYERDESCRIPTOR, "addDescriptor", "(Lmapnik/AttributeDescriptor;)V");

	// AttributeDescriptor
	init_class(env, "mapnik/AttributeDescriptor", CLASS_ATTRIBUTEDESCRIPTOR);
	CTOR_ATTRIBUTEDESCRIPTOR=lookup_method(env, CLASS_ATTRIBUTEDESCRIPTOR, "<init>", "()V");
	FIELD_ATTRIBUTEDESCRIPTOR_NAME=lookup_field(env, CLASS_ATTRIBUTEDESCRIPTOR, "name", "Ljava/lang/String;");
	FIELD_ATTRIBUTEDESCRIPTOR_TYPE=lookup_field(env, CLASS_ATTRIBUTEDESCRIPTOR, "type", "I");
	FIELD_ATTRIBUTEDESCRIPTOR_PRIMARYKEY=lookup_field(env, CLASS_ATTRIBUTEDESCRIPTOR, "primaryKey", "Z");
	FIELD_ATTRIBUTEDESCRIPTOR_SIZE=lookup_field(env, CLASS_ATTRIBUTEDESCRIPTOR, "size", "I");
	FIELD_ATTRIBUTEDESCRIPTOR_PRECISION=lookup_field(env, CLASS_ATTRIBUTEDESCRIPTOR, "precision", "I");

	return true;
}