void UpnpCache::removeTrack( Meta::TrackPtr t ) { #define DOWNCAST( Type, item ) Meta::Upnp##Type##Ptr::staticCast( item ) Meta::UpnpTrackPtr track = DOWNCAST( Track, t ); DOWNCAST( Artist, m_artistMap[ track->artist()->name() ] )->removeTrack( track ); DOWNCAST( Album, m_albumMap.value( track->album() ) )->removeTrack( track ); DOWNCAST( Genre, m_genreMap[ track->genre()->name() ] )->removeTrack( track ); DOWNCAST( Year, m_yearMap[ track->year()->year() ] )->removeTrack( track ); #undef DOWNCAST m_trackMap.remove( track->uidUrl() ); }
static void sip_deserialize(struct proto_info *info_, uint8_t const **buf) { struct sip_proto_info *info = DOWNCAST(info_, info, sip_proto_info); proto_info_deserialize(info_, buf); info->set_values = deserialize_2(buf); if (info->set_values & SIP_CMD_SET) info->cmd = deserialize_1(buf); if (info->set_values & SIP_FROM_SET) deserialize_str(buf, info->from, sizeof(info->from)); if (info->set_values & SIP_TO_SET) deserialize_str(buf, info->to, sizeof(info->to)); if (info->set_values & SIP_CALLID_SET) deserialize_str(buf, info->call_id, sizeof(info->call_id)); if (info->set_values & SIP_MIME_SET) deserialize_str(buf, info->mime_type, sizeof(info->mime_type)); if (info->set_values & SIP_VIA_SET) { info->via.protocol = deserialize_1(buf); ip_addr_deserialize(&info->via.addr, buf); info->via.port = deserialize_2(buf); } if (info->set_values & SIP_LENGTH_SET) info->content_length = deserialize_4(buf); if (info->set_values & SIP_CODE_SET) info->code = deserialize_4(buf); if (info->set_values & SIP_CSEQ_SET) info->cseq = deserialize_4(buf); }
static enum proto_parse_status pg_sbuf_parse(struct parser *parser, struct proto_info *parent, unsigned way, uint8_t const *payload, size_t cap_len, size_t wire_len, struct timeval const *now, size_t tot_cap_len, uint8_t const *tot_packet) { struct pgsql_parser *pg_parser = DOWNCAST(parser, parser, pgsql_parser); // If this is the first time we are called, init c2s_way if (pg_parser->c2s_way == UNSET) { SLOG(LOG_DEBUG, "First packet, init c2s_way to %u", way); pg_parser->c2s_way = way; } // Now build the proto_info struct sql_proto_info info; proto_info_ctor(&info.info, parser, parent, wire_len, 0); info.is_query = way == pg_parser->c2s_way; info.set_values = 0; switch (pg_parser->phase) { case NONE: return pg_parse_init (pg_parser, &info, way, payload, cap_len, wire_len, now, tot_cap_len, tot_packet); case STARTUP: return pg_parse_startup(pg_parser, &info, way, payload, cap_len, wire_len, now, tot_cap_len, tot_packet); case QUERY: return pg_parse_query (pg_parser, &info, way, payload, cap_len, wire_len, now, tot_cap_len, tot_packet); case EXIT: return PROTO_PARSE_ERR; // we do not expect payload after a termination message } return PROTO_PARSE_ERR; }
static void sip_serialize(struct proto_info const *info_, uint8_t **buf) { struct sip_proto_info const *info = DOWNCAST(info_, info, sip_proto_info); proto_info_serialize(info_, buf); serialize_2(buf, info->set_values); if (info->set_values & SIP_CMD_SET) serialize_1(buf, info->cmd); if (info->set_values & SIP_FROM_SET) serialize_str(buf, info->from); if (info->set_values & SIP_TO_SET) serialize_str(buf, info->to); if (info->set_values & SIP_CALLID_SET) serialize_str(buf, info->call_id); if (info->set_values & SIP_MIME_SET) serialize_str(buf, info->mime_type); if (info->set_values & SIP_VIA_SET) { serialize_1(buf, info->via.protocol); ip_addr_serialize(&info->via.addr, buf); serialize_2(buf, info->via.port); } if (info->set_values & SIP_LENGTH_SET) serialize_4(buf, info->content_length); if (info->set_values & SIP_CODE_SET) serialize_4(buf, info->code); if (info->set_values & SIP_CSEQ_SET) serialize_4(buf, info->cseq); }
static void sdp_parser_del(struct parser *parser) { struct sdp_parser *sdp_parser = DOWNCAST(parser, parser, sdp_parser); parser_dtor(parser); FREE(sdp_parser); }
static dir_connection_t * test_conn_download_status_add_a_connection(const char *resource) { dir_connection_t *conn = DOWNCAST(dir_connection_t, test_conn_get_connection( TEST_CONN_STATE, TEST_CONN_TYPE, TEST_CONN_RSRC_PURPOSE)); tt_assert(conn); assert_connection_ok(&conn->base_, time(NULL)); /* Replace the existing resource with the one we want */ if (resource) { if (conn->requested_resource) { tor_free(conn->requested_resource); } conn->requested_resource = tor_strdup(resource); assert_connection_ok(&conn->base_, time(NULL)); } return conn; done: test_conn_get_rsrc_teardown(NULL, conn); return NULL; }
static int test_conn_get_rsrc_teardown(const struct testcase_t *tc, void *arg) { int rv = 0; connection_t *conn = (connection_t *)arg; tt_assert(conn); assert_connection_ok(conn, time(NULL)); if (conn->type == CONN_TYPE_DIR) { dir_connection_t *dir_conn = DOWNCAST(dir_connection_t, arg); tt_assert(dir_conn); assert_connection_ok(&dir_conn->base_, time(NULL)); /* avoid a last-ditch attempt to refetch the consensus */ dir_conn->base_.state = TEST_CONN_RSRC_STATE_SUCCESSFUL; assert_connection_ok(&dir_conn->base_, time(NULL)); } /* connection_free_() cleans up requested_resource */ rv = test_conn_get_basic_teardown(tc, conn); done: return rv; }
static void * test_conn_get_rend_setup(const struct testcase_t *tc) { dir_connection_t *conn = DOWNCAST(dir_connection_t, test_conn_get_basic_setup(tc)); tt_assert(conn); assert_connection_ok(&conn->base_, time(NULL)); rend_cache_init(); /* TODO: use directory_initiate_command_rend() to do this - maybe? */ conn->rend_data = tor_malloc_zero(sizeof(rend_data_t)); tor_assert(strlen(TEST_CONN_REND_ADDR) == REND_SERVICE_ID_LEN_BASE32); memcpy(conn->rend_data->onion_address, TEST_CONN_REND_ADDR, REND_SERVICE_ID_LEN_BASE32+1); conn->rend_data->hsdirs_fp = smartlist_new(); conn->base_.purpose = TEST_CONN_REND_PURPOSE; assert_connection_ok(&conn->base_, time(NULL)); return conn; /* On failure */ done: test_conn_get_rend_teardown(tc, conn); /* Returning NULL causes the unit test to fail */ return NULL; }
static void test_conn_get_rend(void *arg) { dir_connection_t *conn = DOWNCAST(dir_connection_t, arg); tt_assert(conn); assert_connection_ok(&conn->base_, time(NULL)); tt_assert(connection_get_by_type_state_rendquery( conn->base_.type, conn->base_.state, conn->rend_data->onion_address) == TO_CONN(conn)); tt_assert(connection_get_by_type_state_rendquery( TEST_CONN_TYPE, TEST_CONN_STATE, TEST_CONN_REND_ADDR) == TO_CONN(conn)); tt_assert(connection_get_by_type_state_rendquery(TEST_CONN_REND_TYPE_2, !conn->base_.state, "") == NULL); tt_assert(connection_get_by_type_state_rendquery(TEST_CONN_REND_TYPE_2, !TEST_CONN_STATE, TEST_CONN_REND_ADDR_2) == NULL); done: ; }
static void cap_deserialize(struct proto_info *info_, uint8_t const **buf) { struct cap_proto_info *info = DOWNCAST(info_, info, cap_proto_info); proto_info_deserialize(info_, buf); info->dev_id = deserialize_2(buf); timeval_deserialize(&info->tv, buf); }
static void tcp_deserialize(struct proto_info *info_, uint8_t const **buf) { struct tcp_proto_info *info = DOWNCAST(info_, info, tcp_proto_info); proto_info_deserialize(info_, buf); info->key.port[0] = deserialize_2(buf); info->key.port[1] = deserialize_2(buf); unsigned flags = deserialize_1(buf); info->syn = !!(flags & 0x01); info->ack = !!(flags & 0x02); info->rst = !!(flags & 0x04); info->fin = !!(flags & 0x08); info->urg = !!(flags & 0x10); info->psh = !!(flags & 0x20); info->to_srv = !!(flags & 0x40); info->window = deserialize_2(buf); info->urg_ptr = deserialize_2(buf); info->ack_num = deserialize_4(buf); info->seq_num = deserialize_4(buf); info->rel_seq_num = deserialize_4(buf); info->set_values = deserialize_1(buf); info->mss = deserialize_2(buf); info->wsf = deserialize_1(buf); info->nb_options = deserialize_1(buf); for (unsigned o = 0; o < info->nb_options; o++) { info->options[o] = deserialize_1(buf); } }
static char const *mgcp_info_2_str(struct proto_info const *info_) { struct mgcp_proto_info const *info = DOWNCAST(info_, info, mgcp_proto_info); return tempstr_printf("%s, %s, %s", proto_info_2_str(info_), info->response ? mgcp_resp_2_str(&info->u.resp) : mgcp_query_2_str(&info->u.query), mgcp_params_2_str(info)); }
static enum proto_parse_status tns_parse(struct parser *parser, struct proto_info *parent, unsigned way, uint8_t const *payload, size_t cap_len, size_t wire_len, struct timeval const *now, size_t tot_cap_len, uint8_t const *tot_packet) { struct tns_parser *tns_parser = DOWNCAST(parser, parser, tns_parser); enum proto_parse_status const status = streambuf_add(&tns_parser->sbuf, parser, parent, way, payload, cap_len, wire_len, now, tot_cap_len, tot_packet); return status; }
struct mux_subparser *udp_subparser_and_parser_new(struct parser *parser, struct proto *proto, struct proto *requestor, uint16_t src, uint16_t dst, unsigned way, struct timeval const *now) { assert(parser->proto == proto_udp); struct mux_parser *mux_parser = DOWNCAST(parser, parser, mux_parser); struct port_key key; port_key_init(&key, src, dst, way); return mux_subparser_and_parser_new(mux_parser, proto, requestor, &key, now); }
static void eth_serialize(struct proto_info const *info_, uint8_t **buf) { struct eth_proto_info const *info = DOWNCAST(info_, info, eth_proto_info); proto_info_serialize(info_, buf); serialize_3(buf, info->vlan_id); // 16 bits for vlan itself, +we need to handle -1 for UNSET serialize_n(buf, info->addr[0], ETH_ADDR_LEN); serialize_n(buf, info->addr[1], ETH_ADDR_LEN); serialize_2(buf, info->protocol); }
static void rtp_serialize(struct proto_info const *info_, uint8_t **buf) { struct rtp_proto_info const *info = DOWNCAST(info_, info, rtp_proto_info); proto_info_serialize(info_, buf); serialize_4(buf, info->sync_src); serialize_2(buf, info->seq_num); serialize_1(buf, info->payload_type); serialize_4(buf, info->timestamp); }
static void rtp_deserialize(struct proto_info *info_, uint8_t const **buf) { struct rtp_proto_info *info = DOWNCAST(info_, info, rtp_proto_info); proto_info_deserialize(info_, buf); info->sync_src = deserialize_4(buf); info->seq_num = deserialize_2(buf); info->payload_type = deserialize_1(buf); info->timestamp = deserialize_4(buf); }
static inline ewma_policy_circ_data_t * TO_EWMA_POL_CIRC_DATA(circuitmux_policy_circ_data_t *pol) { if (!pol) return NULL; else { tor_assert(pol->magic == EWMA_POL_CIRC_DATA_MAGIC); return DOWNCAST(ewma_policy_circ_data_t, pol); } }
char const *tds_info_2_str(struct proto_info const *info_) { struct tds_proto_info const *info = DOWNCAST(info_, info, tds_proto_info); char *str = tempstr_printf("%s, type=%s, status=0x%x, length=%"PRIu16"", proto_info_2_str(info_), tds_packet_type_2_str(info->type), info->status, info->length); return str; }
static enum proto_parse_status tds_parse(struct parser *parser, struct proto_info *parent, unsigned way, uint8_t const *payload, size_t cap_len, size_t wire_len, struct timeval const *now, size_t tot_cap_len, uint8_t const *tot_packet) { struct tds_parser *tds_parser = DOWNCAST(parser, parser, tds_parser); if (cap_len == 0 && wire_len > 0) return PROTO_TOO_SHORT; // We do not know how to handle pure gaps enum proto_parse_status const status = streambuf_add(&tds_parser->sbuf, parser, parent, way, payload, cap_len, wire_len, now, tot_cap_len, tot_packet); return status; }
static char const *proto_name(struct proto_info const *info) { if (info->parser->proto->code == PROTO_CODE_DISCOVERY) { struct discovery_proto_info const *pipi = DOWNCAST(info, info, discovery_proto_info); return pipi->protocol.name; } return info->parser->proto->name; }
static char const *udp_info_2_str(struct proto_info const *info_) { struct udp_proto_info const *info = DOWNCAST(info_, info, udp_proto_info); char *str = tempstr(); snprintf(str, TEMPSTR_SIZE, "%s, ports=%"PRIu16"->%"PRIu16, proto_info_2_str(info_), info->key.port[0], info->key.port[1]); return str; }
static char const *cifs_info_2_str(struct proto_info const *info_) { struct cifs_proto_info const *info = DOWNCAST(info_, info, cifs_proto_info); char *str = tempstr_printf("%s, command=%#04x, status=0x%08"PRIx32, proto_info_2_str(info_), info->command, info->status); return str; }
static char const *cap_info_2_str(struct proto_info const *info_) { struct cap_proto_info const *info = DOWNCAST(info_, info, cap_proto_info); char *str = tempstr(); snprintf(str, TEMPSTR_SIZE, "%s, dev_id=%u, tv=%s", proto_info_2_str(info_), info->dev_id, timeval_2_str(&info->tv)); return str; }
static char const *rtp_info_2_str(struct proto_info const *info_) { struct rtp_proto_info const *info = DOWNCAST(info_, info, rtp_proto_info); char *str = tempstr(); snprintf(str, TEMPSTR_SIZE, "%s, payload_type=%s, SSRC=%"PRIu32", seqnum=%"PRIu16", timestamp=%"PRIu32, proto_info_2_str(info_), rtp_payload_type_2_str(info->payload_type), info->sync_src, info->seq_num, info->timestamp); return str; }
static void eth_deserialize(struct proto_info *info_, uint8_t const **buf) { struct eth_proto_info *info = DOWNCAST(info_, info, eth_proto_info); proto_info_deserialize(info_, buf); info->vlan_id = deserialize_3(buf); if (info->vlan_id == 0xffffff) info->vlan_id = -1; deserialize_n(buf, info->addr[0], ETH_ADDR_LEN); deserialize_n(buf, info->addr[1], ETH_ADDR_LEN); info->protocol = deserialize_2(buf); }
static void sdp_deserialize(struct proto_info *info_, uint8_t const **buf) { struct sdp_proto_info *info = DOWNCAST(info_, info, sdp_proto_info); proto_info_deserialize(info_, buf); info->set_values = deserialize_1(buf); if (info->set_values & SDP_HOST_SET) ip_addr_deserialize(&info->host, buf); if (info->set_values & SDP_PORT_SET) info->port = deserialize_2(buf); }
static char const *fcoe_info_2_str(struct proto_info const *info_) { struct fcoe_proto_info *info = DOWNCAST(info_, info, fcoe_proto_info); char *str = tempstr(); snprintf(str, TEMPSTR_SIZE, "%s, version=%d, sof=0x%02x, eof=0x%02x", proto_info_2_str(info_), info->version, info->sof, info->eof); return str; }
static void dup_callback(struct proto_subscriber unused_ *s, struct proto_info const *last, size_t cap_len, uint8_t const unused_ *packet, struct timeval const unused_ *now) { struct dedup_proto_info *dedup = DOWNCAST(last, info, dedup_proto_info); mutex_lock(&dup_lock); init(); unsigned const b = MIN(nb_buckets-1, dedup->dt / bucket_width); nb_dups ++; sz_dups += cap_len; dups[b] ++; mutex_unlock(&dup_lock); }
static void dhcp_serialize(struct proto_info const *info_, uint8_t **buf) { struct dhcp_proto_info const *info = DOWNCAST(info_, info, dhcp_proto_info); proto_info_serialize(info_, buf); serialize_1(buf, info->hw_addr_is_eth + (info->opcode << 1U)); serialize_4(buf, info->xid); serialize_1(buf, info->set_values); if (info->set_values & DHCP_CLIENT_SET) ip_addr_serialize(&info->client, buf); serialize_n(buf, info->client_mac, sizeof(info->client_mac)); serialize_str(buf, info->server_name); }