MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / dm_send_custom_req

Function dm_send_custom_req

modules/aaa_diameter/dm_peer.c:453–509  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

451
452
453static int dm_send_custom_req(struct dm_message *msg)
454{
455 str tid_str;
456 struct msg *dmsg;
457 struct avp *avp;
458 struct avp_hdr *h;
459 union avp_value val;
460 struct dict_object *req; /* a custom Diameter request */
461 int rc;
462
463 FD_CHECK(fd_dict_search(fd_g_config->cnf_dict, DICT_COMMAND, CMD_BY_CODE_R,
464 &msg->cmd_code, &req, ENOENT));
465
466 FD_CHECK(fd_msg_new(req, MSGFL_ALLOC_ETEID, &dmsg));
467
468 /* App id */
469 {
470 struct msg_hdr *h;
471 FD_CHECK(fd_msg_hdr(dmsg, &h));
472 h->msg_appl = msg->app_id;
473 }
474
475 /* include all AVPs from the input JSON */
476 if (dm_pack_avps(dmsg, &msg->avps) != 0) {
477 LM_ERR("failed to pack AVPs\n");
478 return -1;
479 }
480
481 /* check if we already have a Session-Id in the message - if so, use it! */
482 rc = fd_msg_search_avp(dmsg, dm_dict.Session_Id, &avp);
483 if (rc != 0) {
484 /* Transaction-Id */
485 struct timeval now;
486 char tid[16 + 1];
487 LM_DBG("No Session-Id in Answer, forcing Transaction-Id\n");
488
489 FD_CHECK(fd_msg_avp_new(dm_dict.Transaction_Id, 0, &avp));
490
491 gettimeofday(&now, NULL);
492 sprintf(tid, "%ld%ld", now.tv_sec, now.tv_usec);
493
494 memset(&val, 0, sizeof val);
495 val.os.data = (unsigned char *)tid;
496 val.os.len = strlen(tid);
497 FD_CHECK(fd_msg_avp_setvalue(avp, &val));
498 FD_CHECK(fd_msg_avp_add(dmsg, MSG_BRW_LAST_CHILD, avp));
499
500 tid_str = (str){(char *)val.os.data, val.os.len};
501 } else {
502 FD_CHECK(fd_msg_avp_hdr(avp, &h));
503 tid_str = (str){(char *)h->avp_value->os.data, h->avp_value->os.len};
504 }
505 FD_CHECK(dm_add_pending_reply(&tid_str, msg->reply_cond));
506
507 FD_CHECK(fd_msg_send(&dmsg, NULL, NULL));
508 return 0;
509}
510

Callers 1

dm_peer_send_msgFunction · 0.85

Calls 2

dm_pack_avpsFunction · 0.85
dm_add_pending_replyFunction · 0.85

Tested by

no test coverage detected