Skip to content

Commit

Permalink
aaa_diameter: add parameter to reply callback
Browse files Browse the repository at this point in the history
  • Loading branch information
razvancrainea authored and bogdan-iancu committed Apr 18, 2024
1 parent 079a1dc commit 663e519
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
4 changes: 2 additions & 2 deletions modules/aaa_diameter/diameter_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ typedef int (diameter_send_req_f)(diameter_conn*, int app_id, int code,
/*
Callback run for an asynchornous command reply
*/
typedef int (diameter_reply_cb)(diameter_conn *conn, diameter_reply *reply);
typedef int (diameter_reply_cb)(diameter_conn *conn, diameter_reply *reply, void *param);

/*
Sends an asynchornous diameter request and calls the callback in the reply
*/
typedef int (diameter_send_req_async_f)(diameter_conn*, int app_id, int code,
cJSON *req, diameter_reply_cb *reply_cb);
cJSON *req, diameter_reply_cb *reply_cb, void *reply_param);

/*
Retrieves a JSON from a reply handle
Expand Down
4 changes: 2 additions & 2 deletions modules/aaa_diameter/diameter_api_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
int dm_api_find_cmd(diameter_conn *conn, int cmd_code);
int dm_api_send_req(diameter_conn *conn, int app_id, int cmd_code, cJSON *req,
diameter_reply *reply);
int dm_api_send_req_async(diameter_conn *conn, int app_id, int cmd_code, cJSON *req,
diameter_reply_cb *reply);
int dm_api_send_req_async(diameter_conn *conn, int app_id, int cmd_code,
cJSON *req, diameter_reply_cb *reply, void *reply_param);
cJSON *dm_api_get_reply(diameter_reply *rpl);
int dm_api_get_reply_status(diameter_reply *rpl);
void dm_api_free_reply(diameter_reply *rpl);
Expand Down
23 changes: 12 additions & 11 deletions modules/aaa_diameter/dm_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ static int dm_avp_inttype[] = {
AAA_TYPE_FLOAT64,
};

static struct dm_cond *dm_get_cond(int type, diameter_reply_cb *cb)
static struct dm_cond *dm_get_cond(int type, diameter_reply_cb *cb, void *param)
{
struct dm_cond *cond = shm_malloc(sizeof *cond);
if (!cond) {
Expand All @@ -130,7 +130,8 @@ static struct dm_cond *dm_get_cond(int type, diameter_reply_cb *cb)
case DM_TYPE_CB:
if (!cb)
LM_WARN("no callback specified\n");
cond->sync.cb = cb;
cond->sync.cb.f = cb;
cond->sync.cb.p = param;
break;
}

Expand All @@ -139,7 +140,7 @@ static struct dm_cond *dm_get_cond(int type, diameter_reply_cb *cb)

int dm_init_reply_cond(int proc_rank)
{
my_reply_cond = dm_get_cond(DM_TYPE_COND, NULL);
my_reply_cond = dm_get_cond(DM_TYPE_COND, NULL, NULL);
return my_reply_cond?0:-1;
}

Expand Down Expand Up @@ -292,9 +293,8 @@ static void dm_cond_signal(struct dm_cond *cond)
pthread_mutex_unlock(&cond->sync.cond.mutex);
break;
case DM_TYPE_CB:
LM_INFO("callback %p\n", cond->sync.cb);
if (cond->sync.cb)
cond->sync.cb(NULL, &cond->rpl);
if (cond->sync.cb.f)
cond->sync.cb.f(NULL, &cond->rpl, cond->sync.cb.p);
shm_free(cond);
break;
}
Expand Down Expand Up @@ -1934,7 +1934,7 @@ int _dm_send_message_async(aaa_conn *_, aaa_message *req, int *fd)
if (!req)
return -1;

cond = dm_get_cond(DM_TYPE_EVENT, NULL);
cond = dm_get_cond(DM_TYPE_EVENT, NULL, NULL);
if (!cond) {
LM_ERR("out of memory for cond\n");
return -1;
Expand All @@ -1948,14 +1948,14 @@ int _dm_send_message_async(aaa_conn *_, aaa_message *req, int *fd)
return 0;
}

int _dm_send_message_callback(aaa_conn *_, aaa_message *req, diameter_reply_cb *cb)
int _dm_send_message_callback(aaa_conn *_, aaa_message *req, diameter_reply_cb *cb, void *param)
{
struct dm_cond *cond;

if (!req)
return -1;

cond = dm_get_cond(DM_TYPE_CB, cb);
cond = dm_get_cond(DM_TYPE_CB, cb, param);
if (!cond) {
LM_ERR("out of memory for cond\n");
return -1;
Expand Down Expand Up @@ -2091,7 +2091,8 @@ int dm_api_send_req(diameter_conn *conn, int app_id, int cmd_code, cJSON *req, d
return rc;
}

int dm_api_send_req_async(diameter_conn *conn, int app_id, int cmd_code, cJSON *req, diameter_reply_cb *reply_cb)
int dm_api_send_req_async(diameter_conn *conn, int app_id, int cmd_code, cJSON *req,
diameter_reply_cb *reply_cb, void *reply_param)
{
aaa_message *dmsg = NULL;

Expand All @@ -2118,7 +2119,7 @@ int dm_api_send_req_async(diameter_conn *conn, int app_id, int cmd_code, cJSON *
return -1;
}

if (_dm_send_message_callback(NULL, dmsg, reply_cb) != 0) {
if (_dm_send_message_callback(NULL, dmsg, reply_cb, reply_param) != 0) {
LM_ERR("could not send Diameter callback message\n");
return -1;
}
Expand Down
5 changes: 4 additions & 1 deletion modules/aaa_diameter/dm_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,10 @@ struct dm_cond {
int fd;
int pid;
} event;
diameter_reply_cb *cb;
struct {
diameter_reply_cb *f;
void *p;
} cb;
} sync;

diameter_reply rpl;
Expand Down

0 comments on commit 663e519

Please sign in to comment.