Esempio n. 1
0
static int
unpack_add_info(LogReaderObject *self)
{
    PyObject *key;
    PyObject *value = NULL;
    int err;

    err = unpack_string(self, &key);
    if (!err) {
        err = unpack_string(self, &value);
        if (err)
            Py_DECREF(key);
        else {
            PyObject *list = PyDict_GetItem(self->info, key);
            if (list == NULL) {
                list = PyList_New(0);
                if (list == NULL) {
                    err = ERR_EXCEPTION;
                    goto finally;
                }
                if (PyDict_SetItem(self->info, key, list)) {
                    err = ERR_EXCEPTION;
                    goto finally;
                }
            }
            if (PyList_Append(list, value))
                err = ERR_EXCEPTION;
        }
    }
 finally:
    Py_XDECREF(key);
    Py_XDECREF(value);
    return err;
}
Esempio n. 2
0
static void tmate_client_env(struct tmate_unpacker *uk)
{
	char *name = unpack_string(uk);
	char *value = unpack_string(uk);

	tmate_set_env(name, value);

	free(name);
	free(value);
}
Esempio n. 3
0
static void handle_set_env(struct tmate_session *session,
			   struct tmate_unpacker *uk)
{
	char *name = unpack_string(uk);
	char *value = unpack_string(uk);

	tmate_set_env(name, value);
	maybe_save_reconnection_data(session, name, value);

	free(name);
	free(value);
}
Esempio n. 4
0
static void handle_exec_cmd_str(__unused struct tmate_session *session,
				struct tmate_unpacker *uk)
{
	struct cmd_q *cmd_q;
	struct cmd_list *cmdlist;
	char *cause;
	u_int i;

	int client_id = unpack_int(uk);
	char *cmd_str = unpack_string(uk);

	if (cmd_string_parse(cmd_str, &cmdlist, NULL, 0, &cause) != 0) {
		tmate_failed_cmd(client_id, cause);
		free(cause);
		goto out;
	}

	cmd_q = cmdq_new(NULL);
	cmdq_run(cmd_q, cmdlist, NULL);
	cmd_list_free(cmdlist);
	cmdq_free(cmd_q);

	/* error messages land in cfg_causes */
	for (i = 0; i < cfg_ncauses; i++) {
		tmate_failed_cmd(client_id, cfg_causes[i]);
		free(cfg_causes[i]);
	}

	free(cfg_causes);
	cfg_causes = NULL;
	cfg_ncauses = 0;

out:
	free(cmd_str);
}
Esempio n. 5
0
static void tmate_client_exec_cmd(struct tmate_unpacker *uk)
{
	struct cmd_q *cmd_q;
	struct cmd_list *cmdlist;
	char *cause;

	int client_id = unpack_int(uk);
	char *cmd_str = unpack_string(uk);

	if (cmd_string_parse(cmd_str, &cmdlist, NULL, 0, &cause) != 0) {
		tmate_failed_cmd(client_id, cause);
		free(cause);
		goto out;
	}

	/* error messages land in cfg_causes */
	ARRAY_FREE(&cfg_causes);

	cmd_q = cmdq_new(NULL);
	cmdq_run(cmd_q, cmdlist);
	cmd_list_free(cmdlist);
	cmdq_free(cmd_q);

	if (!ARRAY_EMPTY(&cfg_causes)) {
		cause = ARRAY_ITEM(&cfg_causes, 0);
		tmate_failed_cmd(client_id, cause);
		free(cause);
		ARRAY_FREE(&cfg_causes);
	}

out:
	free(cmd_str);
}
Esempio n. 6
0
/* unpack sphere from double and integer buffers (unpacking starts at dpos and ipos in
 * d and i and no more than a specific number of doubles and ints can be red) */
