Exemplo n.º 1
0
int
run_unmarshal(struct run *tmp,  struct evbuffer *evbuf)
{
  ev_uint32_t tag;
  while (EVBUFFER_LENGTH(evbuf) > 0) {
    if (evtag_peek(evbuf, &tag) == -1)
      return (-1);
    switch (tag) {

      case RUN_HOW:

        if (tmp->how_set)
          return (-1);
        if (evtag_unmarshal_string(evbuf, RUN_HOW, &tmp->how_data) == -1) {
          event_warnx("%s: failed to unmarshal how", __func__);
          return (-1);
        }
        tmp->how_set = 1;
        break;

      case RUN_SOME_BYTES:

        if (tmp->some_bytes_set)
          return (-1);
        if (evtag_payload_length(evbuf, &tmp->some_bytes_length) == -1)
          return (-1);
        if (tmp->some_bytes_length > EVBUFFER_LENGTH(evbuf))
          return (-1);
        if ((tmp->some_bytes_data = malloc(tmp->some_bytes_length)) == NULL)
          return (-1);
        if (evtag_unmarshal_fixed(evbuf, RUN_SOME_BYTES, tmp->some_bytes_data, tmp->some_bytes_length) == -1) {
          event_warnx("%s: failed to unmarshal some_bytes", __func__);
          return (-1);
        }
        tmp->some_bytes_set = 1;
        break;

      case RUN_FIXED_BYTES:

        if (tmp->fixed_bytes_set)
          return (-1);
        if (evtag_unmarshal_fixed(evbuf, RUN_FIXED_BYTES, tmp->fixed_bytes_data, sizeof(tmp->fixed_bytes_data)) == -1) {
          event_warnx("%s: failed to unmarshal fixed_bytes", __func__);
          return (-1);
        }
        tmp->fixed_bytes_set = 1;
        break;

      default:
        return -1;
    }
  }

  if (run_complete(tmp) == -1)
    return (-1);
  return (0);
}
Exemplo n.º 2
0
int
msg_complete(struct msg *msg)
{
  if (!msg->from_name_set)
    return (-1);
  if (!msg->to_name_set)
    return (-1);
  if (msg->attack_set && kill_complete(msg->attack_data) == -1)
    return (-1);
  {
    int i;
    for (i = 0; i < msg->run_length; ++i) {
      if (msg->run_set && run_complete(msg->run_data[i]) == -1)
        return (-1);
    }
  }
  return (0);
}
Exemplo n.º 3
0
int
run_unmarshal(struct run *tmp,  struct evbuffer *evbuf)
{
  ev_uint32_t tag;
  while (evbuffer_get_length(evbuf) > 0) {
    if (evtag_peek(evbuf, &tag) == -1)
      return (-1);
    switch (tag) {

      case RUN_HOW:

        if (tmp->how_set)
          return (-1);
        if (evtag_unmarshal_string(evbuf, RUN_HOW, &tmp->how_data) == -1) {
          event_warnx("%s: failed to unmarshal how", __func__);
          return (-1);
        }
        tmp->how_set = 1;
        break;

      case RUN_SOME_BYTES:

        if (tmp->some_bytes_set)
          return (-1);
        if (evtag_payload_length(evbuf, &tmp->some_bytes_length) == -1)
          return (-1);
        if (tmp->some_bytes_length > evbuffer_get_length(evbuf))
          return (-1);
        if ((tmp->some_bytes_data = malloc(tmp->some_bytes_length)) == NULL)
          return (-1);
        if (evtag_unmarshal_fixed(evbuf, RUN_SOME_BYTES, tmp->some_bytes_data, tmp->some_bytes_length) == -1) {
          event_warnx("%s: failed to unmarshal some_bytes", __func__);
          return (-1);
        }
        tmp->some_bytes_set = 1;
        break;

      case RUN_FIXED_BYTES:

        if (tmp->fixed_bytes_set)
          return (-1);
        if (evtag_unmarshal_fixed(evbuf, RUN_FIXED_BYTES, tmp->fixed_bytes_data, (24)) == -1) {
          event_warnx("%s: failed to unmarshal fixed_bytes", __func__);
          return (-1);
        }
        tmp->fixed_bytes_set = 1;
        break;

      case RUN_NOTES:

        if (tmp->notes_length >= tmp->notes_num_allocated &&
            run_notes_expand_to_hold_more(tmp) < 0) {
          puts("HEY NOW");
          return (-1);
        }
        if (evtag_unmarshal_string(evbuf, RUN_NOTES, &tmp->notes_data[tmp->notes_length]) == -1) {
          event_warnx("%s: failed to unmarshal notes", __func__);
          return (-1);
        }
        ++tmp->notes_length;
        tmp->notes_set = 1;
        break;

      case RUN_LARGE_NUMBER:

        if (tmp->large_number_set)
          return (-1);
        if (evtag_unmarshal_int64(evbuf, RUN_LARGE_NUMBER, &tmp->large_number_data) == -1) {
          event_warnx("%s: failed to unmarshal large_number", __func__);
          return (-1);
        }
        tmp->large_number_set = 1;
        break;

      case RUN_OTHER_NUMBERS:

        if (tmp->other_numbers_length >= tmp->other_numbers_num_allocated &&
            run_other_numbers_expand_to_hold_more(tmp) < 0) {
          puts("HEY NOW");
          return (-1);
        }
        if (evtag_unmarshal_int(evbuf, RUN_OTHER_NUMBERS, &tmp->other_numbers_data[tmp->other_numbers_length]) == -1) {
          event_warnx("%s: failed to unmarshal other_numbers", __func__);
          return (-1);
        }
        ++tmp->other_numbers_length;
        tmp->other_numbers_set = 1;
        break;

      default:
        return -1;
    }
  }

  if (run_complete(tmp) == -1)
    return (-1);
  return (0);
}