Example #1
0
/*
 * comm_accept() - accept an incoming connection
 *
 * This is a simple wrapper for accept() which enforces FD limits like
 * comm_open() does. Returned fd must be either closed or tagged with
 * fd_open (this function no longer does it).
 */
int
comm_accept(struct Listener *lptr, struct irc_ssaddr *pn)
{
  int newfd;
  socklen_t addrlen = sizeof(struct irc_ssaddr);

  if (number_fd >= hard_fdlimit)
  {
    errno = ENFILE;
    return -1;
  }

  /*
   * Next, do the accept(). if we get an error, we should drop the
   * reserved fd limit, but we can deal with that when comm_open()
   * also does it. XXX -- adrian
   */
  newfd = accept(lptr->fd.fd, (struct sockaddr *)pn, (socklen_t *)&addrlen);
  if (newfd < 0)
  {
#ifdef _WIN32
    errno = WSAGetLastError();
#endif
    return -1;
  }

#ifdef IPV6
  remove_ipv6_mapping(pn);
#else
  pn->ss_len = addrlen;
#endif

  execute_callback(setup_socket_cb, newfd);

  /* .. and return */
  return newfd;
}
Example #2
0
void dequeue_loop(void)
{
	Event_t e = event_dequeue();

	if (e != EVENT_NULL)
	{

// analyse des évènements
#if KBS_ANALYSER

		unsigned long last_process_time = micros();

#endif

		execute_callback(e);

// analyse des évènements
#if KBS_ANALYSER

		busy_time += micros() - last_process_time;

#endif
	}
}
Example #3
0
int    GLUI_Graph::mouse_held_down_handler( int local_x, int local_y, bool inside)
{

	int graph_x,graph_y;

	graph_x = local_x - x_abs - ((w+1)-graph_w)/2;
	if (graph_x < 0) graph_x = 0;
	if (graph_x >= graph_w) graph_x = graph_w-1;
	graph_y = (h - GLUI_GRAPH_IMG_BOTTOM_BORDER - 2) - (local_y - y_abs);
	if (graph_y < 0) graph_y = 0;
	if (graph_y >= graph_h) graph_y = graph_h-1;

	//printf("%d %d\n",graph_x, graph_y);

	event = GLUI_GRAPH_EVENT_MOUSE_MOVE;
	event_x = graph_x;
	event_y = graph_y;
	event_key = -1;
	event_mod = -1;

	execute_callback();

	return false;
}
    LedResource() {
        // create ObjectID with metadata tag of '3201', which is 'digital output'
        led_object = M2MInterfaceFactory::create_object("3201");
        M2MObjectInstance* led_inst = led_object->create_object_instance();

        // 5853 = Multi-state output
        M2MResource* pattern_res = led_inst->create_dynamic_resource("5853", "Pattern",
            M2MResourceInstance::STRING, false);
        // read and write
        pattern_res->set_operation(M2MBase::GET_PUT_ALLOWED);
        // set initial pattern (toggle every 200ms. 7 toggles in total)
        pattern_res->set_value((const uint8_t*)"500:500:500:500:500:500:500", 27);

        // there's not really an execute LWM2M ID that matches... hmm...
        M2MResource* led_res = led_inst->create_dynamic_resource("5850", "Blink",
            M2MResourceInstance::OPAQUE, false);
        // we allow executing a function here...
        led_res->set_operation(M2MBase::POST_ALLOWED);
        // when a POST comes in, we want to execute the led_execute_callback
        led_res->set_execute_function(execute_callback(this, &LedResource::blink));
        // Completion of execute function can take a time, that's why delayed response is used
        led_res->set_delayed_response(true);
        blink_args = new BlinkArgs();
    }
