Example #1
0
/*
 * Free any atoms associated with the value and then free the value
 * itself.
 */
void
pool_value_free(pool_value_t *pv)
{
	if (pv->pv_name)
		atom_free(pv->pv_name);
	if (pv->pv_class == POC_STRING)
		atom_free(pv->pv_u.s);
	free(pv);
}
Example #2
0
static int so_atom_add(session_opt_t *so, const char *id, char *buf, 
    size_t size, void *arg)
{
    atom_t *atom = NULL, *old = NULL;
    size_t new_size, old_found = 0;

    dbg_err_if (so == NULL);
    dbg_err_if (id == NULL);
    dbg_err_if (buf == NULL);

    /* get the old atom associated to this id */
    if(!atoms_get(so->atoms, id, &old))
        old_found = 1;

    /* delete the oldest session if there are already max_count sessions */
    if(so->max_count && atoms_count(so->atoms) - old_found >= so->max_count)
        dbg_err_if(session_delete_oldest(so));

    /* delete the oldest session(s) if we are using already mem_limit bytes */
    if(so->mem_limit)
    {
        warn_err_ifm(size > so->mem_limit, 
            "session size is bigger the memory.limit, save aborted...");
        for(;;)
        {
            /* new_size = size of all atoms + size of the atom we're going to
               add - the size of the atom (if found) we're going to remove */
            new_size = atoms_size(so->atoms) + size - (old ? old->size : 0);
            if(atoms_count(so->atoms) && new_size > so->mem_limit)
                dbg_err_if(session_delete_oldest(so));
            else
                break;
        }
    }

    /* create a new atom */
    dbg_err_if(atom_create(id, buf, size, arg, &atom));

    /* add it to the list */
    dbg_err_if(atoms_add(so->atoms, atom));

    /* remove the old atom associated to this id */
    if(old)
    {
        dbg_err_if(atoms_remove(so->atoms, old));
        atom_free(old);
    }

    return 0;
err:
    if(atom)
        atom_free(atom);
    return ~0;
}
Example #3
0
static atom_p parse_string(parsebuf_p pb, char terminator, int print_mode)
{
  int c, err;
  atom_p a = NULL;
  DEBUG();

  if ((a = atom_alloc_string(print_mode ? operator_string : operator_value, NULL, NULL)) == NULL)
    return NULL;

  while((c = __parsebuf_next(pb)) > 0) {
    if (c == terminator) {
      DEBUG("parsed string atom [%s]", (char *)atom_data(a));
      return a;
    } else if (c == '\\') {
      if ((err = __parse_quote_char(pb)) <= 0) break;
      if (string_append((byte_p *)(&atom_data(a)), err & 0xff)) break;
    } else if (c == '%') {
      if ((err = __parse_hex_char(pb)) <= 0) break;
      if (string_append((byte_p *)(&atom_data(a)), err & 0xff)) break;
    } else {
      if (string_append((byte_p *)(&atom_data(a)), c)) break;
    }
  }
  return atom_free(a);
}
Example #4
0
/*
 * Set the value's data to the supplied uchar_t data. Update the type
 * of the value data to POC_BOOL.
 */
void
pool_value_set_bool(pool_value_t *pv, uchar_t val)
{
	if (pv->pv_class == POC_STRING)
		atom_free(pv->pv_u.s);
	pv->pv_class = POC_BOOL;
	pv->pv_u.b = !!val;	/* Lock value at 0 or 1 */
}
Example #5
0
void
pool_value_set_double(pool_value_t *pv, double val)
{
	if (pv->pv_class == POC_STRING)
		atom_free(pv->pv_u.s);
	pv->pv_class = POC_DOUBLE;
	pv->pv_u.d = val;
}
Example #6
0
/*
 * Set the value's data to the supplied int64_t data. Update the type
 * of the value data to POC_INT.
 */