SPHERE* SPHERE_Unpack (void *solfec, int *dpos, double *d, int doubles, int *ipos, int *i, int ints)
{
  SPHERE *sph;
  int j;

  ERRMEM (sph = MEM_CALLOC (sizeof (SPHERE)));

  sph->surface = unpack_int (ipos, i, ints);
  sph->volume = unpack_int (ipos, i, ints);

  unpack_doubles (dpos, d, doubles, sph->cur_center, 3);
  unpack_doubles (dpos, d, doubles, (double*)sph->cur_point, 9);
  sph->cur_radius = unpack_double  (dpos, d, doubles);

  unpack_doubles (dpos, d, doubles, sph->ref_center, 3);
  unpack_doubles (dpos, d, doubles, (double*)sph->ref_point, 9);
  sph->ref_radius = unpack_double  (dpos, d, doubles);

  j = unpack_int (ipos, i, ints); /* unpack material existence flag */

  if (j)
  {
    SOLFEC *sol = solfec;
    char *label = unpack_string (ipos, i, ints);
    ASSERT_DEBUG_EXT (sph->mat = MATSET_Find (sol->mat, label), "Failed to find material when unpacking a sphere");
    free (label);
  }

  return sph;
}
Esempio n. 7
0
/* unpack ellipsoid from double and integer buffers (unpacking starts at dpos and ipos in
 * d and i and no more than a specific number of doubles and ints can be red) */
ELLIP* ELLIP_Unpack (void *solfec, int *dpos, double *d, int doubles, int *ipos, int *i, int ints)
{
  ELLIP *eli;
  int j;

  ERRMEM (eli = MEM_CALLOC (sizeof (ELLIP)));

  eli->surface = unpack_int (ipos, i, ints);
  eli->volume = unpack_int (ipos, i, ints);

  unpack_doubles (dpos, d, doubles, eli->cur_center, 3);
  unpack_doubles (dpos, d, doubles, (double*)eli->cur_point, 9);

  unpack_doubles (dpos, d, doubles, eli->ref_center, 3);
  unpack_doubles (dpos, d, doubles, (double*)eli->ref_point, 9);

  unpack_doubles (dpos, d, doubles, eli->ref_sca, 3);
  unpack_doubles (dpos, d, doubles, eli->ref_rot, 9);

  unpack_doubles (dpos, d, doubles, eli->cur_sca, 3);
  unpack_doubles (dpos, d, doubles, eli->cur_rot, 9);

  j = unpack_int (ipos, i, ints); /* unpack material existence flag */

  if (j)
  {
    SOLFEC *sol = solfec;
    char *label = unpack_string (ipos, i, ints);
    ASSERT_DEBUG_EXT (eli->mat = MATSET_Find (sol->mat, label), "Failed to find material when unpacking a eliere");
    free (label);
  }

  return eli;
}
Esempio n. 8
0
static void handle_notify(__unused struct tmate_session *session,
			  struct tmate_unpacker *uk)
{
	char *msg = unpack_string(uk);
	tmate_status_message("%s", msg);
	free(msg);
}
Esempio n. 9
0
const std::string
MetaServerPacket::getPacketMessage(unsigned int offset) const
{
	// Just initialise local variable for debug purposes
	std::string tmpstr = "0xDEADBEEF";
	unpack_string(&tmpstr, m_headPtr + offset , (m_Bytes - offset) );
	return tmpstr;
}
Esempio n. 10
0
int
unpack_votehost(char *buf, char *ip, uint16_t *port)
{
    int count = 0;
    count = unpack_string(buf, ip, NULL);
    memcpy(port, buf+count, sizeof(*port));
    count += sizeof(*port);
    return count;
}
static long value_count(grib_accessor* a)
{
	char result[1024]  ;
	size_t s = sizeof(result);

	unpack_string(a,result,&s);

    return s;
}
static int unpack_double   (grib_accessor* a, double* val, size_t *len)
{
    int err=0;
    char buffer[1024]={0,};
    size_t size=1024;

    err=unpack_string (a,buffer,&size);
    if (err) return err;

    *val=atof(buffer);
    *len=1;

    return err;
}
Esempio n. 13
0
static void handle_exec_cmd(__unused struct tmate_session *session,
			    struct tmate_unpacker *uk)
{
	struct cmd_q *cmd_q;
	struct cmd_list *cmdlist;
	struct cmd *cmd;
	char *cause;
	u_int i;
	unsigned int argc;
	char **argv;

	int client_id = unpack_int(uk);

	argc = uk->argc;
	argv = xmalloc(sizeof(char *) * argc);
	for (i = 0; i < argc; i++)
		argv[i] = unpack_string(uk);