Example #5
0
int    GLUI_Slider::special_handler( int key,int mods )
{
   int grads;

   int min_x, max_x, wid_x;

   int g;
   double g_f;

   int new_int;

   min_x = 2 + GLUI_SLIDER_KNOB_SIDE_BORDER + GLUI_SLIDER_KNOB_HALF_WIDTH;
   max_x = w - 2 - GLUI_SLIDER_KNOB_HALF_WIDTH - GLUI_SLIDER_KNOB_SIDE_BORDER;
   wid_x = max_x - min_x + 1;

   //The arrows adjust the slider's value.
   //Without mods (shift, ctrl, alt), the current
   //value is rounded to the nearest grad and then
   //one grad is added/subtracted.  However, shift,
   //ctrl, alt modify the grad size by 1/2,1/10,
   //1/100. If this is an int slider, the min
   //change is 1.
   //Note, by default, grads=0 which takes the
   //num of grads to be equal to the pixel
   //width of the slider...

   if (graduations == 0)
      grads = wid_x;
   else
      grads = graduations;

   if (mods == 0) {
      //Use unmodified grads
   } else if (mods & GLUT_ACTIVE_SHIFT) {
      grads = 2*(grads-1) + 1;
   } else if (mods & GLUT_ACTIVE_CTRL) {
      grads = 10*(grads-1) + 1;
   } else if (mods & GLUT_ACTIVE_ALT) {
      grads = 100*(grads-1) + 1;
   } else {
      return false;
   }

   switch (data_type) {
   case GLUI_SLIDER_INT:
      if (int_low != int_high) {
         if (int_val == int_high)
            g = grads-1;
         else
            g = ((int)(((double)grads)*((double)(int_val-int_low))/((double)(int_high - int_low))));
      } else
         g = 0;
      break;
   case GLUI_SLIDER_FLOAT:
      if (float_low != float_high) {
         if (float_val == float_high)
            g = grads-1;
         else
            g = ((int)(((double)grads)*((double)(float_val-float_low))/((double)(float_high - float_low))));
      } else
         g = 0;
      break;
   default:
      fprintf(stderr,"GLUI_Slider::upate_knob - Impossible data type!\n");
      abort();
   }

   switch (key) {
   case GLUT_KEY_RIGHT:
      g += 1;
      if (g > (grads-1))
         g = grads-1;
      break;
   case GLUT_KEY_LEFT:
      g -= 1;
      if (g < 0)
         g = 0;
      break;
   default:
      return false;
      break;
   }

   g_f = ((double)g)/((double)(grads-1));

   switch (data_type) {
   case GLUI_SLIDER_INT:
      new_int = (int) (((double)int_low) + ((double)(g_f*((double)(int_high-int_low)) )));

      if (new_int == int_val) {
         switch (key) {
         case GLUT_KEY_RIGHT:
            new_int += 1;
            if (new_int > int_high)
               new_int = int_high;
            break;
         case GLUT_KEY_LEFT:
            new_int -= 1;
            if (new_int < int_low)
               new_int = int_low;
            break;
         }
      }
      set_int_val(new_int);
      set_float_val((float)(int_val));
      break;
   case GLUI_SLIDER_FLOAT:
      set_float_val((double)float_low + ((double)g_f)*((double)(float_high-float_low)));
      set_int_val((int)(float_val));
      break;
   default:
      fprintf(stderr,"GLUI_Slider::upate_knob - Impossible data type!\n");
      abort();
   }

   draw_translated_active_area();
   if ( glui ) glui->post_update_main_gfx();
   execute_callback();

   return false;
}
Example #6
0
/*
 * add_connection - creates a client which has just connected to us on 
 * the given fd. The sockhost field is initialized with the ip# of the host.
 * An unique id is calculated now, in case it is needed for auth.
 * The client is sent to the auth module for verification, and not put in
 * any client list yet.
 */
