| 179 | } |
| 180 | |
| 181 | void replicate_entity_update(b2b_dlg_t *dlg, int etype, unsigned int hash_index, |
| 182 | str *b2bl_param, int event_type, bin_packet_t *storage) |
| 183 | { |
| 184 | int rc; |
| 185 | bin_packet_t packet; |
| 186 | b2b_table htable = (etype == B2B_SERVER) ? server_htable : client_htable; |
| 187 | str storage_cnt_buf; |
| 188 | int pkt_type; |
| 189 | |
| 190 | B2BE_LOCK_GET(htable, hash_index); |
| 191 | |
| 192 | if (dlg->state < B2B_CONFIRMED) { |
| 193 | B2BE_LOCK_RELEASE(htable, hash_index); |
| 194 | return; |
| 195 | } |
| 196 | |
| 197 | switch (event_type) { |
| 198 | case -1: |
| 199 | pkt_type = REPL_ENTITY_PARAM_UPDATE; |
| 200 | break; |
| 201 | case B2B_EVENT_ACK: |
| 202 | pkt_type = REPL_ENTITY_ACK; |
| 203 | break; |
| 204 | case B2B_EVENT_UPDATE: |
| 205 | pkt_type = REPL_ENTITY_UPDATE; |
| 206 | break; |
| 207 | default: |
| 208 | LM_ERR("Bad entity event %d\n", event_type); |
| 209 | B2BE_LOCK_RELEASE(htable, hash_index); |
| 210 | return; |
| 211 | } |
| 212 | |
| 213 | if (bin_init(&packet, &entities_repl_cap, pkt_type, B2BE_BIN_VERSION, 0) < 0) { |
| 214 | LM_ERR("Failed to init bin packet\n"); |
| 215 | B2BE_LOCK_RELEASE(htable, hash_index); |
| 216 | return; |
| 217 | } |
| 218 | |
| 219 | if (pkt_type == REPL_ENTITY_PARAM_UPDATE) { /* replicate only the b2bl param update */ |
| 220 | bin_pack_entity_coords(&packet, dlg, etype); |
| 221 | bin_push_str(&packet, b2bl_param); |
| 222 | } else { |
| 223 | bin_pack_entity(&packet, dlg, etype); |
| 224 | |
| 225 | if (storage->buffer.s) { |
| 226 | bin_get_content_start(storage, &storage_cnt_buf); |
| 227 | if (storage_cnt_buf.len > 0 && |
| 228 | bin_append_buffer(&packet, &storage_cnt_buf) < 0) { |
| 229 | LM_ERR("Failed to push the entity storage content into the packet\n"); |
| 230 | B2BE_LOCK_RELEASE(htable, hash_index); |
| 231 | goto end; |
| 232 | } |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | B2BE_LOCK_RELEASE(htable, hash_index); |
| 237 | |
| 238 | rc = cl_api.send_all(&packet, b2be_cluster); |
no test coverage detected