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

Function _bin_init

bin_interface.c:51–99  ·  view source on GitHub ↗

* _bin_init - begins the construction of a new binary packet (header part): * * +-----------------------------+-------------------------------------------------------+ * | 12-byte HEADER | BODY max 65535 bytes | * +-----------------------------+-------------------------------------------------------+ * | PK_MARKER |PGK LEN| VERSION | LEN | CAP | C

Source from the content-addressed store, hash-verified

49 * @length: initial packet size. specify 0 to use the default size (BIN_MAX_BUF_LEN)
50 */
51int _bin_init(bin_packet_t *packet, str *capability, int packet_type,
52 short version, int length, int use_sysmalloc)
53{
54 if (length != 0 && length < MIN_BIN_PACKET_SIZE + capability->len) {
55 LM_ERR("Length parameter has to be greater than: %zu\n",
56 MIN_BIN_PACKET_SIZE + capability->len);
57 return -1;
58 }
59
60 if (!length)
61 length = BIN_MAX_BUF_LEN;
62
63 if (use_sysmalloc) {
64 packet->buffer.s = malloc(length);
65 packet->flags = BINFL_SYSMEM;
66 } else {
67 packet->buffer.s = pkg_malloc(length);
68 packet->flags = 0;
69 }
70 if (!packet->buffer.s) {
71 LM_ERR("No more pkg memory!\n");
72 return -1;
73 }
74
75 packet->buffer.len = 0;
76 packet->type = packet_type;
77 packet->size = length;
78
79 /* binary packet header: marker + pkg_len */
80 memcpy(packet->buffer.s + packet->buffer.len,
81 BIN_PACKET_MARKER, BIN_PACKET_MARKER_SIZE);
82 packet->buffer.len += BIN_PACKET_MARKER_SIZE + PKG_LEN_FIELD_SIZE;
83
84 /* bin version */
85 memcpy(packet->buffer.s + packet->buffer.len, &version, sizeof(version));
86 packet->buffer.len += VERSION_FIELD_SIZE;
87
88 /* capability name */
89 memcpy(packet->buffer.s + packet->buffer.len, &capability->len, LEN_FIELD_SIZE);
90 packet->buffer.len += LEN_FIELD_SIZE;
91 memcpy(packet->buffer.s + packet->buffer.len, capability->s, capability->len);
92 packet->buffer.len += capability->len;
93
94 memcpy(packet->buffer.s + packet->buffer.len, &packet_type, sizeof(packet_type));
95 packet->buffer.len += sizeof(packet_type);
96
97 set_len(packet);
98 return 0;
99}
100
101void bin_set_packet_type(bin_packet_t *packet, int packet_type)
102{

Callers 1

cl_sync_chunk_startFunction · 0.85

Calls 1

set_lenFunction · 0.85

Tested by

no test coverage detected