ipc/chromium/src/third_party/libevent/test/regress.gen.c

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/ipc/chromium/src/third_party/libevent/test/regress.gen.c	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,1225 @@
     1.4 +/*
     1.5 + * Automatically generated from ./regress.rpc
     1.6 + * by event_rpcgen.py/0.1.  DO NOT EDIT THIS FILE.
     1.7 + */
     1.8 +
     1.9 +#include <stdlib.h>
    1.10 +#include <string.h>
    1.11 +#include <assert.h>
    1.12 +#include <event2/event-config.h>
    1.13 +#include <event2/event.h>
    1.14 +#include <event2/buffer.h>
    1.15 +#include <event2/tag.h>
    1.16 +
    1.17 +#ifdef _EVENT___func__
    1.18 +#define __func__ _EVENT___func__
    1.19 +#endif
    1.20 +
    1.21 +
    1.22 +#include "regress.gen.h"
    1.23 +
    1.24 +void event_warn(const char *fmt, ...);
    1.25 +void event_warnx(const char *fmt, ...);
    1.26 +
    1.27 +
    1.28 +/*
    1.29 + * Implementation of msg
    1.30 + */
    1.31 +
    1.32 +static struct msg_access_ __msg_base = {
    1.33 +  msg_from_name_assign,
    1.34 +  msg_from_name_get,
    1.35 +  msg_to_name_assign,
    1.36 +  msg_to_name_get,
    1.37 +  msg_attack_assign,
    1.38 +  msg_attack_get,
    1.39 +  msg_run_assign,
    1.40 +  msg_run_get,
    1.41 +  msg_run_add,
    1.42 +};
    1.43 +
    1.44 +struct msg *
    1.45 +msg_new(void)
    1.46 +{
    1.47 +  return msg_new_with_arg(NULL);
    1.48 +}
    1.49 +
    1.50 +struct msg *
    1.51 +msg_new_with_arg(void *unused)
    1.52 +{
    1.53 +  struct msg *tmp;
    1.54 +  if ((tmp = malloc(sizeof(struct msg))) == NULL) {
    1.55 +    event_warn("%s: malloc", __func__);
    1.56 +    return (NULL);
    1.57 +  }
    1.58 +  tmp->base = &__msg_base;
    1.59 +
    1.60 +  tmp->from_name_data = NULL;
    1.61 +  tmp->from_name_set = 0;
    1.62 +
    1.63 +  tmp->to_name_data = NULL;
    1.64 +  tmp->to_name_set = 0;
    1.65 +
    1.66 +  tmp->attack_data = NULL;
    1.67 +  tmp->attack_set = 0;
    1.68 +
    1.69 +  tmp->run_data = NULL;
    1.70 +  tmp->run_length = 0;
    1.71 +  tmp->run_num_allocated = 0;
    1.72 +  tmp->run_set = 0;
    1.73 +
    1.74 +  return (tmp);
    1.75 +}
    1.76 +
    1.77 +
    1.78 +
    1.79 +
    1.80 +static int
    1.81 +msg_run_expand_to_hold_more(struct msg *msg)
    1.82 +{
    1.83 +  int tobe_allocated = msg->run_num_allocated;
    1.84 +  struct run** new_data = NULL;
    1.85 +  tobe_allocated = !tobe_allocated ? 1 : tobe_allocated << 1;
    1.86 +  new_data = (struct run**) realloc(msg->run_data,
    1.87 +      tobe_allocated * sizeof(struct run*));
    1.88 +  if (new_data == NULL)
    1.89 +    return -1;
    1.90 +  msg->run_data = new_data;
    1.91 +  msg->run_num_allocated = tobe_allocated;
    1.92 +  return 0;}
    1.93 +
    1.94 +struct run* 
    1.95 +msg_run_add(struct msg *msg)
    1.96 +{
    1.97 +  if (++msg->run_length >= msg->run_num_allocated) {
    1.98 +    if (msg_run_expand_to_hold_more(msg)<0)
    1.99 +      goto error;
   1.100 +  }
   1.101 +  msg->run_data[msg->run_length - 1] = run_new();
   1.102 +  if (msg->run_data[msg->run_length - 1] == NULL)
   1.103 +    goto error;
   1.104 +  msg->run_set = 1;
   1.105 +  return (msg->run_data[msg->run_length - 1]);
   1.106 +error:
   1.107 +  --msg->run_length;
   1.108 +  return (NULL);
   1.109 +}
   1.110 +
   1.111 +int
   1.112 +msg_from_name_assign(struct msg *msg,
   1.113 +    const char * value)
   1.114 +{
   1.115 +  if (msg->from_name_data != NULL)
   1.116 +    free(msg->from_name_data);
   1.117 +  if ((msg->from_name_data = strdup(value)) == NULL)
   1.118 +    return (-1);
   1.119 +  msg->from_name_set = 1;
   1.120 +  return (0);
   1.121 +}
   1.122 +
   1.123 +int
   1.124 +msg_to_name_assign(struct msg *msg,
   1.125 +    const char * value)
   1.126 +{
   1.127 +  if (msg->to_name_data != NULL)
   1.128 +    free(msg->to_name_data);
   1.129 +  if ((msg->to_name_data = strdup(value)) == NULL)
   1.130 +    return (-1);
   1.131 +  msg->to_name_set = 1;
   1.132 +  return (0);
   1.133 +}
   1.134 +
   1.135 +int
   1.136 +msg_attack_assign(struct msg *msg,
   1.137 +    const struct kill* value)
   1.138 +{
   1.139 +   struct evbuffer *tmp = NULL;
   1.140 +   if (msg->attack_set) {
   1.141 +     kill_clear(msg->attack_data);
   1.142 +     msg->attack_set = 0;
   1.143 +   } else {
   1.144 +     msg->attack_data = kill_new();
   1.145 +     if (msg->attack_data == NULL) {
   1.146 +       event_warn("%s: kill_new()", __func__);
   1.147 +       goto error;
   1.148 +     }
   1.149 +   }
   1.150 +   if ((tmp = evbuffer_new()) == NULL) {
   1.151 +     event_warn("%s: evbuffer_new()", __func__);
   1.152 +     goto error;
   1.153 +   }
   1.154 +   kill_marshal(tmp, value);
   1.155 +   if (kill_unmarshal(msg->attack_data, tmp) == -1) {
   1.156 +     event_warnx("%s: kill_unmarshal", __func__);
   1.157 +     goto error;
   1.158 +   }
   1.159 +   msg->attack_set = 1;
   1.160 +   evbuffer_free(tmp);
   1.161 +   return (0);
   1.162 + error:
   1.163 +   if (tmp != NULL)
   1.164 +     evbuffer_free(tmp);
   1.165 +   if (msg->attack_data != NULL) {
   1.166 +     kill_free(msg->attack_data);
   1.167 +     msg->attack_data = NULL;
   1.168 +   }
   1.169 +   return (-1);
   1.170 +}
   1.171 +
   1.172 +int
   1.173 +msg_run_assign(struct msg *msg, int off,
   1.174 +    const struct run* value)
   1.175 +{
   1.176 +  if (!msg->run_set || off < 0 || off >= msg->run_length)
   1.177 +    return (-1);
   1.178 +
   1.179 +  {
   1.180 +    int had_error = 0;
   1.181 +    struct evbuffer *tmp = NULL;
   1.182 +    run_clear(msg->run_data[off]);
   1.183 +    if ((tmp = evbuffer_new()) == NULL) {
   1.184 +      event_warn("%s: evbuffer_new()", __func__);
   1.185 +      had_error = 1;
   1.186 +      goto done;
   1.187 +    }
   1.188 +    run_marshal(tmp, value);
   1.189 +    if (run_unmarshal(msg->run_data[off], tmp) == -1) {
   1.190 +      event_warnx("%s: run_unmarshal", __func__);
   1.191 +      had_error = 1;
   1.192 +      goto done;
   1.193 +    }
   1.194 +    done:if (tmp != NULL)
   1.195 +      evbuffer_free(tmp);
   1.196 +    if (had_error) {
   1.197 +      run_clear(msg->run_data[off]);
   1.198 +      return (-1);
   1.199 +    }
   1.200 +  }
   1.201 +  return (0);
   1.202 +}
   1.203 +
   1.204 +int
   1.205 +msg_from_name_get(struct msg *msg, char * *value)
   1.206 +{
   1.207 +  if (msg->from_name_set != 1)
   1.208 +    return (-1);
   1.209 +  *value = msg->from_name_data;
   1.210 +  return (0);
   1.211 +}
   1.212 +
   1.213 +int
   1.214 +msg_to_name_get(struct msg *msg, char * *value)
   1.215 +{
   1.216 +  if (msg->to_name_set != 1)
   1.217 +    return (-1);
   1.218 +  *value = msg->to_name_data;
   1.219 +  return (0);
   1.220 +}
   1.221 +
   1.222 +int
   1.223 +msg_attack_get(struct msg *msg, struct kill* *value)
   1.224 +{
   1.225 +  if (msg->attack_set != 1) {
   1.226 +    msg->attack_data = kill_new();
   1.227 +    if (msg->attack_data == NULL)
   1.228 +      return (-1);
   1.229 +    msg->attack_set = 1;
   1.230 +  }
   1.231 +  *value = msg->attack_data;
   1.232 +  return (0);
   1.233 +}
   1.234 +
   1.235 +int
   1.236 +msg_run_get(struct msg *msg, int offset,
   1.237 +    struct run* *value)
   1.238 +{
   1.239 +  if (!msg->run_set || offset < 0 || offset >= msg->run_length)
   1.240 +    return (-1);
   1.241 +  *value = msg->run_data[offset];
   1.242 +  return (0);
   1.243 +}
   1.244 +
   1.245 +void
   1.246 +msg_clear(struct msg *tmp)
   1.247 +{
   1.248 +  if (tmp->from_name_set == 1) {
   1.249 +    free(tmp->from_name_data);
   1.250 +    tmp->from_name_data = NULL;
   1.251 +    tmp->from_name_set = 0;
   1.252 +  }
   1.253 +  if (tmp->to_name_set == 1) {
   1.254 +    free(tmp->to_name_data);
   1.255 +    tmp->to_name_data = NULL;
   1.256 +    tmp->to_name_set = 0;
   1.257 +  }
   1.258 +  if (tmp->attack_set == 1) {
   1.259 +    kill_free(tmp->attack_data);
   1.260 +    tmp->attack_data = NULL;
   1.261 +    tmp->attack_set = 0;
   1.262 +  }
   1.263 +  if (tmp->run_set == 1) {
   1.264 +    int i;
   1.265 +    for (i = 0; i < tmp->run_length; ++i) {
   1.266 +      run_free(tmp->run_data[i]);
   1.267 +    }
   1.268 +    free(tmp->run_data);
   1.269 +    tmp->run_data = NULL;
   1.270 +    tmp->run_set = 0;
   1.271 +    tmp->run_length = 0;
   1.272 +    tmp->run_num_allocated = 0;
   1.273 +  }
   1.274 +}
   1.275 +
   1.276 +void
   1.277 +msg_free(struct msg *tmp)
   1.278 +{
   1.279 +  if (tmp->from_name_data != NULL)
   1.280 +      free (tmp->from_name_data);
   1.281 +  if (tmp->to_name_data != NULL)
   1.282 +      free (tmp->to_name_data);
   1.283 +  if (tmp->attack_data != NULL)
   1.284 +      kill_free(tmp->attack_data);
   1.285 +  if (tmp->run_set == 1) {
   1.286 +    int i;
   1.287 +    for (i = 0; i < tmp->run_length; ++i) {
   1.288 +      run_free(tmp->run_data[i]);
   1.289 +    }
   1.290 +    free(tmp->run_data);
   1.291 +    tmp->run_data = NULL;
   1.292 +    tmp->run_set = 0;
   1.293 +    tmp->run_length = 0;
   1.294 +    tmp->run_num_allocated = 0;
   1.295 +  }
   1.296 +  free(tmp->run_data);
   1.297 +  free(tmp);
   1.298 +}
   1.299 +
   1.300 +void
   1.301 +msg_marshal(struct evbuffer *evbuf, const struct msg *tmp){
   1.302 +  evtag_marshal_string(evbuf, MSG_FROM_NAME, tmp->from_name_data);
   1.303 +  evtag_marshal_string(evbuf, MSG_TO_NAME, tmp->to_name_data);
   1.304 +  if (tmp->attack_set) {
   1.305 +    evtag_marshal_kill(evbuf, MSG_ATTACK, tmp->attack_data);
   1.306 +  }
   1.307 +  if (tmp->run_set) {
   1.308 +    {
   1.309 +      int i;
   1.310 +      for (i = 0; i < tmp->run_length; ++i) {
   1.311 +    evtag_marshal_run(evbuf, MSG_RUN, tmp->run_data[i]);
   1.312 +      }
   1.313 +    }
   1.314 +  }
   1.315 +}
   1.316 +
   1.317 +int
   1.318 +msg_unmarshal(struct msg *tmp,  struct evbuffer *evbuf)
   1.319 +{
   1.320 +  ev_uint32_t tag;
   1.321 +  while (evbuffer_get_length(evbuf) > 0) {
   1.322 +    if (evtag_peek(evbuf, &tag) == -1)
   1.323 +      return (-1);
   1.324 +    switch (tag) {
   1.325 +
   1.326 +      case MSG_FROM_NAME:
   1.327 +
   1.328 +        if (tmp->from_name_set)
   1.329 +          return (-1);
   1.330 +        if (evtag_unmarshal_string(evbuf, MSG_FROM_NAME, &tmp->from_name_data) == -1) {
   1.331 +          event_warnx("%s: failed to unmarshal from_name", __func__);
   1.332 +          return (-1);
   1.333 +        }
   1.334 +        tmp->from_name_set = 1;
   1.335 +        break;
   1.336 +
   1.337 +      case MSG_TO_NAME:
   1.338 +
   1.339 +        if (tmp->to_name_set)
   1.340 +          return (-1);
   1.341 +        if (evtag_unmarshal_string(evbuf, MSG_TO_NAME, &tmp->to_name_data) == -1) {
   1.342 +          event_warnx("%s: failed to unmarshal to_name", __func__);
   1.343 +          return (-1);
   1.344 +        }
   1.345 +        tmp->to_name_set = 1;
   1.346 +        break;
   1.347 +
   1.348 +      case MSG_ATTACK:
   1.349 +
   1.350 +        if (tmp->attack_set)
   1.351 +          return (-1);
   1.352 +        tmp->attack_data = kill_new();
   1.353 +        if (tmp->attack_data == NULL)
   1.354 +          return (-1);
   1.355 +        if (evtag_unmarshal_kill(evbuf, MSG_ATTACK, tmp->attack_data) == -1) {
   1.356 +          event_warnx("%s: failed to unmarshal attack", __func__);
   1.357 +          return (-1);
   1.358 +        }
   1.359 +        tmp->attack_set = 1;
   1.360 +        break;
   1.361 +
   1.362 +      case MSG_RUN:
   1.363 +
   1.364 +        if (tmp->run_length >= tmp->run_num_allocated &&
   1.365 +            msg_run_expand_to_hold_more(tmp) < 0) {
   1.366 +          puts("HEY NOW");
   1.367 +          return (-1);
   1.368 +        }
   1.369 +        tmp->run_data[tmp->run_length] = run_new();
   1.370 +        if (tmp->run_data[tmp->run_length] == NULL)
   1.371 +          return (-1);
   1.372 +        if (evtag_unmarshal_run(evbuf, MSG_RUN, tmp->run_data[tmp->run_length]) == -1) {
   1.373 +          event_warnx("%s: failed to unmarshal run", __func__);
   1.374 +          return (-1);
   1.375 +        }
   1.376 +        ++tmp->run_length;
   1.377 +        tmp->run_set = 1;
   1.378 +        break;
   1.379 +
   1.380 +      default:
   1.381 +        return -1;
   1.382 +    }
   1.383 +  }
   1.384 +
   1.385 +  if (msg_complete(tmp) == -1)
   1.386 +    return (-1);
   1.387 +  return (0);
   1.388 +}
   1.389 +
   1.390 +int
   1.391 +msg_complete(struct msg *msg)
   1.392 +{
   1.393 +  if (!msg->from_name_set)
   1.394 +    return (-1);
   1.395 +  if (!msg->to_name_set)
   1.396 +    return (-1);
   1.397 +  if (msg->attack_set && kill_complete(msg->attack_data) == -1)
   1.398 +    return (-1);
   1.399 +  {
   1.400 +    int i;
   1.401 +    for (i = 0; i < msg->run_length; ++i) {
   1.402 +      if (msg->run_set && run_complete(msg->run_data[i]) == -1)
   1.403 +        return (-1);
   1.404 +    }
   1.405 +  }
   1.406 +  return (0);
   1.407 +}
   1.408 +
   1.409 +int
   1.410 +evtag_unmarshal_msg(struct evbuffer *evbuf, ev_uint32_t need_tag, struct msg *msg)
   1.411 +{
   1.412 +  ev_uint32_t tag;
   1.413 +  int res = -1;
   1.414 +
   1.415 +  struct evbuffer *tmp = evbuffer_new();
   1.416 +
   1.417 +  if (evtag_unmarshal(evbuf, &tag, tmp) == -1 || tag != need_tag)
   1.418 +    goto error;
   1.419 +
   1.420 +  if (msg_unmarshal(msg, tmp) == -1)
   1.421 +    goto error;
   1.422 +
   1.423 +  res = 0;
   1.424 +
   1.425 + error:
   1.426 +  evbuffer_free(tmp);
   1.427 +  return (res);
   1.428 +}
   1.429 +
   1.430 +void
   1.431 +evtag_marshal_msg(struct evbuffer *evbuf, ev_uint32_t tag, const struct msg *msg)
   1.432 +{
   1.433 +  struct evbuffer *_buf = evbuffer_new();
   1.434 +  assert(_buf != NULL);
   1.435 +  msg_marshal(_buf, msg);
   1.436 +  evtag_marshal_buffer(evbuf, tag, _buf);
   1.437 +   evbuffer_free(_buf);
   1.438 +}
   1.439 +
   1.440 +/*
   1.441 + * Implementation of kill
   1.442 + */
   1.443 +
   1.444 +static struct kill_access_ __kill_base = {
   1.445 +  kill_weapon_assign,
   1.446 +  kill_weapon_get,
   1.447 +  kill_action_assign,
   1.448 +  kill_action_get,
   1.449 +  kill_how_often_assign,
   1.450 +  kill_how_often_get,
   1.451 +  kill_how_often_add,
   1.452 +};
   1.453 +
   1.454 +struct kill *
   1.455 +kill_new(void)
   1.456 +{
   1.457 +  return kill_new_with_arg(NULL);
   1.458 +}
   1.459 +
   1.460 +struct kill *
   1.461 +kill_new_with_arg(void *unused)
   1.462 +{
   1.463 +  struct kill *tmp;
   1.464 +  if ((tmp = malloc(sizeof(struct kill))) == NULL) {
   1.465 +    event_warn("%s: malloc", __func__);
   1.466 +    return (NULL);
   1.467 +  }
   1.468 +  tmp->base = &__kill_base;
   1.469 +
   1.470 +  tmp->weapon_data = NULL;
   1.471 +  tmp->weapon_set = 0;
   1.472 +
   1.473 +  tmp->action_data = NULL;
   1.474 +  tmp->action_set = 0;
   1.475 +
   1.476 +  tmp->how_often_data = NULL;
   1.477 +  tmp->how_often_length = 0;
   1.478 +  tmp->how_often_num_allocated = 0;
   1.479 +  tmp->how_often_set = 0;
   1.480 +
   1.481 +  return (tmp);
   1.482 +}
   1.483 +
   1.484 +
   1.485 +
   1.486 +static int
   1.487 +kill_how_often_expand_to_hold_more(struct kill *msg)
   1.488 +{
   1.489 +  int tobe_allocated = msg->how_often_num_allocated;
   1.490 +  ev_uint32_t* new_data = NULL;
   1.491 +  tobe_allocated = !tobe_allocated ? 1 : tobe_allocated << 1;
   1.492 +  new_data = (ev_uint32_t*) realloc(msg->how_often_data,
   1.493 +      tobe_allocated * sizeof(ev_uint32_t));
   1.494 +  if (new_data == NULL)
   1.495 +    return -1;
   1.496 +  msg->how_often_data = new_data;
   1.497 +  msg->how_often_num_allocated = tobe_allocated;
   1.498 +  return 0;}
   1.499 +
   1.500 +ev_uint32_t *
   1.501 +kill_how_often_add(struct kill *msg, const ev_uint32_t value)
   1.502 +{
   1.503 +  if (++msg->how_often_length >= msg->how_often_num_allocated) {
   1.504 +    if (kill_how_often_expand_to_hold_more(msg)<0)
   1.505 +      goto error;
   1.506 +  }
   1.507 +  msg->how_often_data[msg->how_often_length - 1] = value;
   1.508 +  msg->how_often_set = 1;
   1.509 +  return &(msg->how_often_data[msg->how_often_length - 1]);
   1.510 +error:
   1.511 +  --msg->how_often_length;
   1.512 +  return (NULL);
   1.513 +}
   1.514 +
   1.515 +int
   1.516 +kill_weapon_assign(struct kill *msg,
   1.517 +    const char * value)
   1.518 +{
   1.519 +  if (msg->weapon_data != NULL)
   1.520 +    free(msg->weapon_data);
   1.521 +  if ((msg->weapon_data = strdup(value)) == NULL)
   1.522 +    return (-1);
   1.523 +  msg->weapon_set = 1;
   1.524 +  return (0);
   1.525 +}
   1.526 +
   1.527 +int
   1.528 +kill_action_assign(struct kill *msg,
   1.529 +    const char * value)
   1.530 +{
   1.531 +  if (msg->action_data != NULL)
   1.532 +    free(msg->action_data);
   1.533 +  if ((msg->action_data = strdup(value)) == NULL)
   1.534 +    return (-1);
   1.535 +  msg->action_set = 1;
   1.536 +  return (0);
   1.537 +}
   1.538 +
   1.539 +int
   1.540 +kill_how_often_assign(struct kill *msg, int off,
   1.541 +    const ev_uint32_t value)
   1.542 +{
   1.543 +  if (!msg->how_often_set || off < 0 || off >= msg->how_often_length)
   1.544 +    return (-1);
   1.545 +
   1.546 +  {
   1.547 +    msg->how_often_data[off] = value;
   1.548 +  }
   1.549 +  return (0);
   1.550 +}
   1.551 +
   1.552 +int
   1.553 +kill_weapon_get(struct kill *msg, char * *value)
   1.554 +{
   1.555 +  if (msg->weapon_set != 1)
   1.556 +    return (-1);
   1.557 +  *value = msg->weapon_data;
   1.558 +  return (0);
   1.559 +}
   1.560 +
   1.561 +int
   1.562 +kill_action_get(struct kill *msg, char * *value)
   1.563 +{
   1.564 +  if (msg->action_set != 1)
   1.565 +    return (-1);
   1.566 +  *value = msg->action_data;
   1.567 +  return (0);
   1.568 +}
   1.569 +
   1.570 +int
   1.571 +kill_how_often_get(struct kill *msg, int offset,
   1.572 +    ev_uint32_t *value)
   1.573 +{
   1.574 +  if (!msg->how_often_set || offset < 0 || offset >= msg->how_often_length)
   1.575 +    return (-1);
   1.576 +  *value = msg->how_often_data[offset];
   1.577 +  return (0);
   1.578 +}
   1.579 +
   1.580 +void
   1.581 +kill_clear(struct kill *tmp)
   1.582 +{
   1.583 +  if (tmp->weapon_set == 1) {
   1.584 +    free(tmp->weapon_data);
   1.585 +    tmp->weapon_data = NULL;
   1.586 +    tmp->weapon_set = 0;
   1.587 +  }
   1.588 +  if (tmp->action_set == 1) {
   1.589 +    free(tmp->action_data);
   1.590 +    tmp->action_data = NULL;
   1.591 +    tmp->action_set = 0;
   1.592 +  }
   1.593 +  if (tmp->how_often_set == 1) {
   1.594 +    free(tmp->how_often_data);
   1.595 +    tmp->how_often_data = NULL;
   1.596 +    tmp->how_often_set = 0;
   1.597 +    tmp->how_often_length = 0;
   1.598 +    tmp->how_often_num_allocated = 0;
   1.599 +  }
   1.600 +}
   1.601 +
   1.602 +void
   1.603 +kill_free(struct kill *tmp)
   1.604 +{
   1.605 +  if (tmp->weapon_data != NULL)
   1.606 +      free (tmp->weapon_data);
   1.607 +  if (tmp->action_data != NULL)
   1.608 +      free (tmp->action_data);
   1.609 +  if (tmp->how_often_set == 1) {
   1.610 +    free(tmp->how_often_data);
   1.611 +    tmp->how_often_data = NULL;
   1.612 +    tmp->how_often_set = 0;
   1.613 +    tmp->how_often_length = 0;
   1.614 +    tmp->how_often_num_allocated = 0;
   1.615 +  }
   1.616 +  free(tmp->how_often_data);
   1.617 +  free(tmp);
   1.618 +}
   1.619 +
   1.620 +void
   1.621 +kill_marshal(struct evbuffer *evbuf, const struct kill *tmp){
   1.622 +  evtag_marshal_string(evbuf, KILL_WEAPON, tmp->weapon_data);
   1.623 +  evtag_marshal_string(evbuf, KILL_ACTION, tmp->action_data);
   1.624 +  if (tmp->how_often_set) {
   1.625 +    {
   1.626 +      int i;
   1.627 +      for (i = 0; i < tmp->how_often_length; ++i) {
   1.628 +    evtag_marshal_int(evbuf, KILL_HOW_OFTEN, tmp->how_often_data[i]);
   1.629 +      }
   1.630 +    }
   1.631 +  }
   1.632 +}
   1.633 +
   1.634 +int
   1.635 +kill_unmarshal(struct kill *tmp,  struct evbuffer *evbuf)
   1.636 +{
   1.637 +  ev_uint32_t tag;
   1.638 +  while (evbuffer_get_length(evbuf) > 0) {
   1.639 +    if (evtag_peek(evbuf, &tag) == -1)
   1.640 +      return (-1);
   1.641 +    switch (tag) {
   1.642 +
   1.643 +      case KILL_WEAPON:
   1.644 +
   1.645 +        if (tmp->weapon_set)
   1.646 +          return (-1);
   1.647 +        if (evtag_unmarshal_string(evbuf, KILL_WEAPON, &tmp->weapon_data) == -1) {
   1.648 +          event_warnx("%s: failed to unmarshal weapon", __func__);
   1.649 +          return (-1);
   1.650 +        }
   1.651 +        tmp->weapon_set = 1;
   1.652 +        break;
   1.653 +
   1.654 +      case KILL_ACTION:
   1.655 +
   1.656 +        if (tmp->action_set)
   1.657 +          return (-1);
   1.658 +        if (evtag_unmarshal_string(evbuf, KILL_ACTION, &tmp->action_data) == -1) {
   1.659 +          event_warnx("%s: failed to unmarshal action", __func__);
   1.660 +          return (-1);
   1.661 +        }
   1.662 +        tmp->action_set = 1;
   1.663 +        break;
   1.664 +
   1.665 +      case KILL_HOW_OFTEN:
   1.666 +
   1.667 +        if (tmp->how_often_length >= tmp->how_often_num_allocated &&
   1.668 +            kill_how_often_expand_to_hold_more(tmp) < 0) {
   1.669 +          puts("HEY NOW");
   1.670 +          return (-1);
   1.671 +        }
   1.672 +        if (evtag_unmarshal_int(evbuf, KILL_HOW_OFTEN, &tmp->how_often_data[tmp->how_often_length]) == -1) {
   1.673 +          event_warnx("%s: failed to unmarshal how_often", __func__);
   1.674 +          return (-1);
   1.675 +        }
   1.676 +        ++tmp->how_often_length;
   1.677 +        tmp->how_often_set = 1;
   1.678 +        break;
   1.679 +
   1.680 +      default:
   1.681 +        return -1;
   1.682 +    }
   1.683 +  }
   1.684 +
   1.685 +  if (kill_complete(tmp) == -1)
   1.686 +    return (-1);
   1.687 +  return (0);
   1.688 +}
   1.689 +
   1.690 +int
   1.691 +kill_complete(struct kill *msg)
   1.692 +{
   1.693 +  if (!msg->weapon_set)
   1.694 +    return (-1);
   1.695 +  if (!msg->action_set)
   1.696 +    return (-1);
   1.697 +  return (0);
   1.698 +}
   1.699 +
   1.700 +int
   1.701 +evtag_unmarshal_kill(struct evbuffer *evbuf, ev_uint32_t need_tag, struct kill *msg)
   1.702 +{
   1.703 +  ev_uint32_t tag;
   1.704 +  int res = -1;
   1.705 +
   1.706 +  struct evbuffer *tmp = evbuffer_new();
   1.707 +
   1.708 +  if (evtag_unmarshal(evbuf, &tag, tmp) == -1 || tag != need_tag)
   1.709 +    goto error;
   1.710 +
   1.711 +  if (kill_unmarshal(msg, tmp) == -1)
   1.712 +    goto error;
   1.713 +
   1.714 +  res = 0;
   1.715 +
   1.716 + error:
   1.717 +  evbuffer_free(tmp);
   1.718 +  return (res);
   1.719 +}
   1.720 +
   1.721 +void
   1.722 +evtag_marshal_kill(struct evbuffer *evbuf, ev_uint32_t tag, const struct kill *msg)
   1.723 +{
   1.724 +  struct evbuffer *_buf = evbuffer_new();
   1.725 +  assert(_buf != NULL);
   1.726 +  kill_marshal(_buf, msg);
   1.727 +  evtag_marshal_buffer(evbuf, tag, _buf);
   1.728 +   evbuffer_free(_buf);
   1.729 +}
   1.730 +
   1.731 +/*
   1.732 + * Implementation of run
   1.733 + */
   1.734 +
   1.735 +static struct run_access_ __run_base = {
   1.736 +  run_how_assign,
   1.737 +  run_how_get,
   1.738 +  run_some_bytes_assign,
   1.739 +  run_some_bytes_get,
   1.740 +  run_fixed_bytes_assign,
   1.741 +  run_fixed_bytes_get,
   1.742 +  run_notes_assign,
   1.743 +  run_notes_get,
   1.744 +  run_notes_add,
   1.745 +  run_large_number_assign,
   1.746 +  run_large_number_get,
   1.747 +  run_other_numbers_assign,
   1.748 +  run_other_numbers_get,
   1.749 +  run_other_numbers_add,
   1.750 +};
   1.751 +
   1.752 +struct run *
   1.753 +run_new(void)
   1.754 +{
   1.755 +  return run_new_with_arg(NULL);
   1.756 +}
   1.757 +
   1.758 +struct run *
   1.759 +run_new_with_arg(void *unused)
   1.760 +{
   1.761 +  struct run *tmp;
   1.762 +  if ((tmp = malloc(sizeof(struct run))) == NULL) {
   1.763 +    event_warn("%s: malloc", __func__);
   1.764 +    return (NULL);
   1.765 +  }
   1.766 +  tmp->base = &__run_base;
   1.767 +
   1.768 +  tmp->how_data = NULL;
   1.769 +  tmp->how_set = 0;
   1.770 +
   1.771 +  tmp->some_bytes_data = NULL;
   1.772 +  tmp->some_bytes_length = 0;
   1.773 +  tmp->some_bytes_set = 0;
   1.774 +
   1.775 +  memset(tmp->fixed_bytes_data, 0, sizeof(tmp->fixed_bytes_data));
   1.776 +  tmp->fixed_bytes_set = 0;
   1.777 +
   1.778 +  tmp->notes_data = NULL;
   1.779 +  tmp->notes_length = 0;
   1.780 +  tmp->notes_num_allocated = 0;
   1.781 +  tmp->notes_set = 0;
   1.782 +
   1.783 +  tmp->large_number_data = 0;
   1.784 +  tmp->large_number_set = 0;
   1.785 +
   1.786 +  tmp->other_numbers_data = NULL;
   1.787 +  tmp->other_numbers_length = 0;
   1.788 +  tmp->other_numbers_num_allocated = 0;
   1.789 +  tmp->other_numbers_set = 0;
   1.790 +
   1.791 +  return (tmp);
   1.792 +}
   1.793 +
   1.794 +
   1.795 +
   1.796 +
   1.797 +static int
   1.798 +run_notes_expand_to_hold_more(struct run *msg)
   1.799 +{
   1.800 +  int tobe_allocated = msg->notes_num_allocated;
   1.801 +  char ** new_data = NULL;
   1.802 +  tobe_allocated = !tobe_allocated ? 1 : tobe_allocated << 1;
   1.803 +  new_data = (char **) realloc(msg->notes_data,
   1.804 +      tobe_allocated * sizeof(char *));
   1.805 +  if (new_data == NULL)
   1.806 +    return -1;
   1.807 +  msg->notes_data = new_data;
   1.808 +  msg->notes_num_allocated = tobe_allocated;
   1.809 +  return 0;}
   1.810 +
   1.811 +char * *
   1.812 +run_notes_add(struct run *msg, const char * value)
   1.813 +{
   1.814 +  if (++msg->notes_length >= msg->notes_num_allocated) {
   1.815 +    if (run_notes_expand_to_hold_more(msg)<0)
   1.816 +      goto error;
   1.817 +  }
   1.818 +  if (value != NULL) {
   1.819 +    msg->notes_data[msg->notes_length - 1] = strdup(value);
   1.820 +    if (msg->notes_data[msg->notes_length - 1] == NULL) {
   1.821 +      goto error;
   1.822 +    }
   1.823 +  } else {
   1.824 +    msg->notes_data[msg->notes_length - 1] = NULL;
   1.825 +  }
   1.826 +  msg->notes_set = 1;
   1.827 +  return &(msg->notes_data[msg->notes_length - 1]);
   1.828 +error:
   1.829 +  --msg->notes_length;
   1.830 +  return (NULL);
   1.831 +}
   1.832 +
   1.833 +
   1.834 +static int
   1.835 +run_other_numbers_expand_to_hold_more(struct run *msg)
   1.836 +{
   1.837 +  int tobe_allocated = msg->other_numbers_num_allocated;
   1.838 +  ev_uint32_t* new_data = NULL;
   1.839 +  tobe_allocated = !tobe_allocated ? 1 : tobe_allocated << 1;
   1.840 +  new_data = (ev_uint32_t*) realloc(msg->other_numbers_data,
   1.841 +      tobe_allocated * sizeof(ev_uint32_t));
   1.842 +  if (new_data == NULL)
   1.843 +    return -1;
   1.844 +  msg->other_numbers_data = new_data;
   1.845 +  msg->other_numbers_num_allocated = tobe_allocated;
   1.846 +  return 0;}
   1.847 +
   1.848 +ev_uint32_t *
   1.849 +run_other_numbers_add(struct run *msg, const ev_uint32_t value)
   1.850 +{
   1.851 +  if (++msg->other_numbers_length >= msg->other_numbers_num_allocated) {
   1.852 +    if (run_other_numbers_expand_to_hold_more(msg)<0)
   1.853 +      goto error;
   1.854 +  }
   1.855 +  msg->other_numbers_data[msg->other_numbers_length - 1] = value;
   1.856 +  msg->other_numbers_set = 1;
   1.857 +  return &(msg->other_numbers_data[msg->other_numbers_length - 1]);
   1.858 +error:
   1.859 +  --msg->other_numbers_length;
   1.860 +  return (NULL);
   1.861 +}
   1.862 +
   1.863 +int
   1.864 +run_how_assign(struct run *msg,
   1.865 +    const char * value)
   1.866 +{
   1.867 +  if (msg->how_data != NULL)
   1.868 +    free(msg->how_data);
   1.869 +  if ((msg->how_data = strdup(value)) == NULL)
   1.870 +    return (-1);
   1.871 +  msg->how_set = 1;
   1.872 +  return (0);
   1.873 +}
   1.874 +
   1.875 +int
   1.876 +run_some_bytes_assign(struct run *msg, const ev_uint8_t * value, ev_uint32_t len)
   1.877 +{
   1.878 +  if (msg->some_bytes_data != NULL)
   1.879 +    free (msg->some_bytes_data);
   1.880 +  msg->some_bytes_data = malloc(len);
   1.881 +  if (msg->some_bytes_data == NULL)
   1.882 +    return (-1);
   1.883 +  msg->some_bytes_set = 1;
   1.884 +  msg->some_bytes_length = len;
   1.885 +  memcpy(msg->some_bytes_data, value, len);
   1.886 +  return (0);
   1.887 +}
   1.888 +
   1.889 +int
   1.890 +run_fixed_bytes_assign(struct run *msg, const ev_uint8_t *value)
   1.891 +{
   1.892 +  msg->fixed_bytes_set = 1;
   1.893 +  memcpy(msg->fixed_bytes_data, value, 24);
   1.894 +  return (0);
   1.895 +}
   1.896 +
   1.897 +int
   1.898 +run_notes_assign(struct run *msg, int off,
   1.899 +    const char * value)
   1.900 +{
   1.901 +  if (!msg->notes_set || off < 0 || off >= msg->notes_length)
   1.902 +    return (-1);
   1.903 +
   1.904 +  {
   1.905 +    if (msg->notes_data[off] != NULL)
   1.906 +      free(msg->notes_data[off]);
   1.907 +    msg->notes_data[off] = strdup(value);
   1.908 +    if (msg->notes_data[off] == NULL) {
   1.909 +      event_warnx("%s: strdup", __func__);
   1.910 +      return (-1);
   1.911 +    }
   1.912 +  }
   1.913 +  return (0);
   1.914 +}
   1.915 +
   1.916 +int
   1.917 +run_large_number_assign(struct run *msg, const ev_uint64_t value)
   1.918 +{
   1.919 +  msg->large_number_set = 1;
   1.920 +  msg->large_number_data = value;
   1.921 +  return (0);
   1.922 +}
   1.923 +
   1.924 +int
   1.925 +run_other_numbers_assign(struct run *msg, int off,
   1.926 +    const ev_uint32_t value)
   1.927 +{
   1.928 +  if (!msg->other_numbers_set || off < 0 || off >= msg->other_numbers_length)
   1.929 +    return (-1);
   1.930 +
   1.931 +  {
   1.932 +    msg->other_numbers_data[off] = value;
   1.933 +  }
   1.934 +  return (0);
   1.935 +}
   1.936 +
   1.937 +int
   1.938 +run_how_get(struct run *msg, char * *value)
   1.939 +{
   1.940 +  if (msg->how_set != 1)
   1.941 +    return (-1);
   1.942 +  *value = msg->how_data;
   1.943 +  return (0);
   1.944 +}
   1.945 +
   1.946 +int
   1.947 +run_some_bytes_get(struct run *msg, ev_uint8_t * *value, ev_uint32_t *plen)
   1.948 +{
   1.949 +  if (msg->some_bytes_set != 1)
   1.950 +    return (-1);
   1.951 +  *value = msg->some_bytes_data;
   1.952 +  *plen = msg->some_bytes_length;
   1.953 +  return (0);
   1.954 +}
   1.955 +
   1.956 +int
   1.957 +run_fixed_bytes_get(struct run *msg, ev_uint8_t **value)
   1.958 +{
   1.959 +  if (msg->fixed_bytes_set != 1)
   1.960 +    return (-1);
   1.961 +  *value = msg->fixed_bytes_data;
   1.962 +  return (0);
   1.963 +}
   1.964 +
   1.965 +int
   1.966 +run_notes_get(struct run *msg, int offset,
   1.967 +    char * *value)
   1.968 +{
   1.969 +  if (!msg->notes_set || offset < 0 || offset >= msg->notes_length)
   1.970 +    return (-1);
   1.971 +  *value = msg->notes_data[offset];
   1.972 +  return (0);
   1.973 +}
   1.974 +
   1.975 +int
   1.976 +run_large_number_get(struct run *msg, ev_uint64_t *value)
   1.977 +{
   1.978 +  if (msg->large_number_set != 1)
   1.979 +    return (-1);
   1.980 +  *value = msg->large_number_data;
   1.981 +  return (0);
   1.982 +}
   1.983 +
   1.984 +int
   1.985 +run_other_numbers_get(struct run *msg, int offset,
   1.986 +    ev_uint32_t *value)
   1.987 +{
   1.988 +  if (!msg->other_numbers_set || offset < 0 || offset >= msg->other_numbers_length)
   1.989 +    return (-1);
   1.990 +  *value = msg->other_numbers_data[offset];
   1.991 +  return (0);
   1.992 +}
   1.993 +
   1.994 +void
   1.995 +run_clear(struct run *tmp)
   1.996 +{
   1.997 +  if (tmp->how_set == 1) {
   1.998 +    free(tmp->how_data);
   1.999 +    tmp->how_data = NULL;
  1.1000 +    tmp->how_set = 0;
  1.1001 +  }
  1.1002 +  if (tmp->some_bytes_set == 1) {
  1.1003 +    free (tmp->some_bytes_data);
  1.1004 +    tmp->some_bytes_data = NULL;
  1.1005 +    tmp->some_bytes_length = 0;
  1.1006 +    tmp->some_bytes_set = 0;
  1.1007 +  }
  1.1008 +  tmp->fixed_bytes_set = 0;
  1.1009 +  memset(tmp->fixed_bytes_data, 0, sizeof(tmp->fixed_bytes_data));
  1.1010 +  if (tmp->notes_set == 1) {
  1.1011 +    int i;
  1.1012 +    for (i = 0; i < tmp->notes_length; ++i) {
  1.1013 +      if (tmp->notes_data[i] != NULL) free(tmp->notes_data[i]);
  1.1014 +    }
  1.1015 +    free(tmp->notes_data);
  1.1016 +    tmp->notes_data = NULL;
  1.1017 +    tmp->notes_set = 0;
  1.1018 +    tmp->notes_length = 0;
  1.1019 +    tmp->notes_num_allocated = 0;
  1.1020 +  }
  1.1021 +  tmp->large_number_set = 0;
  1.1022 +  if (tmp->other_numbers_set == 1) {
  1.1023 +    free(tmp->other_numbers_data);
  1.1024 +    tmp->other_numbers_data = NULL;
  1.1025 +    tmp->other_numbers_set = 0;
  1.1026 +    tmp->other_numbers_length = 0;
  1.1027 +    tmp->other_numbers_num_allocated = 0;
  1.1028 +  }
  1.1029 +}
  1.1030 +
  1.1031 +void
  1.1032 +run_free(struct run *tmp)
  1.1033 +{
  1.1034 +  if (tmp->how_data != NULL)
  1.1035 +      free (tmp->how_data);
  1.1036 +  if (tmp->some_bytes_data != NULL)
  1.1037 +      free(tmp->some_bytes_data);
  1.1038 +  if (tmp->notes_set == 1) {
  1.1039 +    int i;
  1.1040 +    for (i = 0; i < tmp->notes_length; ++i) {
  1.1041 +      if (tmp->notes_data[i] != NULL) free(tmp->notes_data[i]);
  1.1042 +    }
  1.1043 +    free(tmp->notes_data);
  1.1044 +    tmp->notes_data = NULL;
  1.1045 +    tmp->notes_set = 0;
  1.1046 +    tmp->notes_length = 0;
  1.1047 +    tmp->notes_num_allocated = 0;
  1.1048 +  }
  1.1049 +  free(tmp->notes_data);
  1.1050 +  if (tmp->other_numbers_set == 1) {
  1.1051 +    free(tmp->other_numbers_data);
  1.1052 +    tmp->other_numbers_data = NULL;
  1.1053 +    tmp->other_numbers_set = 0;
  1.1054 +    tmp->other_numbers_length = 0;
  1.1055 +    tmp->other_numbers_num_allocated = 0;
  1.1056 +  }
  1.1057 +  free(tmp->other_numbers_data);
  1.1058 +  free(tmp);
  1.1059 +}
  1.1060 +
  1.1061 +void
  1.1062 +run_marshal(struct evbuffer *evbuf, const struct run *tmp){
  1.1063 +  evtag_marshal_string(evbuf, RUN_HOW, tmp->how_data);
  1.1064 +  if (tmp->some_bytes_set) {
  1.1065 +    evtag_marshal(evbuf, RUN_SOME_BYTES, tmp->some_bytes_data, tmp->some_bytes_length);
  1.1066 +  }
  1.1067 +  evtag_marshal(evbuf, RUN_FIXED_BYTES, tmp->fixed_bytes_data, (24));
  1.1068 +  if (tmp->notes_set) {
  1.1069 +    {
  1.1070 +      int i;
  1.1071 +      for (i = 0; i < tmp->notes_length; ++i) {
  1.1072 +    evtag_marshal_string(evbuf, RUN_NOTES, tmp->notes_data[i]);
  1.1073 +      }
  1.1074 +    }
  1.1075 +  }
  1.1076 +  if (tmp->large_number_set) {
  1.1077 +    evtag_marshal_int64(evbuf, RUN_LARGE_NUMBER, tmp->large_number_data);
  1.1078 +  }
  1.1079 +  if (tmp->other_numbers_set) {
  1.1080 +    {
  1.1081 +      int i;
  1.1082 +      for (i = 0; i < tmp->other_numbers_length; ++i) {
  1.1083 +    evtag_marshal_int(evbuf, RUN_OTHER_NUMBERS, tmp->other_numbers_data[i]);
  1.1084 +      }
  1.1085 +    }
  1.1086 +  }
  1.1087 +}
  1.1088 +
  1.1089 +int
  1.1090 +run_unmarshal(struct run *tmp,  struct evbuffer *evbuf)
  1.1091 +{
  1.1092 +  ev_uint32_t tag;
  1.1093 +  while (evbuffer_get_length(evbuf) > 0) {
  1.1094 +    if (evtag_peek(evbuf, &tag) == -1)
  1.1095 +      return (-1);
  1.1096 +    switch (tag) {
  1.1097 +
  1.1098 +      case RUN_HOW:
  1.1099 +
  1.1100 +        if (tmp->how_set)
  1.1101 +          return (-1);
  1.1102 +        if (evtag_unmarshal_string(evbuf, RUN_HOW, &tmp->how_data) == -1) {
  1.1103 +          event_warnx("%s: failed to unmarshal how", __func__);
  1.1104 +          return (-1);
  1.1105 +        }
  1.1106 +        tmp->how_set = 1;
  1.1107 +        break;
  1.1108 +
  1.1109 +      case RUN_SOME_BYTES:
  1.1110 +
  1.1111 +        if (tmp->some_bytes_set)
  1.1112 +          return (-1);
  1.1113 +        if (evtag_payload_length(evbuf, &tmp->some_bytes_length) == -1)
  1.1114 +          return (-1);
  1.1115 +        if (tmp->some_bytes_length > evbuffer_get_length(evbuf))
  1.1116 +          return (-1);
  1.1117 +        if ((tmp->some_bytes_data = malloc(tmp->some_bytes_length)) == NULL)
  1.1118 +          return (-1);
  1.1119 +        if (evtag_unmarshal_fixed(evbuf, RUN_SOME_BYTES, tmp->some_bytes_data, tmp->some_bytes_length) == -1) {
  1.1120 +          event_warnx("%s: failed to unmarshal some_bytes", __func__);
  1.1121 +          return (-1);
  1.1122 +        }
  1.1123 +        tmp->some_bytes_set = 1;
  1.1124 +        break;
  1.1125 +
  1.1126 +      case RUN_FIXED_BYTES:
  1.1127 +
  1.1128 +        if (tmp->fixed_bytes_set)
  1.1129 +          return (-1);
  1.1130 +        if (evtag_unmarshal_fixed(evbuf, RUN_FIXED_BYTES, tmp->fixed_bytes_data, (24)) == -1) {
  1.1131 +          event_warnx("%s: failed to unmarshal fixed_bytes", __func__);
  1.1132 +          return (-1);
  1.1133 +        }
  1.1134 +        tmp->fixed_bytes_set = 1;
  1.1135 +        break;
  1.1136 +
  1.1137 +      case RUN_NOTES:
  1.1138 +
  1.1139 +        if (tmp->notes_length >= tmp->notes_num_allocated &&
  1.1140 +            run_notes_expand_to_hold_more(tmp) < 0) {
  1.1141 +          puts("HEY NOW");
  1.1142 +          return (-1);
  1.1143 +        }
  1.1144 +        if (evtag_unmarshal_string(evbuf, RUN_NOTES, &tmp->notes_data[tmp->notes_length]) == -1) {
  1.1145 +          event_warnx("%s: failed to unmarshal notes", __func__);
  1.1146 +          return (-1);
  1.1147 +        }
  1.1148 +        ++tmp->notes_length;
  1.1149 +        tmp->notes_set = 1;
  1.1150 +        break;
  1.1151 +
  1.1152 +      case RUN_LARGE_NUMBER:
  1.1153 +
  1.1154 +        if (tmp->large_number_set)
  1.1155 +          return (-1);
  1.1156 +        if (evtag_unmarshal_int64(evbuf, RUN_LARGE_NUMBER, &tmp->large_number_data) == -1) {
  1.1157 +          event_warnx("%s: failed to unmarshal large_number", __func__);
  1.1158 +          return (-1);
  1.1159 +        }
  1.1160 +        tmp->large_number_set = 1;
  1.1161 +        break;
  1.1162 +
  1.1163 +      case RUN_OTHER_NUMBERS:
  1.1164 +
  1.1165 +        if (tmp->other_numbers_length >= tmp->other_numbers_num_allocated &&
  1.1166 +            run_other_numbers_expand_to_hold_more(tmp) < 0) {
  1.1167 +          puts("HEY NOW");
  1.1168 +          return (-1);
  1.1169 +        }
  1.1170 +        if (evtag_unmarshal_int(evbuf, RUN_OTHER_NUMBERS, &tmp->other_numbers_data[tmp->other_numbers_length]) == -1) {
  1.1171 +          event_warnx("%s: failed to unmarshal other_numbers", __func__);
  1.1172 +          return (-1);
  1.1173 +        }
  1.1174 +        ++tmp->other_numbers_length;
  1.1175 +        tmp->other_numbers_set = 1;
  1.1176 +        break;
  1.1177 +
  1.1178 +      default:
  1.1179 +        return -1;
  1.1180 +    }
  1.1181 +  }
  1.1182 +
  1.1183 +  if (run_complete(tmp) == -1)
  1.1184 +    return (-1);
  1.1185 +  return (0);
  1.1186 +}
  1.1187 +
  1.1188 +int
  1.1189 +run_complete(struct run *msg)
  1.1190 +{
  1.1191 +  if (!msg->how_set)
  1.1192 +    return (-1);
  1.1193 +  if (!msg->fixed_bytes_set)
  1.1194 +    return (-1);
  1.1195 +  return (0);
  1.1196 +}
  1.1197 +
  1.1198 +int
  1.1199 +evtag_unmarshal_run(struct evbuffer *evbuf, ev_uint32_t need_tag, struct run *msg)
  1.1200 +{
  1.1201 +  ev_uint32_t tag;
  1.1202 +  int res = -1;
  1.1203 +
  1.1204 +  struct evbuffer *tmp = evbuffer_new();
  1.1205 +
  1.1206 +  if (evtag_unmarshal(evbuf, &tag, tmp) == -1 || tag != need_tag)
  1.1207 +    goto error;
  1.1208 +
  1.1209 +  if (run_unmarshal(msg, tmp) == -1)
  1.1210 +    goto error;
  1.1211 +
  1.1212 +  res = 0;
  1.1213 +
  1.1214 + error:
  1.1215 +  evbuffer_free(tmp);
  1.1216 +  return (res);
  1.1217 +}
  1.1218 +
  1.1219 +void
  1.1220 +evtag_marshal_run(struct evbuffer *evbuf, ev_uint32_t tag, const struct run *msg)
  1.1221 +{
  1.1222 +  struct evbuffer *_buf = evbuffer_new();
  1.1223 +  assert(_buf != NULL);
  1.1224 +  run_marshal(_buf, msg);
  1.1225 +  evtag_marshal_buffer(evbuf, tag, _buf);
  1.1226 +   evbuffer_free(_buf);
  1.1227 +}
  1.1228 +

mercurial