void
add_connection(struct Listener *listener, struct irc_ssaddr *irn, int fd)
{
  struct Client *new_client;

  assert(NULL != listener);

  new_client = make_client(NULL);

  fd_open(&new_client->localClient->fd, fd, 1,
          (listener->flags & LISTENER_SSL) ?
	  "Incoming SSL connection" : "Incoming connection");

  /* 
   * copy address to 'sockhost' as a string, copy it to host too
   * so we have something valid to put into error messages...
   */
  memcpy(&new_client->ip, irn, sizeof(struct irc_ssaddr));

  irc_getnameinfo((struct sockaddr*)&new_client->ip,
        new_client->ip.ss_len,  new_client->sockhost, 
        HOSTIPLEN, NULL, 0, NI_NUMERICHOST);
  new_client->aftype = new_client->ip.ss.ss_family;
#ifdef IPV6
  if (new_client->sockhost[0] == ':')
    strlcat(new_client->host, "0", HOSTLEN+1);

  if (new_client->aftype == AF_INET6 && 
      ConfigFileEntry.dot_in_ip6_addr == 1)
  {
    strlcat(new_client->host, new_client->sockhost,HOSTLEN+1);
    strlcat(new_client->host, ".", HOSTLEN+1);
  }
  else
#endif
    strlcat(new_client->host, new_client->sockhost,HOSTLEN+1);

  new_client->connect_id = ++connect_id;
  new_client->localClient->listener = listener;
  ++listener->ref_count;

#ifdef HAVE_LIBCRYPTO
  if (listener->flags & LISTENER_SSL)
  {
    if ((new_client->localClient->fd.ssl = SSL_new(ServerInfo.ctx)) == NULL)
    {
      ilog(L_CRIT, "SSL_new() ERROR! -- %s",
           ERR_error_string(ERR_get_error(), NULL));

      SetDead(new_client);
      exit_client(new_client, new_client, "SSL_new failed");
      return;
    }

    SSL_set_fd(new_client->localClient->fd.ssl, fd);
    ssl_handshake(0, new_client);
  }
  else
#endif
    execute_callback(auth_cb, new_client);
}
Example #7
0
/**
 * Main function of the timer task. This function is in charge of
 *    calling the callbacks associated with the timers.
 *
 *    This function is run in a high priority task on microkernel builds.
 *    This function is run in a high priority fiber on nanokernel builds.
 *    It implements an infinite loop that waits for any of the semaphores from
 *    g_TimerSem.
 *    When a semaphore is signaled, this function fetches the pointer to the
 *    associated callback in g_TimerDesc, then calls it.
 *
 * @param dummy1 not used (required by ZEPHYR API)
 * @param dummy2 not used (required by ZEPHYR API) *
 *
 */
