Browse code

pv: added kemi functions to manage avps

Daniel-Constantin Mierla authored on 06/06/2019 09:07:58
Showing 1 changed files
... ...
@@ -1428,6 +1428,154 @@ static int pv_init_rpc(void)
1428 1428
 	return 0;
1429 1429
 }
1430 1430
 
1431
+/**
1432
+ *
1433
+ */
1434
+static int ki_avp_seti(sip_msg_t *msg, str *xname, int vn)
1435
+{
1436
+	unsigned short atype;
1437
+	int_str aname;
1438
+	int_str avalue;
1439
+
1440
+	memset(&aname, 0, sizeof(int_str));
1441
+
1442
+	atype = AVP_NAME_STR;
1443
+	aname.s = *xname;
1444
+
1445
+	avalue.n = vn;
1446
+
1447
+	if (add_avp(atype, aname, avalue)<0) {
1448
+		LM_ERR("error - cannot add AVP\n");
1449
+		return -1;
1450
+	}
1451
+
1452
+	return 1;
1453
+}
1454
+
1455
+/**
1456
+ *
1457
+ */
1458
+static int ki_avp_sets(sip_msg_t *msg, str *xname, str *vs)
1459
+{
1460
+	unsigned short atype;
1461
+	int_str aname;
1462
+	int_str avalue;
1463
+
1464
+	memset(&aname, 0, sizeof(int_str));
1465
+
1466
+	atype = AVP_NAME_STR;
1467
+	aname.s = *xname;
1468
+
1469
+	avalue.s = *vs;
1470
+	atype |= AVP_VAL_STR;
1471
+
1472
+	if (add_avp(atype, aname, avalue)<0) {
1473
+		LM_ERR("error - cannot add AVP\n");
1474
+		return -1;
1475
+	}
1476
+
1477
+	return 1;
1478
+}
1479
+
1480
+/**
1481
+ *
1482
+ */
1483
+static int ki_avp_rm(sip_msg_t *msg, str *xname)
1484
+{
1485
+	unsigned short atype;
1486
+	int_str aname;
1487
+
1488
+	memset(&aname, 0, sizeof(int_str));
1489
+
1490
+	atype = AVP_NAME_STR;
1491
+	aname.s = *xname;
1492
+
1493
+	destroy_avps(atype, aname, 0);
1494
+
1495
+	return 1;
1496
+}
1497
+
1498
+/**
1499
+ *
1500
+ */
1501
+static int ki_avp_is_null(sip_msg_t *msg, str *xname)
1502
+{
1503
+	unsigned short atype;
1504
+	int_str aname;
1505
+	int_str avalue;
1506
+	avp_search_state_t astate;
1507
+
1508
+	memset(&astate, 0, sizeof(avp_search_state_t));
1509
+	memset(&aname, 0, sizeof(int_str));
1510
+
1511
+	atype = AVP_NAME_STR;
1512
+	aname.s = *xname;
1513
+
1514
+	destroy_avps(atype, aname, 0);
1515
+
1516
+	if (search_first_avp(atype, aname, &avalue, &astate)==0) {
1517
+		return 1;
1518
+	}
1519
+
1520
+	return -1;
1521
+}
1522
+
1523
+/**
1524
+ *
1525
+ */
1526
+static sr_kemi_xval_t* ki_avp_get_mode(sip_msg_t *msg, str *xname, int rmode)
1527
+{
1528
+	avp_t *avp = NULL;
1529
+	avp_search_state_t astate;
1530
+	unsigned short atype;
1531
+	int_str aname;
1532
+	int_str avalue;
1533
+
1534
+	memset(&_sr_kemi_pv_xval, 0, sizeof(sr_kemi_xval_t));
1535
+	memset(&astate, 0, sizeof(avp_search_state_t));
1536
+	memset(&aname, 0, sizeof(int_str));
1537
+
1538
+	atype = AVP_NAME_STR;
1539
+	aname.s = *xname;
1540
+
1541
+	if ((avp=search_first_avp(atype, aname, &avalue, &astate))==0) {
1542
+		sr_kemi_xval_null(&_sr_kemi_pv_xval, rmode);
1543
+		return &_sr_kemi_pv_xval;
1544
+	}
1545
+	if(avp->flags & AVP_VAL_STR) {
1546
+		_sr_kemi_pv_xval.vtype = SR_KEMIP_STR;
1547
+		_sr_kemi_pv_xval.v.s = avalue.s;
1548
+		return &_sr_kemi_pv_xval;
1549
+	} else {
1550
+		_sr_kemi_pv_xval.vtype = SR_KEMIP_INT;
1551
+		_sr_kemi_pv_xval.v.n = avalue.n;
1552
+		return &_sr_kemi_pv_xval;
1553
+	}
1554
+}
1555
+
1556
+/**
1557
+ *
1558
+ */
1559
+static sr_kemi_xval_t* ki_avp_get(sip_msg_t *msg, str *xname)
1560
+{
1561
+	return ki_avp_get_mode(msg, xname, SR_KEMI_XVAL_NULL_NONE);
1562
+}
1563
+
1564
+/**
1565
+ *
1566
+ */
1567
+static sr_kemi_xval_t* ki_avp_gete(sip_msg_t *msg, str *xname)
1568
+{
1569
+	return ki_avp_get_mode(msg, xname, SR_KEMI_XVAL_NULL_EMPTY);
1570
+}
1571
+
1572
+/**
1573
+ *
1574
+ */
1575
+static sr_kemi_xval_t* ki_avp_getw(sip_msg_t *msg, str *xname)
1576
+{
1577
+	return ki_avp_get_mode(msg, xname, SR_KEMI_XVAL_NULL_PRINT);
1578
+}
1431 1579
 
1432 1580
 /**
1433 1581
  *
... ...
@@ -1529,6 +1677,41 @@ static sr_kemi_t sr_kemi_pvx_exports[] = {
1529 1677
 		{ SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_NONE,
1530 1678
 			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
1531 1679
 	},
1680
+	{ str_init("pvx"), str_init("avp_seti"),
1681
+		SR_KEMIP_INT, ki_avp_seti,
1682
+		{ SR_KEMIP_STR, SR_KEMIP_INT, SR_KEMIP_NONE,
1683
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
1684
+	},
1685
+	{ str_init("pvx"), str_init("avp_sets"),
1686
+		SR_KEMIP_INT, ki_avp_seti,
1687
+		{ SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_NONE,
1688
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
1689
+	},
1690
+	{ str_init("pvx"), str_init("avp_get"),
1691
+		SR_KEMIP_XVAL, ki_avp_get,
1692
+		{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
1693
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
1694
+	},
1695
+	{ str_init("pvx"), str_init("avp_gete"),
1696
+		SR_KEMIP_XVAL, ki_avp_gete,
1697
+		{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
1698
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
1699
+	},
1700
+	{ str_init("pvx"), str_init("avp_getw"),
1701
+		SR_KEMIP_XVAL, ki_avp_getw,
1702
+		{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
1703
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
1704
+	},
1705
+	{ str_init("pvx"), str_init("avp_rm"),
1706
+		SR_KEMIP_INT, ki_avp_rm,
1707
+		{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
1708
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
1709
+	},
1710
+	{ str_init("pvx"), str_init("avp_is_null"),
1711
+		SR_KEMIP_INT, ki_avp_is_null,
1712
+		{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
1713
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
1714
+	},
1532 1715
 
1533 1716
 	{ {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
1534 1717
 };