Ejemplo n.º 1
0
static void handle_message(struct cfw_message *msg, void *param)
{
	switch (CFW_MESSAGE_ID(msg)) {
	case MSG_ID_CIRCULAR_STORAGE_PUSH_REQ:
		handle_push(msg);
		break;
	case MSG_ID_CIRCULAR_STORAGE_POP_REQ:
		handle_pop(msg);
		break;
	case MSG_ID_CIRCULAR_STORAGE_PEEK_REQ:
		handle_peek(msg);
		break;
	case MSG_ID_CIRCULAR_STORAGE_CLEAR_REQ:
		handle_clear(msg);
		break;
	case MSG_ID_LL_CIRCULAR_STORAGE_SHUTDOWN_REQ:
		cfw_send_message(CFW_MESSAGE_PRIV(msg));
		break;
	case MSG_ID_CIRCULAR_STORAGE_GET_REQ:
		handle_get(msg);
	default:
		cfw_print_default_handle_error_msg(LOG_MODULE_MAIN,
						   CFW_MESSAGE_ID(
							   msg));
		break;
	}

	cfw_msg_free(msg);
}
Ejemplo n.º 2
0
cell_t *invoke(cell_t *fun, cell_t *args, environ_t *env) {
  int argslen, paramlen;
  environ_t *new_env;
  function_t *func = fun->slot2.fun;
  cell_t *ret;
  cell_t *code;
  handle_t *hc;

  argslen = proper_list_length(args,0);
  paramlen = proper_list_length(func->param_list, 0);

  if (argslen != paramlen) return NULL; /* error */

  create_empty_environment(&new_env);
  extend(func->lexical_env, new_env, func->param_list, args);

  code = func->code;
  hc = handle_push(code);
  while (NULL != code && !NILP(code)) {
    ret = evaluate(CAR(code), new_env); // code handled

    code = handle_get(hc);
    code = CDR(code);
    handle_set(hc, code);
  }
  handle_pop(hc);

  return ret;
}
Ejemplo n.º 3
0
cell_t *evargs(cell_t *args, environ_t *env) {
#define MAX_LISP_ARGS 16
  handle_t *harray[MAX_LISP_ARGS];
  int length;
  int i;
  cell_t *tmp, *head = nil_cell, *tail = nil_cell;
  handle_t *hhandle, *thandle;

  if ((length = proper_list_length(args, 0)) < 0) return NULL; /* error */
  if (length > MAX_LISP_ARGS) return NULL; /* can only handle 16 args atm */

  for (i = 0; i < length; i++, args = CDR(args)) {
    harray[i] = handle_push(CAR(args));
  }
  for (i = 0; i < length; i++) {
    cell_t *t = handle_get(harray[i]);
    handle_set(harray[i], evaluate(t, env)); // everything handled
  }

  hhandle = handle_push(head);
  thandle = handle_push(tail);
  for (i = length - 1; i >= 0; i--) {
    tmp = new(cell_t); // head and tail protected by handles
    head = handle_get(hhandle);
    tail = handle_get(thandle);

    tail = head;
    head = handle_get(harray[i]);
    CONS(tmp, head, tail);
    head = tmp;

    handle_set(hhandle, head);
    handle_set(thandle, tail);
  }
  handle_pop(thandle);
  handle_pop(hhandle);

  for (i = length - 1; i >= 0; i--) {
    handle_pop(harray[i]);
  }

  return head;
}
Ejemplo n.º 4
0
void handle_msi_packet(Messenger *m, uint32_t friend_number, const uint8_t *data, uint16_t length, void *object)
{
    LOGGER_DEBUG(m->log, "Got msi message");

    MSISession *session = (MSISession *)object;
    MSIMessage msg;

    if (msg_parse_in(m->log, &msg, data, length) == -1) {
        LOGGER_WARNING(m->log, "Error parsing message");
        send_error(m, friend_number, msi_EInvalidMessage);
        return;
    }

    LOGGER_DEBUG(m->log, "Successfully parsed message");

    pthread_mutex_lock(session->mutex);
    MSICall *call = get_call(session, friend_number);

    if (call == NULL) {
        if (msg.request.value != requ_init) {
            send_error(m, friend_number, msi_EStrayMessage);
            pthread_mutex_unlock(session->mutex);
            return;
        }

        call = new_call(session, friend_number);

        if (call == NULL) {
            send_error(m, friend_number, msi_ESystem);
            pthread_mutex_unlock(session->mutex);
            return;
        }
    }

    switch (msg.request.value) {
        case requ_init:
            handle_init(call, &msg);
            break;

        case requ_push:
            handle_push(call, &msg);
            break;

        case requ_pop:
            handle_pop(call, &msg); /* always kills the call */
            break;
    }

    pthread_mutex_unlock(session->mutex);
}
Ejemplo n.º 5
0
int Fl_Dial::handle(int event)
{
    int X = 0; int Y = 0; int W = w(); int H = h();
    box()->inset(X,Y,W,H);
    switch (event)
    {
        case FL_PUSH:
            handle_push();
        case FL_DRAG:
        {
            int mx = Fl::event_x()-X-W/2;
            int my = Fl::event_y()-Y-H/2;
            if (!mx && !my) return 1;
            double angle = 270-atan2((float)-my, (float)mx)*180/M_PI;
            double oldangle = (a2-a1)*(value()-minimum())/(maximum()-minimum()) + a1;
            while (angle < oldangle-180) angle += 360;
            while (angle > oldangle+180) angle -= 360;
            double val;
            if ((a1<a2) ? (angle <= a1) : (angle >= a1))
            {
                val = minimum();
            }
            else if ((a1<a2) ? (angle >= a2) : (angle <= a2))
            {
                val = maximum();
            }
            else
            {
                val = minimum() + (maximum()-minimum())*(angle-a1)/(a2-a1);
            }
            handle_drag(val);
        } return 1;
        case FL_RELEASE:
            if (!Fl::pushed()) handle_release();
            return 1;
        default:
            return Fl_Valuator::handle(event);
    }
}
Ejemplo n.º 6
0
int Fl_Roller::handle(int event)
{
    static int ipos;
    int newpos = type()==HORIZONTAL ? Fl::event_x() : -Fl::event_y();
    switch (event)
    {
        case FL_PUSH:
            handle_push();
            ipos = newpos;
            return 1;
        case FL_DRAG:
            handle_drag(previous_value()+(newpos-ipos)*(step()?step():.01));
            return 1;
        case FL_RELEASE:
            handle_release();
            return 1;
        case FL_KEY:
            // Only arrows in the correct direction are used.  This allows the
            // opposite arrows to be used to navigate between a set of parellel
            // rollers.
            switch (Fl::event_key())
            {
                case FL_Up:
                case FL_Down:
                case FL_Home:
                case FL_End:
                    if (type()==HORIZONTAL) return 0;
                    break;
                case FL_Left:
                case FL_Right:
                    if (type() != HORIZONTAL) return 0;
            }                    // else fall through...
        default:
            return Fl_Valuator::handle(event);
    }
}
Ejemplo n.º 7
0
static void handle_message(struct cfw_message * msg, void * param)
{
    switch (CFW_MESSAGE_ID(msg)) {
    case MSG_ID_LL_ERASE_BLOCK_REQ:
        handle_erase_block(msg);
        break;
    case MSG_ID_LL_READ_PARTITION_REQ:
        handle_read_partition(msg);
        break;
    case MSG_ID_LL_WRITE_PARTITION_REQ:
        handle_write_partition(msg);
        break;
#ifdef CONFIG_SERVICES_QUARK_SE_STORAGE_CIRCULAR
    case MSG_ID_LL_CIR_STOR_INIT_REQ:
        handle_cir_stor_init(msg);
        break;
    case MSG_ID_LL_PUSH_REQ:
        handle_push(msg);
        break;
    case MSG_ID_LL_POP_REQ:
        handle_pop(msg);
        break;
    case MSG_ID_LL_PEEK_REQ:
        handle_peek(msg);
        break;
    case MSG_ID_LL_CLEAR_REQ:
        handle_clear(msg);
        break;
#endif
    default:
        cfw_print_default_handle_error_msg(LOG_MODULE_MAIN, CFW_MESSAGE_ID(msg));
        break;
    }

    cfw_msg_free(msg);
}
Ejemplo n.º 8
0
cell_t *evaluate(cell_t *exp, environ_t *env) {
  ++__tl_eval_level;

  // push a frame
  eval_stack_t s;
  s.next = eval_stack;
  s.value = env;
  eval_stack = &s;

  if (DFLAG) {
    printf("Eval (%d) got : ", __tl_eval_level);
    pretty_print(exp);
  }

  if (NULL == exp) {
    DRETURN(RET_VAL, NULL);
  } else if (NILP(exp)) {
    DRETURN(RET_VAL, nil_cell);
  } else if (ATOMP(exp)) {
    if (SYMBOLP(exp)) {
      DRETURN(RET_VAL, find_value(env, exp));
    } else if (STRINGP(exp) || NUMBERP(exp)) {
      DRETURN(RET_VAL, exp);
    } else {
      DEBUGPRINT_("Expression not valid.\n");
      pretty_print(orig_sexpr);
      GOTO_TOPLEVEL();
      return NULL; /* unreachable */
    }
  } else { /* list */
    handle_t *he = handle_push(exp);
    cell_t *first = evaluate(CAR(exp), env); // exp handled
    exp = handle_get(he);
    handle_pop(he);
    cell_t *rest = CDR(exp);

    if (DFLAG) {
      printf("First is: ");
      pretty_print(first);
      printf("Rest is: ");
      pretty_print(rest);
    }

    if (NULL == first) {
      fast_error(" malformed expression.");
      /* This is unreachable */
    } else if (PRIMITIVEP(first)) {
      cell_t *(*f)(cell_t *, environ_t *) = CELL_PRIMITIVE(first);
      DRETURN(RET_PRIM, (*f)(rest, env));
    } else if (FUNCTIONP(first)) { /* function call */
      cell_t *t;
      handle_t *hf;

      hf = handle_push(first);
      t = evargs(rest, env); // first handled
      first = handle_get(hf);
      handle_pop(hf);

      DRETURN(RET_FUNCALL, invoke(first, t, env)); // no need for handles
    }
    undefun_error(first, exp); /* Not primitive or funcall, error.*/
    return NULL; /* Unreachable, undefun_error() does not return. */
  }
}
Ejemplo n.º 9
0
int Flu_Spinner::handle(int event)
{
  int W = w()*15/100;
  if( W < h()/2 )
    W = h()/2;
  int X = x()+w()-W, Y = y();

  if( (align() & FL_ALIGN_INSIDE) || !_editable )
    {
      _input.readonly( true );
      _input.cursor_color( FL_WHITE );
    }
  else
    {
      _input.readonly( false );
      _input.cursor_color( FL_BLACK );
    }

  switch( event )
    {
    case FL_PUSH:
      _dragging = true;
      if (Fl::visible_focus() && handle(FL_FOCUS)) Fl::focus(this);
      _lastValue = value();
      _lastY = Fl::event_y();
      Fl::remove_timeout( repeat_callback, this );
      if( Fl::event_inside( X, Y, W, h()/2 ) ) // up button
	{
	  _pushed = true;
	  _valbox[0] = FL_DOWN_BOX;
	  _up = true;
	}
      if( Fl::event_inside( X, Y+h()/2, W, h()/2 ) ) // down button
	{
	  _pushed = true;
	  _valbox[1] = FL_DOWN_BOX;
	  _up = false;
	}
      if( _pushed )
	{
	  increment_cb();
	  _totalTime = _initialDelay;
	  if( _doRepeat )
	    Fl::add_timeout( _initialDelay, repeat_callback, this);
	  handle_push();
	  take_focus();
	  redraw();
	  return 1;
	}
      break;

    case FL_DRAG:
      {
	// only do the dragging if the last Y differs from the current Y by more than 3 pixels
	if( ABS(_lastY-Fl::event_y()) < 3 )
	  break;
	_dragging = true;
	_pushed = false;
	Fl::remove_timeout( repeat_callback, this );
	int oldWhen = when();
	_setvalue(increment(_lastValue,(_lastY-Fl::event_y())*(Fl::event_state(FL_SHIFT|FL_CTRL|FL_ALT)?10:1)));
	_valbox[0] = _valbox[1] = FL_DOWN_BOX;
	when( oldWhen );
	fl_cursor((Fl_Cursor)22);
	_input.redraw();
	redraw();
      }
      break;

    case FL_RELEASE:
      {
	bool doCB = ( ( when() & FL_WHEN_RELEASE ) || ( when() & FL_WHEN_RELEASE_ALWAYS ) ) &&
	  ( _pushed || ( _valbox[0] == FL_DOWN_BOX ^ _valbox[1] == FL_DOWN_BOX ) );
	_pushed = false;
	_dragging = false;
	Fl::remove_timeout( repeat_callback, this );
	_valbox[0] = _valbox[1] = FL_UP_BOX;
	fl_cursor(FL_CURSOR_DEFAULT);
	redraw();
	handle_release();
	if( doCB )
	  do_callback();
	_input.take_focus();
      }
      break;

    case FL_FOCUS:
    case FL_UNFOCUS:
      redraw();
      _input.take_focus();
      return 0;

    case FL_ENTER:
      if( Fl::event_inside( &_input ) )
	return _input.handle(event);
      else if( active_r() )
	{
	  fl_cursor(FL_CURSOR_DEFAULT);
	  return 1;
	}
      break;

    case FL_LEAVE:
      if( Fl::event_inside( &_input ) )
	return _input.handle(event);
      else if( active_r() )
	{
	  fl_cursor(FL_CURSOR_DEFAULT);
	  return 1;
	}
      break;

    case FL_KEYBOARD:
      switch( Fl::event_key() )
	{
	case FL_Down:
	  {
	    int oldWhen = when(); when( FL_WHEN_CHANGED );
	    _setvalue(increment(value(),-1*(Fl::event_state(FL_SHIFT|FL_CTRL|FL_ALT)?10:1)));
	    when( oldWhen );
	    redraw();
	    return 1;
	  }
	case FL_Up:
	  {
	    int oldWhen = when(); when( FL_WHEN_CHANGED );
	    _setvalue(increment(value(),1*(Fl::event_state(FL_SHIFT|FL_CTRL|FL_ALT)?10:1)));
	    when( oldWhen );
	    redraw();
	    return 1;
	  }
	}
      break;
    }

  return _input.handle(event);
}
Ejemplo n.º 10
0
int Fl_Slider::handle(int event, int x, int y, int w, int h)
{

    switch (event)
    {
        case FL_FOCUS:
        case FL_UNFOCUS:
            redraw(FL_DAMAGE_ALL);
            return 1;
        case FL_PUSH:
            redraw(FL_DAMAGE_HIGHLIGHT);
            handle_push();
        case FL_DRAG:
            {
            // figure out the space the slider moves in and where the event is:
                int mx;
                if (horizontal())
                {
                    w = w-box()->dw();
                    mx = Fl::event_x()-x-box()->dx();
                }
                else
                {
                    w = h-box()->dh();
                    mx = Fl::event_y()-y-box()->dy();
                }
                if (w <= slider_size_) return 1;
                static int offcenter;
                int X = slider_position(value(), w);
                if (event == FL_PUSH)
                {
                    offcenter = mx-X;
                // we are done if they clicked on the slider:
                    if (offcenter >= (slider_size() ? 0 : -8) && offcenter <= slider_size_)
                        return 1;
                    if (Fl::event_button() > 1)
                    {
                    // Move the near end of the slider to the cursor. This is good
                    // for scrollbars.
                        offcenter = (offcenter < 0) ? 0 : slider_size_;
                    }
                    else
                    {
                    // Center the slider under the cursor, what most toolkits do
                        offcenter = slider_size_/2;
                    }
                }
                double v;
            RETRY:
                X = mx-offcenter;
                if (X < 0)
                {
                    X = 0;
                    offcenter = mx; if (offcenter < 0) offcenter = 0;
                }
                else if (X > (w-slider_size_))
                {
                    X = w-slider_size_;
                    offcenter = mx-X; if (offcenter > slider_size_) offcenter = slider_size_;
                }
                v = position_value(X, w);
                handle_drag(v);
            // make sure a click outside the sliderbar moves it:
                if (event == FL_PUSH && value() == previous_value())
                {
                    offcenter = slider_size_/2;
                    event = FL_DRAG;
                    goto RETRY;
                }
                return 1;
            }
        case FL_RELEASE:
            handle_release();
            redraw(FL_DAMAGE_HIGHLIGHT);
            return 1;
        case FL_KEY:
            // Only arrows in the correct direction are used.  This allows the
            // opposite arrows to be used to navigate between a set of parellel
            // sliders.
            switch (Fl::event_key())
            {
                case FL_Up:
                case FL_Down:
                    if (horizontal()) return 0;
                    break;
                case FL_Left:
                case FL_Right:
                    if (!horizontal()) return 0;
            }
        default:
            return Fl_Valuator::handle(event);
    }
}
Ejemplo n.º 11
0
int Fl_Scrollbar::handle(int event)
{
    // area of scrollbar:
    int X=0; int Y=0; int W=w(); int H=h(); box()->inset(X,Y,W,H);

    // adjust slider area to be inside the arrow buttons:
    if (vertical())
    {
        if (H >= 3*W) {Y += W; H -= 2*W;}
    }
    else
    {
        if (W >= 3*H) {X += H; W -= 2*H;}
    }

    // which widget part is highlighted?
    int mx = Fl::event_x();
    int my = Fl::event_y();
    int which_part;
    if (!Fl::event_inside(0, 0, w(), h())) which_part = NOTHING;
    else if (vertical())
    {
        if (my < Y) which_part = UP_ARROW;
        else if (my >= Y+H) which_part = DOWN_ARROW;
        else
        {
            int slidery = slider_position(value(), H);
            if (my < Y+slidery) which_part = ABOVE_SLIDER;
            else if (my >= Y+slidery+slider_size()) which_part = BELOW_SLIDER;
            else which_part = SLIDER;
        }
    }                            // horizontal
    else
    {
        if (mx < X) which_part = UP_ARROW;
        else if (mx >= X+W) which_part = DOWN_ARROW;
        else
        {
            int sliderx = slider_position(value(), W);
            if (mx < X+sliderx) which_part = ABOVE_SLIDER;
            else if (mx >= X+sliderx+slider_size()) which_part = BELOW_SLIDER;
            else which_part = SLIDER;
        }
    }
    switch (event)
    {
        case FL_FOCUS:
            return 0;
        case FL_ENTER:
        case FL_MOVE:
            if (!highlight_color()) return 1;
            if (which_part != which_highlight)
            {
                which_highlight = which_part;
                redraw(FL_DAMAGE_HIGHLIGHT);
            }
            return 1;
        case FL_LEAVE:
            if (which_highlight)
            {
                which_highlight = 0;
                redraw(FL_DAMAGE_HIGHLIGHT);
            }
            return 1;
        case FL_PUSH:
            // Clicking on the slider or middle or right click on the trough
            // gives us normal slider behavior:
            if (which_part == SLIDER ||
                Fl::event_button() > 1 && which_part > DOWN_ARROW)
            {
                which_pushed = SLIDER;
                return Fl_Slider::handle(event, X,Y,W,H);
            }
            handle_push();
            goto J1;
        case FL_DRAG:
            if (which_pushed==SLIDER) return Fl_Slider::handle(event, X,Y,W,H);
            if (which_part == SLIDER) which_part = NOTHING;
            // it is okay to switch between arrows and nothing, but no other
            // changes are allowed:
            if (!which_pushed && which_part <= DOWN_ARROW) ;
            else if (!which_part && which_pushed <= DOWN_ARROW) ;
            else which_part = which_pushed;
            J1:
            if (which_part != which_pushed)
            {
                Fl::remove_timeout(timeout_cb, this);
                which_highlight = which_pushed = which_part;
                redraw(FL_DAMAGE_HIGHLIGHT);
                if (which_part)
                {
                    Fl::add_timeout(INITIALREPEAT, timeout_cb, this);
                    increment_cb();
                }
            }
            return 1;
        case FL_RELEASE:
            if (which_pushed == SLIDER)
            {
                Fl_Slider::handle(event, X,Y,W,H);
            }
            else if (which_pushed)
            {
                Fl::remove_timeout(timeout_cb, this);
                handle_release();
                redraw(FL_DAMAGE_HIGHLIGHT);
            }
            which_pushed = NOTHING;
            return 1;
        case FL_MOUSEWHEEL:
            {
                float n = (vertical() ? Fl::event_dy() : Fl::event_dx())
                    * Fl_Style::wheel_scroll_lines * linesize();
                if (fabsf(n) > pagesize()) n = (n<0)?-pagesize():pagesize();
                handle_drag(value()+n);
                return 1;
            }
        case FL_KEY:
            if (vertical()) switch(Fl::event_key())
            {
                case FL_Home: handle_drag(maximum()); return 1;
                case FL_End:  handle_drag(minimum()); return 1;
                case FL_Page_Up: handle_drag(value()-pagesize()); return 1;
                case FL_Page_Down: handle_drag(value()+pagesize()); return 1;
            }                    // else fall through...
        default:
            return Fl_Slider::handle(event);
    }
}
Ejemplo n.º 12
0
int Fl_Value_Input_Spin::handle(int event) {
  double v;
  int olddelta;
  int mx = Fl::event_x();
  int my = Fl::event_y();
  int sxx = x(), syy = y(), sww = w(), shh = h();
  sxx += sww - buttonssize(); sww = buttonssize();
 
  if(!indrag && ( !sldrag || !((mx>=sxx && mx<=(sxx+sww)) &&
       (my>=syy && my<=(syy+shh))))  ) {  
          indrag=0;     
	  switch(event) {
            case FL_PUSH:
            case FL_DRAG:
	      sldrag=1;
	      break;
            case FL_FOCUS:
	       input.take_focus();
	       break;
           case FL_UNFOCUS:
	       redraw();
	       break;
	    default:
	      sldrag=0;
	  }
          input.type(step()>=1.0 ? FL_INT_INPUT : FL_FLOAT_INPUT);
          return input.handle(event);
  }

  switch (event) {
  case FL_PUSH:
//    if (!step()) goto DEFAULT;
    iy = my;
    ix = mx;
    drag = Fl::event_button();
    handle_push();
    indrag=1;
    mouseobj=1;
    Fl::add_timeout(.5, repeat_callback, this);  
    delta=0;
    if(Fl::event_inside(sxx,syy,sww,shh/2)) {
     deltadir=1;
    } else if (Fl::event_inside(sxx,syy+shh/2,sww,shh/2)) {
     deltadir=-1;
    } else {
     deltadir=0;
    }
    increment_cb();
    redraw();
    return 1;
  case FL_DRAG:
    if(mouseobj) {
      mouseobj=0;
      Fl::remove_timeout(repeat_callback, this);      
    }
//    if (!step()) goto DEFAULT;
    olddelta=delta;
    delta = - (Fl::event_y()-iy);
    if ((delta>5) || (delta<-5)  ) {  deltadir=((olddelta-delta)>0)?-1:(((olddelta-delta)<0)?1:0); } 
    else  { deltadir=0; delta = olddelta;}
    switch (drag) {
    case 3: v = increment(value(), deltadir*100); break;
    case 2: v = increment(value(), deltadir*10); break;
    default:v = increment(value(), deltadir); break;
    }
    v = round(v);
    handle_drag(soft()?softclamp(v):clamp(v));
    indrag=1;
    return 1;
  case FL_RELEASE:
    if(mouseobj) {
      Fl::remove_timeout(repeat_callback, this);      
    }
//    if (!step()) goto DEFAULT;
    indrag=0;
    delta=0;
    deltadir=0;
    mouseobj=0;
    handle_release();
    redraw();
    return 1;
  case FL_FOCUS:
    indrag=0;
    return input.take_focus();
  default:
    indrag=0;
    input.type(step()>=1.0 ? FL_INT_INPUT : FL_FLOAT_INPUT);
    return 1;
  }
}
Ejemplo n.º 13
0
int
main(int argc, char *argv[])
{
  const char *filename;
  bool skip_hs = false;
  bool with_dump_headers = false;
  int fd, c;

  setvbuf(stdout, NULL, _IOLBF, 0);
  
  while (-1 != (c = getopt(argc, argv, "DHh"))) {
    switch (c) {
    case 'h':
      usage(EXIT_SUCCESS);
      break;

    case 'H':
      skip_hs = true;
      break;
     
    case 'D':
      with_dump_headers = true;
      break;
     
    default:
      fprintf(stderr, "Unsupported option: -- %c\n", c);
      usage(EXIT_FAILURE);
    }
  }
  argc -= optind;
  argv += optind;

  if (argc > 1) {
    fprintf(stderr,
      "Error: "
      "Specify exactly one filename or none to read from the standard input."
      "\n");
    usage(EXIT_FAILURE);
  }

  filename = argv[0];
  if (filename) {
    fd = open(filename, O_RDONLY, 0);
    if (fd < 0) {
      fprintf(stderr, "open(\"%s\", O_RDONLY, 0) failed: %s\n",
        filename, strerror(errno));
      exit(EXIT_FAILURE);
    }
  } else {
    fd = STDIN_FILENO;
  }

  /* Discard the handshake */
  if (skip_hs) {
    if (0 != skip_handshake(fd)) {
      fprintf(stderr, "Failed to skip handshake\n");
      exit(EXIT_FAILURE);
    }
    printf("Skipped handshake\n");
  }
 
  for (;;) {
    struct gnutella_header header;
    static char *payload;
    size_t ret;
    uint32_t payload_size;
    
    STATIC_ASSERT(23 == sizeof header);

    if (!payload) {
      payload = malloc(GNUTELLA_MAX_PAYLOAD);
      if (!payload) {
        fprintf(stderr, "malloc(%lu) failed: %s",
            (unsigned long) GNUTELLA_MAX_PAYLOAD, strerror(errno));
        return -1;
      }
    }

    if (with_dump_headers) {
      struct dump_header dh;
      safe_read(fd, &dh, sizeof dh);

      if (dh.flags & DH_F_TO) {
        struct dump_header dh_from;
        safe_read(fd, &dh_from, sizeof dh_from);
        print_dump_from_header(&dh_from);
        print_dump_to_header(&dh);
      } else {
        print_dump_from_header(&dh);
      }
    }

    ret = fill_buffer_from_fd(fd, &header, sizeof header);
    switch (ret) {
    case 0:
      fprintf(stderr, "Error: Unexpected end of file.\n");
      exit(EXIT_FAILURE);
    case (size_t) -1:
      fprintf(stderr, "Error: Could not fill packet buffer: %s\n",
          strerror(errno));
      exit(EXIT_FAILURE);
    case 1:
      break;
    default:
      RUNTIME_ASSERT(0);
    }

    payload_size = peek_le32(header.size);

    if (payload_size > GNUTELLA_MAX_PAYLOAD) {
      fprintf(stderr, "Error: Message is too large.\n");
      return -1;
    }

    if (payload_size > 0) {
      ret = fill_buffer_from_fd(fd, payload, payload_size);
      switch (ret) {
        case 0:
        case (size_t) -1:
          exit(EXIT_FAILURE);
        case 1:
          break;
        default:
          RUNTIME_ASSERT(0);
      }
    }

    printf("GUID: %08lx-%08lx-%08lx-%08lx\n",
        (unsigned long) peek_be32(&header.guid.data[0]),
        (unsigned long) peek_be32(&header.guid.data[4]),
        (unsigned long) peek_be32(&header.guid.data[8]),
        (unsigned long) peek_be32(&header.guid.data[12]));

    if (header.type != GPT_DHT) {
      printf("Type: %s\n", packet_type_to_string(header.type));
      printf("TTL : %u\n", (unsigned char) header.ttl);
      printf("Hops: %u\n", (unsigned char) header.hops);
      printf("Size: %lu\n", (unsigned long) payload_size);
    } else {
      printf("Type: %s\n", kademlia_type_to_string(header.type));
      printf("V   : %u.%u\n",
          (unsigned char) header.ttl, (unsigned char) header.hops);
      printf("Size: %lu\n", (unsigned long) payload_size + 23 - 61);
    }

    printf("--\n");
   
    switch ((enum gnutella_packet_type) header.type) {
    case GPT_PING:      handle_ping(payload, payload_size); break;
    case GPT_PONG:      handle_pong(payload, payload_size); break;
    case GPT_QRP:       handle_qrp(payload, payload_size); break;
    case GPT_VMSG_PRIV: handle_vmsg_priv(&header, payload, payload_size); break;
    case GPT_VMSG_STD:  handle_vmsg_std(payload, payload_size); break;
    case GPT_PUSH:      handle_push(payload, payload_size); break;
    case GPT_RUDP:      handle_rudp(payload, payload_size); break;
    case GPT_DHT:       handle_dht(payload, payload_size); break;
    case GPT_QUERY:     handle_query(&header, payload, payload_size); break;
    case GPT_QHIT:      handle_qhit(payload, payload_size); break;
    case GPT_HSEP:      handle_hsep(payload, payload_size); break;
    }
    printf("==========\n");

  }

  return 0;
}
Ejemplo n.º 14
0
bool Cache::push_local(const std::string& key, uint32_t node_id) {
   return handle_push(key, node_id, PUSH_LOCAL);
}
Ejemplo n.º 15
0
int Fl_Spin::handle(int event) {
  double v;
  int olddelta;
  int mx = Fl::event_x();
  int my = Fl::event_y();
  int sxx = x(), syy = y(), sww = w(), shh = h();
 
  switch (event) {
  case FL_PUSH:
//    if (!step()) goto DEFAULT;
    iy = my;
    ix = mx;
    drag = Fl::event_button();
    handle_push();
    indrag=1;
    mouseobj=1;
    Fl::add_timeout(.5, repeat_callback, this);  
    delta=0;
    if(Fl::event_inside(sxx,syy,sww,shh/2)) {
     deltadir=1;
    } else if (Fl::event_inside(sxx,syy+shh/2,sww,shh/2)) {
     deltadir=-1;
    } else {
     deltadir=0;
    }
    increment_cb();
    redraw();
    return 1;
  case FL_DRAG:
    if(mouseobj) {
      mouseobj=0;
      Fl::remove_timeout(repeat_callback, this);      
    }
//    if (!step()) goto DEFAULT;
    olddelta=delta;
    delta = - (Fl::event_y()-iy);
    if ((delta>5) || (delta<-5)  ) {  deltadir=((olddelta-delta)>0)?-1:(((olddelta-delta)<0)?1:0); } 
    else  { deltadir=0; delta = olddelta;}
    switch (drag) {
    case 3: v = increment(value(), deltadir*100); break;
    case 2: v = increment(value(), deltadir*10); break;
    default:v = increment(value(), deltadir); break;
    }
    v = round(v);
    handle_drag(soft()?softclamp(v):clamp(v));
    indrag=1;
    return 1;
  case FL_RELEASE:
    if(mouseobj) {
      Fl::remove_timeout(repeat_callback, this);      
    }
//    if (!step()) goto DEFAULT;
    indrag=0;
    delta=0;
    deltadir=0;
    mouseobj=0;
    handle_release();
    redraw();
    return 1;
  default:
    indrag=0;
    return Fl_Valuator::handle(event);
  }
}