* copies the given string at the end position in the packet * allows null strings (NULL content or NULL param) * * @return: * > 0: success, the size of the packet * < 0: internal buffer limit reached */
| 169 | * < 0: internal buffer limit reached |
| 170 | */ |
| 171 | int bin_push_str(bin_packet_t *packet, const str *info) |
| 172 | { |
| 173 | if (!packet->buffer.s || !packet->size) { |
| 174 | LM_ERR("not initialized yet, call bin_init before altering buffer\n"); |
| 175 | return -1; |
| 176 | } |
| 177 | |
| 178 | if (packet->buffer.len + LEN_FIELD_SIZE + (info ? info->len : 0) > packet->size) { |
| 179 | if (bin_extend(packet, LEN_FIELD_SIZE + (info ? info->len : 0)) < 0) |
| 180 | return -1; |
| 181 | } |
| 182 | |
| 183 | if (!info || info->len == 0 || !info->s) { |
| 184 | memset(packet->buffer.s + packet->buffer.len, 0, LEN_FIELD_SIZE); |
| 185 | packet->buffer.len += LEN_FIELD_SIZE; |
| 186 | |
| 187 | set_len(packet); |
| 188 | return packet->buffer.len; |
| 189 | } |
| 190 | |
| 191 | memcpy(packet->buffer.s + packet->buffer.len, &info->len, LEN_FIELD_SIZE); |
| 192 | packet->buffer.len += LEN_FIELD_SIZE; |
| 193 | memcpy(packet->buffer.s + packet->buffer.len, info->s, info->len); |
| 194 | packet->buffer.len += info->len; |
| 195 | |
| 196 | set_len(packet); |
| 197 | return packet->buffer.len; |
| 198 | } |
| 199 | |
| 200 | /* |
| 201 | * adds a new integer value at the end position in the packet |
no test coverage detected