vendredi 8 mai 2015

Asterisk create_stasis_message Invalid magic number

I stuck to send a stasis_message for a self made module to the ARI.

I try to use the code example from the documentation :

http://ift.tt/1EhASX6

I use asterisk 13 instead example (who use the 12), and some signature are changed.

Here is the initialisation :

struct stasis_topic *foo_topic;

static int load_module(void)
{
    //  Register to stasis.
    stasis_app_register(app, callback_stasis, 0);
    // Create a bridge on witch ARI can conenct.
    stasis_app_bridge_create("mixing", app, "11000");

    // Create the topic
    foo_topic = stasis_topic_create(app);
    return ast_register_application_xml(app, exec);
}

And the code method who is calling when phone arrive :

static int exec()
{
    publish_foo();
}

static void publish_foo()
{
   printf("Trace 1\n");

   char* test =  "dataToSend";
   RAII_VAR(struct stasis_message_type*, foo_type, NULL, ao2_cleanup);
   stasis_message_type_create(app, NULL, &foo_type);

   RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
   printf("Trace 3\n");
   msg = stasis_message_create(type, test);

   if (!msg)
      return;

    stasis_publish(foo_topic, msg);

    printf("PASSING MESSAGE 4\n");
}

I always get message like :

bad magic number 0x332065 for object 0x7f2ea5ab8ec5

And this error appends in the method stasis_create_message().

[Edit]

I do not understand the error and the cause any help is appreciated.

As suggest by arheops, there is the function who are created problem. Apparently my object cannot be convert to an Asterisk object. Probably the structure I need to send to the create_message_function must be on a astobj2 type.

static struct astobj2 *INTERNAL_OBJ(void *user_data)
{
        struct astobj2 *p;

        if (!user_data) {
                ast_log(LOG_ERROR, "user_data is NULL\n");
                return NULL;
        }

        p = (struct astobj2 *) ((char *) user_data - sizeof(*p));
        if (AO2_MAGIC != p->priv_data.magic) {
                if (p->priv_data.magic) {
                        ast_log(LOG_ERROR, "bad magic number 0x%x for object %p\n",
                                p->priv_data.magic, user_data);
                } else {
                        ast_log(LOG_ERROR,
                                "bad magic number for object %p. Object is likely destroyed.\n",
                                user_data);
                }
                ast_assert(0);
                return NULL;
        }

        return p;
}

And the struct of astobj2 definition :

struct astobj2 
{    
   struct __priv_data priv_data;
   void *user_data[0];
};

I tried to create a a2object like describe here :

enter link description here

And I get an error :

*** Error in `asterisk': free(): invalid pointer:

Thanks

Aucun commentaire:

Enregistrer un commentaire