void timer_task(int dummy1, int dummy2)
{
    uint32_t timeout;
    uint32_t now;

    UNUSED(dummy1);
    UNUSED(dummy2);

    timeout = OS_WAIT_FOREVER;

    while (1) /* the Timer task shall never stop */
    {
#ifdef CONFIG_MICROKERNEL /********************** MICRO KERNEL SPECIFIC:  */
        /* block until g_TimerSem is signaled or until the next timeout expires */
        (void) task_sem_take_wait_timeout(g_TimerSem, timeout);
#else
        if (NULL == g_CurrentTimerHead)
        {
            /* Start a background timer with max positive delay */
            nano_fiber_timer_start (&g_NanoTimer, 0x7FFFFFFF);
            /* wait until the next timer expires or one is added or removed */
            nano_fiber_timer_wait (&g_NanoTimer);
        }
#endif
        now = _GET_TICK();
        /* task is unblocked: check for expired timers */
        while (is_after_expiration (now, &(g_CurrentTimerHead->desc)))
        {
            execute_callback(g_CurrentTimerHead);
        }
        /* Compute timeout until the expiration of the next timer */
        if ( NULL != g_CurrentTimerHead )
        {
            now = _GET_TICK();
            /* In micro kernel context, timeout = 0 or timeout < 0 works.
             * In nano kernel context timeout must be a positive value.
            */
#ifdef CONFIG_NANOKERNEL
            if (g_CurrentTimerHead->desc.expiration > now)
            {
#endif
                timeout = g_CurrentTimerHead->desc.expiration - now;
                if (OS_WAIT_FOREVER == timeout)
                { /* cannot have timeout = OS_WAIT_FOREVER while there is
                    still at least one active timer */
                    timeout++;
                }
#ifdef CONFIG_NANOKERNEL
                nano_fiber_timer_start (&g_NanoTimer, timeout);
                /* wait until the next timer expires or one is added or removed */
                nano_fiber_timer_wait (&g_NanoTimer);
                /* nano_fiber_timer_wait will wait until "natural" timer
                * expiration, or until nano_fiber_timer_stop(&g_NanoTimer)
                * is called by the timer_callback or by timer_stop() */
            }
#endif
        }
#ifdef CONFIG_MICROKERNEL
        else
        {
            timeout = OS_WAIT_FOREVER;
        }
#endif

#ifdef __DEBUG_OS_ABSTRACTION_TIMER
        if (NULL != g_CurrentTimerHead )
            _log ("\nINFO : timer_task : now = %u, next timer expires at %u, timeout = %u", _GET_TICK() , g_CurrentTimerHead->desc.expiration, timeout );
        else
            _log ("\nINFO : timer_task : now = %u, no next timer, timeout = OS_WAIT_FOREVER", _GET_TICK() );
#endif

    } /* end while(1) */
}
Example #8
0
int main(int argc, char *argv[])
{
#ifndef _WIN32
  if (geteuid() == 0)
  {
    fprintf(stderr, "Running IRC services is root is not recommended.");
    return 1;
  }
  setup_corefile();
#endif
  memset(&ServicesInfo, 0, sizeof(ServicesInfo));
  memset(&ServicesState, 0, sizeof(ServicesState));

  ServicesState.configfile = CPATH; 
  ServicesState.logfile    = LPATH;
  ServicesState.pidfile    = PPATH;
  ServicesState.fully_connected = 0;

  parseargs(&argc, &argv, myopts);

  if(ServicesState.printversion)
  {
    printf("oftc-ircservices: version: %s\n", VERSION);
    exit(EXIT_SUCCESS);
  }

  if(chdir(DPATH))
  {
    perror("chdir");
    exit(EXIT_FAILURE);
  }

#ifndef _WIN32
  if(!ServicesState.foreground)
    make_daemon();
  else
    print_startup(getpid());
#endif

  setup_signals();
  memset(&me, 0, sizeof(me));

  libio_init(!ServicesState.foreground);
  init_events();
  iorecv_cb = register_callback("iorecv", iorecv_default);
  connected_cb = register_callback("server connected", server_connected);
  iosend_cb = register_callback("iosend", iosend_default);

  OpenSSL_add_all_digests();
 
  init_interface();
  check_pidfile(ServicesState.pidfile);
  init_log(ServicesState.logfile);

#ifdef HAVE_RUBY
  init_ruby();
  signal(SIGSEGV, SIG_DFL);
#endif

  init_channel();
  init_conf();
  init_client();
  init_parser();
  init_channel_modes();
  init_mqueue();
  init_tor();

  me.from = me.servptr = &me;
  SetServer(&me);
  SetMe(&me);
  dlinkAdd(&me, &me.node, &global_client_list);
  
  read_services_conf(TRUE);
  init_db();
  init_uid();
 
#ifdef HAVE_PYTHON
  init_python();
#endif

  init_kill();

  write_pidfile(ServicesState.pidfile);
  ilog(L_NOTICE, "Services Ready");

  db_load_driver();
#ifdef USE_SHARED_MODULES
  if(chdir(MODPATH))
  {
    ilog(L_ERROR, "Could not load core modules from %s: %s",
         MODPATH, strerror(errno));
    exit(EXIT_FAILURE);
  }

  /* Go back to DPATH after checking to see if we can chdir to MODPATH */
  chdir(DPATH);
#else
  load_all_modules(1);
#endif

  boot_modules(1);
  
  connect_server();

  for(;;)
  {
    while (eventNextTime() <= CurrentTime)
      eventRun();

    execute_callback(do_event_cb);

    if(events_loop() == -1)
    {
      ilog(L_CRIT, "libevent returned error %d", errno);
      services_die("Libevent returned some sort of error", NO);
      break;
    }

    comm_select();
    send_queued_all();

    if(dorehash)
    {
      ilog(L_INFO, "Got SIGHUP, reloading configuration");
      read_services_conf(NO);
      dorehash = 0;
    }
  }

  return 0;
}
Example #9
0
/*! \brief SVSMODE command handler (called by services)
 *
 * \param client_p Pointer to allocated Client struct with physical connection
 *                 to this server, i.e. with an open socket connected.
 * \param source_p Pointer to allocated Client struct from which the message
 *                 originally comes from.  This can be a local or remote client.
 * \param parc     Integer holding the number of supplied arguments.
 * \param parv     Argument vector where parv[0] .. parv[parc-1] are non-NULL
 *                 pointers.
 * \note Valid arguments for this command are:
 *      - parv[0] = sender prefix
 *      - parv[1] = nickname
 *      - parv[2] = TS (or mode, depending on svs version)
 *      - parv[3] = mode (or services id if old svs version)
 *      - parv[4] = optional argument (services id)
 */
