Exemplo n.º 1
0
void mrp_fragbuf_destroy(mrp_fragbuf_t *buf)
{
    if (buf != NULL) {
        mrp_free(buf->data);
        mrp_free(buf);
    }
}
Exemplo n.º 2
0
static void resource_set_lua_destroy(void *data)
{
    resource_set_lua_t *rset = (resource_set_lua_t *) data;

    mrp_debug("lua destructor for rset %p", rset);

    /* remove resources from the resource set -- they are finally cleaned from
     * their own lua destructors */

    if (rset->resource_set)
        mrp_resource_set_destroy(rset->resource_set);

    if (rset->resources) {
        mrp_debug("deleting htbl at %p", rset->resources);
        mrp_htbl_destroy(rset->resources, TRUE);
        rset->resources = NULL;
    }

    mrp_free(rset->zone);
    mrp_free(rset->application_class);

    if (rset->initialized) {
       n_sets--;

        if (n_sets == 0) {
            mrp_resource_client_destroy(client);
            client = NULL;
        }
    }

    return;
}
Exemplo n.º 3
0
static void player_free(void *key, void *object)
{
    player_t *player = (player_t *)object;
    context_t *ctx;
    srs_plugin_t *pl;
    srs_context_t *srs;
    pa_mainloop_api *api;


    if (strcmp(key, player->name))
        mrp_log_error("mpris2-client: corrupt hashtable (key '%s')",
                      (char *)key);
    else {
        if (player->timer && (ctx = player->ctx) && (pl = ctx->plugin) &&
            (srs = pl->srs) && (api = srs->pa))
        {
            api->time_free(player->timer);
        }

        mrp_free((void *)player->name);
        mrp_free((void *)player->service);
        mrp_free((void *)player->object);
        mrp_free((void *)player);
        playlist_free(player->nlist, player->lists);
    }
}
Exemplo n.º 4
0
static void buf_free(rnc_buf_t *b)
{
    if (b == NULL)
        return;

    mrp_free(b->name);
    mrp_free(b);
}
Exemplo n.º 5
0
static void htbl_free_resource(void *key, void *object)
{
    resource_lua_t *res = (resource_lua_t *) object;

    MRP_UNUSED(key);

    mrp_free(res->resource_name);
    mrp_free(res);
}
Exemplo n.º 6
0
static int basic_tests(int n)
{
    void **ptrs;
    char   buf[1024], *p;
    int    i;

    mrp_mm_config(MRP_MM_DEBUG);

    ptrs = mrp_allocz(n * sizeof(*ptrs));

    if (ptrs == NULL)
        fatal("Failed to allocate pointer table.");

    for (i = 0; i < n; i++) {
        snprintf(buf, sizeof(buf), "#%d: message number %d (0x%x)", i, i, i);

        p = ptrs[i] = mrp_strdup(buf);

        if (p != NULL) {
            if (!strcmp(buf, p)) {
                printf("'%s' was duplicated as '%s'\n", buf, p);
            }
            else {
                printf("'%s' was incorrectly duplicated as '%s'\n", buf, p);
                return FALSE;
            }
        }
        else {
            printf("failed to duplicate '%s'\n", buf);
            return FALSE;
        }
    }

    mrp_mm_check(stdout);

    for (i = 0; i < n; i += 2) {
        mrp_free(ptrs[i]);
        ptrs[i] = NULL;
    }

    mrp_mm_check(stdout);

    for (i = 0; i < n; i++) {
        mrp_free(ptrs[i]);
        ptrs[i] = NULL;
    }

    mrp_mm_check(stdout);

    mrp_free(ptrs);

    mrp_mm_check(stdout);

    return TRUE;
}
void options_destroy(context_t *ctx)
{
    options_t *opts;
    options_decoder_t*dec;
    size_t i;

    if (ctx && (opts = ctx->opts)) {
        ctx->opts = NULL;

        if (opts->decs) {
            for (i = 0; i < opts->ndec;  i++) {
                dec = opts->decs + i;
                mrp_free((void *)dec->name);
                mrp_free((void *)dec->hmm);
                mrp_free((void *)dec->lm);
                mrp_free((void *)dec->dict);
                mrp_free((void *)dec->fsg);
            }
        }

        mrp_free((void *)opts->srcnam);
        mrp_free((void *)opts->audio);
        mrp_free((void *)opts->logfn);

        mrp_free(opts);
    }
}
Exemplo n.º 8
0
void dbusif_destroy(context_t *ctx)
{
    dbusif_t *dbusif;

    if (ctx && (dbusif = ctx->dbusif)) {
        ctx->dbusif = NULL;

        mrp_dbus_unref(dbusif->dbus);

        mrp_free((void *)dbusif->bustype);
        mrp_free((void *)dbusif);
    }
}
Exemplo n.º 9
0
static client_t *create_client(server_t *s, mrp_transport_t *lt)
{
    mrp_transport_t *t;
    client_t        *c;

    c = mrp_allocz(sizeof(*c));

    if (c != NULL) {
        mrp_list_init(&c->hook);

        c->s  = s;
        c->id = s->next_id++;
        c->t  = mrp_transport_accept(lt, c, MRP_TRANSPORT_REUSEADDR);

        if (c->t != NULL) {
            mrp_list_append(&s->clients, &c->hook);

            return c;
        }

        mrp_free(c);
    }
    else {
        t = mrp_transport_accept(lt, NULL, MRP_TRANSPORT_REUSEADDR);
        mrp_transport_destroy(t);
    }

    return NULL;
}
Exemplo n.º 10
0
mrp_res_string_array_t * mrp_res_list_attribute_names(mrp_res_context_t *cx,
        const mrp_res_resource_t *res)
{
    int i;
    mrp_res_string_array_t *ret;

    if (!cx || !res)
        return NULL;

    ret = mrp_allocz(sizeof(mrp_res_string_array_t));

    if (!ret)
        return NULL;

    ret->num_strings = res->priv->num_attributes;
    ret->strings = mrp_allocz_array(const char *, res->priv->num_attributes);

    if (!ret->strings) {
        mrp_free(ret);
        return NULL;
    }

    for (i = 0; i < res->priv->num_attributes; i++) {
        ret->strings[i] = mrp_strdup(res->priv->attrs[i].name);
        if (!ret->strings[i]) {
            ret->num_strings = i;
            mrp_res_free_string_array(ret);
            return NULL;
        }
    }

    return ret;
}
Exemplo n.º 11
0
mrp_mainloop_t *glib_mainloop_create(test_config_t *cfg)
{
    glib_config_t  *glib;
    mrp_mainloop_t *ml;

    glib = mrp_allocz(sizeof(*glib));

    if (glib != NULL) {
        glib->gml = g_main_loop_new(NULL, FALSE);
        ml        = mrp_mainloop_glib_get(glib->gml);

        if (ml != NULL) {
            cfg->glib = glib;
            cfg->ml   = ml;

            return ml;
        }
        else {
            g_main_loop_unref(glib->gml);
            mrp_free(glib);
        }
    }

    return NULL;
}
Exemplo n.º 12
0
int mrp_attribute_set_values(mrp_attr_t      *values,
                             uint32_t          nattr,
                             mrp_attr_def_t   *defs,
                             mrp_attr_value_t *attrs)
{
    mrp_attr_def_t *adef;
    mrp_attr_value_t *vsrc;
    mrp_attr_value_t *vdst;
    uint32_t i;


    MRP_ASSERT(!nattr || (nattr > 0 && defs && attrs),
               "invalid arguments");

    for (i = 0;  i < nattr;  i++) {
        adef = defs  + i;
        vdst = attrs + i;

        if (!(adef->access & MRP_RESOURCE_WRITE) ||
            !(vsrc = get_attr_value_from_list(values, adef->name, adef->type)))
            vsrc = &adef->value; /* default value */

        if (adef->type !=  mqi_string)
            *vdst = *vsrc;
        else if (vdst->string != vsrc->string) {
            /* if the string is not the same, change it */
            mrp_free((void *)vdst->string);
            if (!(vdst->string = mrp_strdup(vsrc->string)))
                return -1;
        }
    }

    return 0;
}
Exemplo n.º 13
0
void mrp_resource_set_free_attribute(mrp_attr_t *attr)
{
    if (!attr)
        return;

    mrp_free(attr);
}
Exemplo n.º 14
0
int mrp_attribute_copy_definitions(mrp_attr_def_t *from, mrp_attr_def_t *to)
{
    mrp_attr_def_t *s, *d;

    MRP_ASSERT(to,"invalid argument");

    if (from) {
        for (s = from, d = to;   s->name;   s++, d++) {

            if (!(d->name = mrp_strdup(s->name)))
                goto no_memory;

            d->access = s->access;

            if ((d->type = s->type) != mqi_string)
                d->value = s->value;
            else {
                if (!(d->value.string = mrp_strdup(s->value.string))) {
                    mrp_free((void *)d->name);
                    memset(d, 0, sizeof(*d));
                    goto no_memory;
                }
            }
        }
    }

    return 0;

 no_memory:
    mrp_log_error("Memory alloc failure. Can't copy attribute definition");
    return -1;
}
Exemplo n.º 15
0
void clients_player_disappeared(context_t *ctx, const char *name)
{
    clients_t *clients;
    player_t *player, *removed;

    if (ctx && (clients = ctx->clients) && clients->player.name) {
        if ((player = mrp_htbl_lookup(clients->player.name, (void *)name))) {
            removed = mrp_htbl_remove(clients->player.addr,
                                      (void *)player->address,
                                      FALSE);
            if (player != removed) {
                mrp_log_error("mpris2 client: confused with data structures "
                              "when removing '%s'", player->address);
            }
            else {
                mrp_free((void *)player->address);
                player->address = NULL;
                player->state = UNKNOWN;
                player->ready = false;

                playlist_free(player->nlist, player->lists);
                player->nlist = 0;
                player->lists = NULL;
                player->active_list = NULL;

                mrp_log_info("mrpis2 client '%s' disappeared", name);
            }
        }
    }
}
Exemplo n.º 16
0
static int set_address(transport_lua_t *t, const char *address,
                       char *err, size_t elen, int overwrite)
{
    MRP_LUA_ERRUSE(err, elen);

    if (t->address != NULL) {
        if (t->address == address) {
            if (t->alen > 0 && t->atype != NULL)
                return 1;
        }
        else {
            if (!overwrite)
                return mrp_lua_error(-1, t->L,
                                     "address already set ('%s')", t->address);
        }
    }

    if (t->address != address) {
        mrp_free(t->address);
        t->address = NULL;
    }

    t->atype = NULL;
    t->alen  = 0;

    if (address == NULL)
        return 1;

    if ((t->address = mrp_strdup(address)) == NULL)
        return mrp_lua_error(-1, t->L,
                             "failed to store address '%s'", address);

    t->alen = mrp_transport_resolve(NULL, t->address, &t->addr,
                                    sizeof(t->addr), &t->atype);

    if (t->alen <= 0) {
        if (address != t->address)
            mrp_free(t->address);

        t->atype = NULL;
        t->alen  = 0;

        return mrp_lua_error(-1, t->L, "failed to resolve '%s'", address);
    }

    return 0;
}
Exemplo n.º 17
0
static void destroy_client(client_t *c)
{
    mrp_list_delete(&c->hook);

    mrp_transport_destroy(c->t);
    client_destroy(c->c);

    mrp_free(c);
}
Exemplo n.º 18
0
void mrp_attribute_array_free(mrp_res_attribute_t *arr,
        uint32_t dim)
{
    uint32_t i;
    mrp_res_attribute_t *attr;

    if (arr) {
        for (i = 0; i < dim; i++) {
            attr = arr + i;

            mrp_free((void *)attr->name);

            if (attr->type == mrp_string)
                mrp_free((void *)attr->string);
        }
        mrp_free(arr);
    }
}
Exemplo n.º 19
0
static void attribute_lua_destroy(void *data)
{
    attribute_lua_t *attribute = (attribute_lua_t *) data;

    mrp_debug("> attribute_destroy");

    mrp_free(attribute);
    return;
}
Exemplo n.º 20
0
static void reset_commands(client_t *c)
{
    int i;

    if (c->registered){
        print(c, "You need to unregister first to modify commands.");
        return;
    }

    for (i = 0; i < c->ncommand; i++)
        mrp_free(c->commands[i]);
    mrp_free(c->commands);

    c->commands = NULL;
    c->ncommand = 0;

    print(c, "Commands resetted, no current commands.");
}
Exemplo n.º 21
0
void mrp_fragbuf_reset(mrp_fragbuf_t *buf)
{
    if (buf != NULL) {
        mrp_free(buf->data);
        buf->data = NULL;
        buf->size = 0;
        buf->used = 0;
    }
}
Exemplo n.º 22
0
static void destroy_input(srs_plugin_t *plugin)
{
    context_t *ctx = (context_t *)plugin->plugin_data;

    mrp_log_info("destroying input plugin");

    if (ctx) {
        mrp_free(ctx);
    }
}
Exemplo n.º 23
0
static void cdpa_close(rnc_dev_t *dev)
{
    cdpa_t *cdpa = dev->data;

    mrp_debug("closing device");

    if (cdpa == NULL)
        return;

    /* Hmm... what is the opposite of cdio_open ? */

    if (cdpa->cdpa)
        cdio_paranoia_free(cdpa->cdpa);

    if (cdpa->cdio)
        cdio_cddap_close(cdpa->cdda);

    mrp_free(cdpa->errmsg);
    mrp_free(cdpa);
}
Exemplo n.º 24
0
Arquivo: debug.c Projeto: 01org/murphy
static int add_rule(const char *func, const char *file, int line, int off)
{
    mrp_htbl_t  *ht;
    char        *rule, *r, buf[PATH_MAX * 2];

    if (rules_on == NULL)
        if (!init_rules())
            return FALSE;

    r = rule = NULL;

    if (!off)
        ht = rules_on;
    else
        ht = rules_off;

    if (func != NULL && file == NULL && line == 0) {
        r    = mrp_htbl_lookup(ht, (void *)func);
        rule = (char *)func;
    }
    else if (func != NULL && file != NULL && line == 0) {
        snprintf(buf, sizeof(buf), "%s@%s", func, file);
        r    = mrp_htbl_lookup(ht, (void *)buf);
        rule = buf;
    }
    else if (func == NULL && file != NULL && line == 0) {
        snprintf(buf, sizeof(buf), "@%s", file);
        r    = mrp_htbl_lookup(ht, (void *)buf);
        rule = buf;
    }
    else if (func == NULL && file != NULL && line > 0) {
        snprintf(buf, sizeof(buf), "%s:%d", file, line);
        r    = mrp_htbl_lookup(ht, (void *)buf);
        rule = buf;
    }

    if (r != NULL)
        return FALSE;

    rule = mrp_strdup(rule);
    if (rule == NULL)
        return FALSE;

    if (mrp_htbl_insert(ht, rule, rule)) {
        mrp_debug_stamp++;

        return TRUE;
    }
    else {
        mrp_free(rule);

        return FALSE;
    }
}
Exemplo n.º 25
0
void filter_buffer_destroy(context_t *ctx)
{
    filter_buf_t *filtbuf;

    if (ctx && (filtbuf = ctx->filtbuf)) {
        ctx->filtbuf = NULL;

        mrp_free(filtbuf->buf);

        free(filtbuf);
    }
}
Exemplo n.º 26
0
static void destroy_dbusif(srs_plugin_t *plugin)
{
    srs_context_t *srs = plugin->srs;
    dbusif_t      *dbus = (dbusif_t *)plugin->plugin_data;

    MRP_UNUSED(srs);

    mrp_debug("destroy D-Bus client interface plugin");

    dbusif_cleanup(dbus);
    mrp_free(dbus);
}
Exemplo n.º 27
0
void destroy_domain_control(pdp_t *pdp)
{
    if (pdp != NULL) {
        destroy_proxies(pdp);
        destroy_tables(pdp);
        destroy_transport(pdp->extt);
        destroy_transport(pdp->intt);
        destroy_transport(pdp->wrtt);

        mrp_free(pdp);
    }
}
Exemplo n.º 28
0
void resctl_exit(resctl_t *ctl)
{
    if (ctl != NULL) {
        if (ctl->set != NULL)
            mrp_resource_set_destroy(ctl->set);

        if (ctl->client != NULL)
            mrp_resource_client_destroy(ctl->client);

        mrp_free(ctl);
    }
}
Exemplo n.º 29
0
static void glib_pump_cleanup(void)
{
    if (glib_glue != NULL) {
        mrp_del_subloop(glib_glue->sl);

        g_main_loop_unref(glib_glue->ml);
        g_main_context_unref(glib_glue->mc);

        mrp_free(glib_glue);
        glib_glue = NULL;
    }
}
Exemplo n.º 30
0
static void destroy_wrtc(srs_plugin_t *plugin)
{
    srs_context_t *srs  = plugin->srs;
    wrtc_t        *wrtc = (wrtc_t *)plugin->plugin_data;

    MRP_UNUSED(srs);

    mrp_debug("destroy WRT media client plugin");

    wrtc_cleanup(wrtc);
    mrp_free(wrtc);
}