void
pool_value_set_int64(pool_value_t *pv, int64_t val)
{
	if (pv->pv_class == POC_STRING)
		atom_free(pv->pv_u.s);
	pv->pv_class = POC_INT;
	pv->pv_u.i = val;
}
Example #7
0
/* add an atom to the list of global atoms */
static int session_mem_add(session_opt_t *so, const char *filename, char *buf, 
    size_t size, time_t mtime)
{
    atom_t *atom = NULL;
    enc_ses_mem_t *esm = NULL;
    ppc_t *ppc;
    size_t esize;

    dbg_err_if (so == NULL);
    dbg_err_if (filename == NULL);
    dbg_err_if (buf == NULL);

    if(ctx->pipc)
    {   /* children context */
        ppc = server_get_ppc(ctx->server);
        dbg_err_if(ppc == NULL);

        /* build the encoded parameters structure */
        esize = size + sizeof(enc_ses_mem_t);
        esm = (enc_ses_mem_t*)u_malloc(esize);
        dbg_err_if(esm == NULL);

        /* fill esm fields */
        esm->mtime = time(0);
        esm->size = size;
        dbg_err_if(strlen(filename) > SESSION_FILENAME_MAX_LENGTH); 
        u_strlcpy(esm->filename, filename, sizeof esm->filename);
        memcpy(esm->data, buf, size);

        /* send the command request */
        dbg_err_if(ppc_write(ppc, ctx->pipc, PPC_CMD_MSES_SAVE, 
            (char*)esm, esize) < 0);

        U_FREE(esm);

        /* add it to the local copy of atom list */
        dbg_err_if(so_atom_add(so, filename, buf, size, (void*)mtime));

    } else {
        /* parent context */
        dbg_err_if(so_atom_add(so, filename, buf, size, (void*)mtime));
    }

    return 0;
err:
    U_FREE(esm);
    if(atom)
        atom_free(atom);
    return ~0;
}
Example #8
0
/*
 * Set the name of the value to the supplied name.
 */
int
pool_value_set_name(pool_value_t *pv, const char *name)
{
	if (name == NULL || strlen(name) >= PV_NAME_MAX_LEN) {
		pool_seterror(POE_BADPARAM);
		return (PO_FAIL);
	} else {
		if (pv->pv_name)
			atom_free(pv->pv_name);
		if ((pv->pv_name = atom_string(name)) == NULL)
			return (PO_FAIL);
	}
	return (PO_SUCCESS);
}
Example #9
0
/*
 * Try to make an internal copy of the val, returning PO_SUCCESS or
 * PO_FAIL if the copy works or fails.
 */