static void
ms_svsmode(struct Client *client_p, struct Client *source_p,
           int parc, char *parv[])
{
  struct Client *target_p = NULL;
  int what = MODE_ADD;
  unsigned int flag = 0, setflags = 0;
  char *m = NULL, *modes = NULL, *extarg = NULL;
  time_t ts = 0;

  if (!HasFlag(source_p, FLAGS_SERVICE))
    return;

  if ((parc >= 4) && ((*parv[3] == '+') || (*parv[3] == '-')))
  {
    ts     = atol(parv[2]);
    modes  = parv[3];
    extarg = (parc > 4) ? parv[4] : NULL;
  }
  else
  {
    modes  = parv[2];
    extarg = (parc > 3) ? parv[3] : NULL;
  }

  if ((target_p = find_person(client_p, parv[1])) == NULL)
    return;

  if (ts && (ts != target_p->tsinfo))
    return;

  setflags = target_p->umodes;

  for (m = modes; *m; ++m)
  {
    switch (*m)
    {
      case '+':
        what = MODE_ADD;
        break;

      case '-':
        what = MODE_DEL;
        break;

      case 'x':
        if (what == MODE_ADD && extarg)
          user_set_hostmask(target_p, extarg);

        break;

      case 'd':
        if (!EmptyString(extarg))
          strlcpy(target_p->svid, extarg, sizeof(target_p->svid));

        break;

      case 'o':
        if (what == MODE_DEL && HasUMode(target_p, UMODE_OPER))
        {
          ClearOper(target_p);
          Count.oper--;

          if (MyConnect(target_p))
          {
            dlink_node *dm = NULL;

            detach_conf(target_p, OPER_TYPE);
            ClrOFlag(target_p);
            DelUMode(target_p, ConfigFileEntry.oper_only_umodes);

            if ((dm = dlinkFindDelete(&oper_list, target_p)) != NULL)
              free_dlink_node(dm);
          }
        }

        break;

      case 'i':
        if (what == MODE_ADD && !HasUMode(target_p, UMODE_INVISIBLE))
        {
          AddUMode(target_p, UMODE_INVISIBLE);
          ++Count.invisi;
        }

        if (what == MODE_DEL && HasUMode(target_p, UMODE_INVISIBLE))
        {
          DelUMode(target_p, UMODE_INVISIBLE);
          --Count.invisi;
        }

        break;

      case ' ':
      case '\n':
      case '\r':
      case '\t':
        break;

      default:
        if ((flag = user_modes[(unsigned char) * m]))
          execute_callback(umode_cb, client_p, target_p, what, flag);

        break;
    }
  }

  if (extarg)
  {
    sendto_server(client_p, CAP_TS6, NOCAPS,
                  ":%s SVSMODE %s %lu %s %s", ID(source_p),
                  ID(target_p), (unsigned long)target_p->tsinfo, modes, extarg);
    sendto_server(client_p, NOCAPS, CAP_TS6,
                  ":%s SVSMODE %s %lu %s %s", source_p->name,
                  target_p->name, (unsigned long)target_p->tsinfo, modes, extarg);
  }
  else
  {
    sendto_server(client_p, CAP_TS6, NOCAPS,
                  ":%s SVSMODE %s %lu %s", ID(source_p),
                  ID(target_p), (unsigned long)target_p->tsinfo, modes);
    sendto_server(client_p, NOCAPS, CAP_TS6,
                  ":%s SVSMODE %s %lu %s", source_p->name,
                  target_p->name, (unsigned long)target_p->tsinfo, modes);
  }

  if (MyConnect(target_p) && (setflags != target_p->umodes))
  {
    char modebuf[IRCD_BUFSIZE];

    send_umode(target_p, target_p, setflags, 0xffffffff, modebuf);
  }
}
void Test_M2MResourceInstance::test_set_execute_function()
{
    MyTest test;
    resource_instance->set_execute_function(execute_callback(&test,&MyTest::execute_function));
}