	cmd = cmd_parse(argc, argv, NULL, 0, &cause);
	if (!cmd) {
		tmate_failed_cmd(client_id, cause);
		free(cause);
		goto out;
	}

	cmdlist = xcalloc(1, sizeof *cmdlist);
	cmdlist->references = 1;
	TAILQ_INIT(&cmdlist->list);
	TAILQ_INSERT_TAIL(&cmdlist->list, cmd, qentry);

	cmd_q = cmdq_new(NULL);
	cmdq_run(cmd_q, cmdlist, NULL);
	cmd_list_free(cmdlist);
	cmdq_free(cmd_q);

	/* error messages land in cfg_causes */
	for (i = 0; i < cfg_ncauses; i++) {
		tmate_failed_cmd(client_id, cfg_causes[i]);
		free(cfg_causes[i]);
	}

	free(cfg_causes);
	cfg_causes = NULL;
	cfg_ncauses = 0;

out:
	cmd_free_argv(argc, argv);
}
Esempio n. 14
0
int unpack_struct_MultiCallEntry(BUFFER *buf, MultiCallEntry *ptr)
{
    if (unpack_string(buf, &(ptr->name)))
        return -1;
    if (unpack_integer(buf, &(ptr->countent)))
        return -1;
    if (unpack_integer(buf, &(ptr->countexit)))
        return -1;
    if (unpack_integer(buf, &(ptr->tsec)))
        return -1;
    if (unpack_integer(buf, &(ptr->tusec)))
        return -1;
    if (unpack_integer(buf, &(ptr->counttime)))
        return -1;
    return 0;
}
Esempio n. 15
0
int message_deserialize_request(struct message_request *req,
    msgpack_object *obj, struct api_error *api_error)
{
  msgpack_object *type, *msgid, *method, *params;
  uint64_t tmp_type;
  uint64_t tmp_msgid;

  if (!api_error)
    return (-1);

  if (!req || !obj) {
    error_set(api_error, API_ERROR_TYPE_VALIDATION, "Error");
    return (-1);
  }

  /* type */
  if (obj->via.array.ptr[0].type != MSGPACK_OBJECT_POSITIVE_INTEGER) {
    error_set(api_error, API_ERROR_TYPE_VALIDATION, "type field has wrong type");
    return (-1);
  }

  type = &obj->via.array.ptr[0];
  if (!type) {
    error_set(api_error, API_ERROR_TYPE_VALIDATION, "unpack type failed");
    return (-1);
  }

  tmp_type = unpack_uint(type);

  if (tmp_type != MESSAGE_TYPE_REQUEST) {
    error_set(api_error, API_ERROR_TYPE_VALIDATION, "type must be 0 or 1");
    return (-1);
  }

  /* message id */
  msgid = &obj->via.array.ptr[1];

  if (!msgid || msgid->type != MSGPACK_OBJECT_POSITIVE_INTEGER) {
    error_set(api_error, API_ERROR_TYPE_VALIDATION, "illegal msgid");
    return (-1);
  }

  tmp_msgid = unpack_uint(msgid);

  if (tmp_msgid >= UINT32_MAX) {
    error_set(api_error, API_ERROR_TYPE_VALIDATION, "invalid msgid");
    return (-1);
  }

  req->msgid = (uint32_t)tmp_msgid;

  /* method */
  if (obj->via.array.ptr[2].type != MSGPACK_OBJECT_STR) {
    error_set(api_error, API_ERROR_TYPE_VALIDATION, "method field has wrong type");
    return (-1);
  }

  method = &obj->via.array.ptr[2];

  if (!method) {
    error_set(api_error, API_ERROR_TYPE_VALIDATION, "unpack method failed");
    return (-1);
  }

  req->method = unpack_string(method);

  if (!req->method.str) {
    error_set(api_error, API_ERROR_TYPE_VALIDATION, "Error unpacking method");
    return (-1);
  }

  /* params */
  if (obj->via.array.ptr[3].type != MSGPACK_OBJECT_ARRAY) {
    free_string(req->method);
    error_set(api_error, API_ERROR_TYPE_VALIDATION, "params field has wrong type");
    return (-1);
  }

  params = &obj->via.array.ptr[3];

  if (!params) {
    free_string(req->method);
    error_set(api_error, API_ERROR_TYPE_VALIDATION, "unpack params failed");
    return (-1);
  }

  if (unpack_params(params, &req->params) == -1) {
    free_string(req->method);
    error_set(api_error, API_ERROR_TYPE_VALIDATION, "Error unpacking params");
    return (-1);
  }

  return (0);
}
Esempio n. 16
0
static PyObject *
logreader_tp_iternext(LogReaderObject *self)
{
    int c;
    int what;
    int err = ERR_NONE;
    int lineno = -1;
    int fileno = -1;
    int tdelta = -1;
    PyObject *s1 = NULL, *s2 = NULL;
    PyObject *result = NULL;
#if 0
    unsigned char b0, b1;
#endif

    if (self->logfp == NULL) {
        PyErr_SetString(ProfilerError,
                        "cannot iterate over closed LogReader object");
        return NULL;
    }

restart:
    /* decode the record type */
    if ((c = fgetc(self->logfp)) == EOF) {
        fclose(self->logfp);
        self->logfp = NULL;
        return NULL;
    }
    what = c & WHAT_OTHER;
    if (what == WHAT_OTHER)
        what = c; /* need all the bits for type */
    else
        ungetc(c, self->logfp); /* type byte includes packed int */

    switch (what) {
    case WHAT_ENTER:
        err = unpack_packed_int(self, &fileno, 2);
        if (!err) {
            err = unpack_packed_int(self, &lineno, 0);
            if (self->frametimings && !err)
                err = unpack_packed_int(self, &tdelta, 0);
        }
        break;
    case WHAT_EXIT:
        err = unpack_packed_int(self, &tdelta, 2);
        break;
    case WHAT_LINENO:
        err = unpack_packed_int(self, &lineno, 2);
        if (self->linetimings && !err)
            err = unpack_packed_int(self, &tdelta, 0);
        break;
    case WHAT_ADD_INFO:
        err = unpack_add_info(self);
        break;
    case WHAT_DEFINE_FILE:
        err = unpack_packed_int(self, &fileno, 0);
        if (!err) {
            err = unpack_string(self, &s1);
            if (!err) {
                Py_INCREF(Py_None);
                s2 = Py_None;
            }
        }
        break;
    case WHAT_DEFINE_FUNC:
        err = unpack_packed_int(self, &fileno, 0);
        if (!err) {
            err = unpack_packed_int(self, &lineno, 0);
            if (!err)
                err = unpack_string(self, &s1);
        }
        break;
    case WHAT_LINE_TIMES:
        if ((c = fgetc(self->logfp)) == EOF)
            err = ERR_EOF;
        else {
            self->linetimings = c ? 1 : 0;
            goto restart;
        }
        break;
    case WHAT_FRAME_TIMES:
        if ((c = fgetc(self->logfp)) == EOF)
            err = ERR_EOF;
        else {
            self->frametimings = c ? 1 : 0;
            goto restart;
        }
        break;
    default:
        err = ERR_BAD_RECTYPE;
    }
    if (err == ERR_BAD_RECTYPE) {
        PyErr_SetString(PyExc_ValueError,
                        "unknown record type in log file");
    }
    else if (err == ERR_EOF) {
        eof_error(self);
    }
    else if (!err) {
        result = PyTuple_New(4);
        if (result == NULL)
            return NULL;
        PyTuple_SET_ITEM(result, 0, PyInt_FromLong(what));
        PyTuple_SET_ITEM(result, 2, PyInt_FromLong(fileno));
        if (s1 == NULL)
            PyTuple_SET_ITEM(result, 1, PyInt_FromLong(tdelta));
        else
            PyTuple_SET_ITEM(result, 1, s1);
        if (s2 == NULL)
            PyTuple_SET_ITEM(result, 3, PyInt_FromLong(lineno));
        else
            PyTuple_SET_ITEM(result, 3, s2);
    }
    /* The only other case is err == ERR_EXCEPTION, in which case the
     * exception is already set.
     */
#if 0
    b0 = self->buffer[self->index];
    b1 = self->buffer[self->index + 1];
    if (b0 & 1) {
        /* This is a line-number event. */
        what = PyTrace_LINE;
        lineno = ((b0 & ~1) << 7) + b1;
        self->index += 2;
    }
    else {
        what = (b0 & 0x0E) >> 1;
        tdelta = ((b0 & 0xF0) << 4) + b1;
        if (what == PyTrace_CALL) {
            /* we know there's a 2-byte file ID & 2-byte line number */
            fileno = ((self->buffer[self->index + 2] << 8)
                      + self->buffer[self->index + 3]);
            lineno = ((self->buffer[self->index + 4] << 8)
                      + self->buffer[self->index + 5]);
            self->index += 6;
        }
        else
            self->index += 2;
    }
#endif
    return result;
}
Esempio n. 17
0
static void tmate_notify(struct tmate_unpacker *uk)
{
	char *msg = unpack_string(uk);
	tmate_status_message("%s", msg);
	free(msg);
}
Esempio n. 18
0
void unpack_local_force_data (entity *en, pack_modes mode)
{

	int
		count,
		loop;

	force
		*raw;

	campaign_criteria_type
		*last_campaign_criteria,
		*campaign_criteria;

	ASSERT ((mode >= 0) && (mode < NUM_PACK_MODES));

	ASSERT (en);

	raw = (force *) get_local_entity_data (en);
		
	switch (mode)
	{
		////////////////////////////////////////
		case PACK_MODE_SERVER_SESSION:
		////////////////////////////////////////
		{
         unpack_string (en, STRING_TYPE_FORCE_NAME, raw->force_name);

			// keysite_force
		
			// pilot root
		
			unpack_list_root (en, LIST_TYPE_DIVISION, &raw->division_root);
	
			unpack_list_root (en, LIST_TYPE_CAMPAIGN_OBJECTIVE, &raw->campaign_objective_root);
	
			// air_registry_root
			// ground_registry_root
			// sea_registry_root
	
//			unpack_list_root (en, LIST_TYPE_INDEPENDENT_GROUP, &raw->independent_group_root);
	
			// force_link
		
			// update link
		
			// task generation //////////////////////////////////////////////
		
			for (loop = 0; loop < NUM_ENTITY_SUB_TYPE_TASKS; loop ++)
			{
				raw->task_generation [loop].valid = unpack_int_value (en, INT_TYPE_VALID);

				raw->task_generation [loop].created = unpack_int_value (en, INT_TYPE_TASK_GENERATION);
			}
			/////////////////////////////////////////////////////////////////
		
			// campaign criteria ////////////////////////////////////////////
		
			count = unpack_int_value (en, INT_TYPE_CAMPAIGN_CRITERIA_COUNT);
	
			last_campaign_criteria = NULL;
	
			while (count)
			{
	
				campaign_criteria = (campaign_criteria_type *) malloc_heap_mem (sizeof (campaign_criteria_type));
	
				memset (campaign_criteria, 0, sizeof (campaign_criteria_type));
		
				campaign_criteria->criteria_type = unpack_int_value (en, INT_TYPE_CAMPAIGN_CRITERIA_TYPE);
		
				campaign_criteria->valid = unpack_int_value (en, INT_TYPE_VALID);
		
				campaign_criteria->result = unpack_int_value (en, INT_TYPE_CAMPAIGN_CRITERIA_RESULT);
		
				campaign_criteria->value1 = unpack_int_value (en, INT_TYPE_CAMPAIGN_CRITERIA_VALUE);
		
				campaign_criteria->value2 = unpack_int_value (en, INT_TYPE_CAMPAIGN_CRITERIA_VALUE);
		
				campaign_criteria->value3 = unpack_int_value (en, INT_TYPE_CAMPAIGN_CRITERIA_VALUE);
		
				campaign_criteria->value4 = unpack_int_value (en, INT_TYPE_CAMPAIGN_CRITERIA_VALUE);
		
				campaign_criteria->next = last_campaign_criteria;
	
				raw->campaign_criteria = campaign_criteria;
	
				last_campaign_criteria = campaign_criteria;
	
				count --;
			}
			/////////////////////////////////////////////////////////////////
		
			// force_info_criteria
		
			for (loop = 0; loop < NUM_FORCE_INFO_CATAGORIES; loop ++)
			{
				raw->force_info_current_hardware [loop] = unpack_int_value (en, INT_TYPE_VALUE);
		
				raw->force_info_reserve_hardware [loop] = unpack_int_value (en, INT_TYPE_VALUE);
			}
			/////////////////////////////////////////////////////////////////
	
			for (loop = 0; loop < NUM_ENTITY_SUB_TYPE_GROUPS; loop ++)
			{
				raw->kills [loop] = unpack_int_value (en, INT_TYPE_VALUE);
				raw->losses [loop] = unpack_int_value (en, INT_TYPE_VALUE);
//				raw->group_count [loop] = unpack_int_value (en, INT_TYPE_VALUE);
			}

			raw->sleep = unpack_float_value (en, FLOAT_TYPE_SLEEP);
		
			raw->force_attitude = unpack_int_value (en, INT_TYPE_FORCE_ATTITUDE);
		
			// sector_count
		
			raw->colour = unpack_int_value (en, INT_TYPE_COLOUR);
		
			raw->side = unpack_int_value (en, INT_TYPE_SIDE);
	
			break;
		}
		////////////////////////////////////////
		case PACK_MODE_CLIENT_SESSION:
		////////////////////////////////////////
		{
			//
			// create entity
			//

			debug_assert (get_free_entity (get_local_entity_safe_index (en)));

			set_local_entity_type (en, ENTITY_TYPE_FORCE);

			raw = (force *) malloc_fast_mem (sizeof (force));

			set_local_entity_data (en, raw);

			memset (raw, 0, sizeof (force));

			//
			// unpack data (in exactly the same order as the data was packed)
			//

         unpack_string (en, STRING_TYPE_FORCE_NAME, raw->force_name);

			// keysite_force
	
			unpack_list_root (en, LIST_TYPE_PILOT, &raw->pilot_root);

			unpack_list_root (en, LIST_TYPE_DIVISION, &raw->division_root);

			unpack_list_root (en, LIST_TYPE_CAMPAIGN_OBJECTIVE, &raw->campaign_objective_root);

			//	air_registry_root
			//	ground_registry_root
			//	sea_registry_root

//			unpack_list_root (en, LIST_TYPE_INDEPENDENT_GROUP, &raw->independent_group_root);
	
			unpack_list_link (en, LIST_TYPE_FORCE, &raw->force_link);

			// update_link

			////////////////////////////////////////////
			// task_generation
			for (loop = 0; loop < NUM_ENTITY_SUB_TYPE_TASKS; loop ++)
			{
				raw->task_generation [loop].valid = unpack_int_value (en, INT_TYPE_VALID);

				raw->task_generation [loop].created = unpack_int_value (en, INT_TYPE_TASK_GENERATION);
			}
			////////////////////////////////////////////

			////////////////////////////////////////////
			// campaign criteria 
			raw->campaign_criteria = NULL;

			count = unpack_int_value (en, INT_TYPE_CAMPAIGN_CRITERIA_COUNT);

			while (count)
			{

				count --;

				campaign_criteria = (campaign_criteria_type *) malloc_heap_mem (sizeof (campaign_criteria_type));

				memset (campaign_criteria, 0, sizeof (campaign_criteria_type));

				campaign_criteria->next = raw->campaign_criteria;

				raw->campaign_criteria = campaign_criteria;

				campaign_criteria->criteria_type = unpack_int_value (en, INT_TYPE_CAMPAIGN_CRITERIA_TYPE);

				campaign_criteria->valid = unpack_int_value (en, INT_TYPE_VALID);

				campaign_criteria->result = unpack_int_value (en, INT_TYPE_CAMPAIGN_CRITERIA_RESULT);

				campaign_criteria->value1 = unpack_int_value (en, INT_TYPE_CAMPAIGN_CRITERIA_VALUE);

				campaign_criteria->value2 = unpack_int_value (en, INT_TYPE_CAMPAIGN_CRITERIA_VALUE);

				campaign_criteria->value3 = unpack_int_value (en, INT_TYPE_CAMPAIGN_CRITERIA_VALUE);

				campaign_criteria->value4 = unpack_int_value (en, INT_TYPE_CAMPAIGN_CRITERIA_VALUE);
			}
			/////////////////////////////////////////////////////////////////

			////////////////////////////////////////////
			// force_info_criteria
			for (loop = 0; loop < NUM_FORCE_INFO_CATAGORIES; loop ++)
			{
				raw->force_info_current_hardware [loop] = unpack_int_value (en, INT_TYPE_VALUE);

				raw->force_info_reserve_hardware [loop] = unpack_int_value (en, INT_TYPE_VALUE);
			}
			// force_info_criteria

			for (loop = 0; loop < NUM_ENTITY_SUB_TYPE_GROUPS; loop ++)
			{
				raw->kills [loop] = unpack_int_value (en, INT_TYPE_VALUE);
				raw->losses [loop] = unpack_int_value (en, INT_TYPE_VALUE);
//				raw->group_count [loop] = unpack_int_value (en, INT_TYPE_VALUE);
			}

			raw->sleep = unpack_float_value (en, FLOAT_TYPE_SLEEP);

			raw->force_attitude = unpack_int_value (en, INT_TYPE_FORCE_ATTITUDE);

			raw->sector_count = unpack_int_value (en, INT_TYPE_FORCE_SECTOR_COUNT);

			raw->colour = unpack_int_value (en, INT_TYPE_COLOUR);

			raw->side = unpack_int_value (en, INT_TYPE_SIDE);

			insert_local_entity_into_parents_child_list (en, LIST_TYPE_UPDATE, get_update_entity (), NULL);

			break;
		}
		////////////////////////////////////////
		case PACK_MODE_BROWSE_SESSION:
		////////////////////////////////////////
		{
			//
			// create entity
			//

			debug_assert (get_free_entity (get_local_entity_safe_index (en)));

			set_local_entity_type (en, ENTITY_TYPE_FORCE);

			raw = (force *) malloc_fast_mem (sizeof (force));

			set_local_entity_data (en, raw);

			memset (raw, 0, sizeof (force));

			//
			// unpack data (in exactly the same order as the data was packed)
			//

         unpack_string (en, STRING_TYPE_FORCE_NAME, raw->force_name);

			// keysite_force_root

			unpack_list_root (en, LIST_TYPE_PILOT, &raw->pilot_root);

			unpack_list_link (en, LIST_TYPE_FORCE, &raw->force_link);

			// update_link

			// task_generation

			// campaign_criteria

			// force_info_catagories

			// sleep

			raw->force_attitude = unpack_int_value (en, INT_TYPE_FORCE_ATTITUDE);

			raw->colour = unpack_int_value (en, INT_TYPE_COLOUR);

			raw->side = unpack_int_value (en, INT_TYPE_SIDE);

			break;
		}
	}
}
Esempio n. 19
0
bool
bresultfile::open()
{
    if( m_fp != NULL )
    {
        fseek( m_fp, 0L, SEEK_SET );
    }

    m_header.version = RESULT_CUR_VERSION;
    m_header.format = 0;
    m_header.snp_names_length = 0;
    m_header.col_names_length = 0;
    m_header.num_pairs = 0;
    m_header.num_float_cols = 0;

    m_fp = fopen( m_path.c_str( ), m_mode.c_str( ) );
    if( m_fp == NULL )
    {
        return false;
    }

    if( m_mode == "r" )
    {
        size_t bytes_read = fread( &m_header, sizeof( result_header ), 1, m_fp );
        if( bytes_read != 1 || m_header.version != RESULT_CUR_VERSION )
        {
            fclose( m_fp );
            m_fp = NULL;
            return false;
        }

        char *buffer = (char *) malloc( m_header.snp_names_length );
        bytes_read = fread( buffer, 1, m_header.snp_names_length, m_fp );
        if( bytes_read != m_header.snp_names_length )
        {
            free( buffer );
            fclose( m_fp );
            m_fp = NULL;
            return false;
        }

        m_snp_names = unpack_string( buffer );
        free( buffer );

        buffer = (char *) malloc( m_header.col_names_length );
        bytes_read = fread( buffer, 1, m_header.col_names_length, m_fp );
        if( bytes_read != m_header.col_names_length )
        {
            free( buffer );
            fclose( m_fp );
            m_fp = NULL;
            return false;
        }

        m_col_names = unpack_string( buffer );
    }
    else
    {
        return set_header( m_col_names );
    }

    return m_fp != NULL;
}
Esempio n. 20
0
static int unpack_string64(char *p, uint8_t * buf)
{
	return unpack_string(p, buf, 64);
}
Esempio n. 21
0
string_packet* unpack_string_packet(serial input, string_packet* str) {
  str->str = unpack_string(input, str->str, &str->len);
  return (str);
}
Esempio n. 22
0
static void unpack_local_data (entity *en, entity_types type, pack_modes mode)
{
   ASSERT ((mode >= 0) && (mode < NUM_PACK_MODES));

   switch (mode)
   {
      ////////////////////////////////////////
      case PACK_MODE_SERVER_SESSION:
      ////////////////////////////////////////
		{
			break;
		}
      ////////////////////////////////////////
      case PACK_MODE_CLIENT_SESSION:
      ////////////////////////////////////////
      {
         int
            index;

         pilot
            *raw;

         //
         // create entity
         //

         index = unpack_entity_safe_index ();

         en = get_free_entity (index);

         set_local_entity_type (en, type);

         raw = malloc_fast_mem (sizeof (pilot));

         set_local_entity_data (en, raw);

         memset (raw, 0, sizeof (pilot));

         //
         // unpack data (in exactly the same order as the data was packed)
         //

         raw->sub_type = unpack_int_value (en, INT_TYPE_ENTITY_SUB_TYPE);

         unpack_string (en, STRING_TYPE_PILOTS_NAME, raw->pilots_name);

         raw->rank = unpack_int_value (en, INT_TYPE_PILOT_RANK);

         raw->kills = unpack_int_value (en, INT_TYPE_KILLS);

         raw->unique_id = unpack_int_value (en, INT_TYPE_UNIQUE_ID);

			raw->crew_role = CREW_ROLE_PILOT;

         unpack_list_root (en, LIST_TYPE_PILOT_LOCK, &raw->pilot_lock_root);

         unpack_list_link (en, LIST_TYPE_AIRCREW, &raw->aircrew_link);

         unpack_list_link (en, LIST_TYPE_PILOT, &raw->pilot_link);

         unpack_list_link (en, LIST_TYPE_PLAYER_TASK, &raw->player_task_link);

         raw->side = unpack_int_value (en, INT_TYPE_SIDE);

			raw->difficulty_level = unpack_int_value (en, INT_TYPE_DIFFICULTY_LEVEL);

         break;
      }
      ////////////////////////////////////////
      case PACK_MODE_BROWSE_SESSION:
      ////////////////////////////////////////
      {
         int
            index;

         pilot
            *raw;

         //
         // create entity
         //

         index = unpack_entity_safe_index ();

         en = get_free_entity (index);

         set_local_entity_type (en, type);

         raw = malloc_fast_mem (sizeof (pilot));

         set_local_entity_data (en, raw);

         memset (raw, 0, sizeof (pilot));

         //
         // unpack data (in exactly the same order as the data was packed)
         //

         raw->sub_type = unpack_int_value (en, INT_TYPE_ENTITY_SUB_TYPE);

         unpack_string (en, STRING_TYPE_PILOTS_NAME, raw->pilots_name);

         raw->rank = unpack_int_value (en, INT_TYPE_PILOT_RANK);

         raw->kills = unpack_int_value (en, INT_TYPE_KILLS);

         raw->unique_id = unpack_int_value (en, INT_TYPE_UNIQUE_ID);

			raw->crew_role = CREW_ROLE_PILOT;

			// aircrew_link

         unpack_list_link (en, LIST_TYPE_PILOT, &raw->pilot_link);

         raw->side = unpack_int_value (en, INT_TYPE_SIDE);

         break;
      }
      ////////////////////////////////////////
      case PACK_MODE_UPDATE_ENTITY:
      ////////////////////////////////////////
      {
         //
         // always use access functions to set the data
         //

         break;
      }
   }
}