int
pool_value_set_string(pool_value_t *pv, const char *val)
{
	if (pv->pv_class == POC_STRING)
		atom_free(pv->pv_u.s);
	pv->pv_class = POC_STRING;
	if (val == NULL || strlen(val) >= PV_VALUE_MAX_LEN) {
		pool_seterror(POE_BADPARAM);
		return (PO_FAIL);
	} else {
		if ((pv->pv_u.s = atom_string(val)) == NULL)
			return (PO_FAIL);
	}
	return (PO_SUCCESS);
}
Example #10
0
int validate_expression(char * n, char * s, expression_callback_t out) {
  parsebuf_t pb;
  atom_p a;
  DEBUG();
  pb.n = n;
  pb.s = s;
  pb.i = 0;
  pb.l = 1;
  pb.c = 1;
  pb._c = -1;
  a = parse_list(&pb, out, 0);
  if (a != NULL) {
    atom_free(a);
    return 0;
  }
  return -1;
}
Example #11
0
static int so_atom_remove(session_opt_t *so, const char *id)
{
    atom_t *atom = NULL;

    dbg_err_if (so == NULL);
    dbg_err_if (id == NULL);

    /* find the atom bound to this session */
    if(atoms_get(so->atoms, id, &atom))
        return 0;

    /* remove it from the list */
    dbg_err_if(atoms_remove(so->atoms, atom));

    atom_free(atom);

    return 0;
err:
    return ~0;
}
Example #12
0
static atom_p parse_list(parsebuf_p pb, expression_callback_t out, int indentation)
{
  int c, i, terminator;
  atom_p first, prev, curr;
  struct __operator * operator;
  parsebuf_t buf;
  DEBUG();

  // Grab the opening parenthesis, or whatever it is
  __consume_whitespace(pb);
  __parsebuf_snapshot(pb, &buf);
  if((c = __parsebuf_next(pb)) == '(') {
    terminator = ')';
  } else if(c == '[') {
    terminator = ']';
  } else if(c == '<') {
    terminator = '>';
  } else if(c == '{') {
    terminator = '}';
  } else {
    splinter_error_return(NULL, "%s invalid list opening @ %d:%d", buf.n, buf.l, buf.c);
  }

  __consume_whitespace(pb);
  if ((operator = __find_closest_token(pb, terminator)) == NULL)
    return NULL;

  __parse_out_indentation(out, indentation);
  __parse_out_char(out, c);
  __parse_out_string(out, operator->token, (int)strlen(operator->token));

  for(first = prev = curr = NULL; 1;) {
    __consume_whitespace(pb);
    i = pb->i;
    __parse_out_char(out, '\n');
    if((c = __parsebuf_next(pb)) <= 0) {
      splinter_error_set("%s missing list closing @ %d:%d", buf.n, pb->l, pb->c);
      return atom_free(first);
    } else if(c == terminator) {
      if ((curr = atom_alloc_list(operator->exec_call, first)) == NULL) {
        return atom_free(first);
      }
      __parse_out_indentation(out, indentation);
      __parse_out_char(out, terminator);
      return curr;
    } else if(c == '0' && (__parsebuf_peek(pb) == 'x' || __parsebuf_peek(pb) == 'X')) {
      __parsebuf_prev(pb);
      curr = parse_hex(pb, operator->mode);
      if (curr != NULL) __parse_out_line(out, pb->s + i, pb->i - i, indentation + 2);
    } else if('0' <= c && c <= '9') {
      __parsebuf_prev(pb);
      curr = (c == '0') ? parse_oct(pb, operator->mode) : parse_uint(pb, operator->mode);
      if (curr != NULL) __parse_out_line(out, pb->s + i, pb->i - i, indentation + 2);
    } else if(c == '-' && ('0' <= __parsebuf_peek(pb) && __parsebuf_peek(pb) <= '9')) {
      __parsebuf_prev(pb);
      curr = parse_int(pb, operator->mode);
      if (curr != NULL) __parse_out_line(out, pb->s + i, pb->i - i, indentation + 2);
    } else if(c == '(' || c == '[' || c == '<' || c == '{') {
      __parsebuf_prev(pb);
      curr = parse_list(pb, out, indentation + 2);
    } else if(c == '\'') {
      curr = parse_string(pb, '\'', operator->mode);
      if (curr != NULL) __parse_out_line(out, pb->s + i, pb->i - i, indentation + 2);
    } else if(c == '"') {
      curr = parse_string(pb, '"', operator->mode);
      if (curr != NULL) __parse_out_line(out, pb->s + i, pb->i - i, indentation + 2);
    } else if (c == '$') {
      __parsebuf_prev(pb);
      curr = parse_variable(pb, terminator, operator->mode);
      if (curr != NULL) __parse_out_line(out, (char *)curr->data, strlen((char *)curr->data), indentation + 2);
    } else if (c == '@') {
      __parsebuf_prev(pb);
      curr = parse_symbol(pb, terminator, operator->mode);
      if (curr != NULL) __parse_out_line(out, pb->s + i, pb->i - i, indentation + 2);
    } else {
      curr = NULL;
    }

    if(curr == NULL) {
      return atom_free(first);
    }

    if(first == NULL) {
      first = prev = curr;
    } else {
      prev->next = curr;
      prev = curr;
    }
  }
}
Example #13
0
static void free_atom(gpointer d, gpointer ud)
{
    atom_free((Atom*) d);
}