bool RtspDispatcher::setup( boost::asio::ip::tcp::socket & rtsp_sock, std::string const & control, std::string const & in_transport, std::string & out_transport, boost::system::error_code & ec) { std::string stream_index_str = control.substr(sizeof("track") - 1,2); size_t stream_index = -1; parse2<size_t>(stream_index_str, stream_index); ppbox::dispatch::Sink * sink = create_transport(rtsp_sock, in_transport, out_transport, ec); if (!CustomDispatcher::setup(stream_index, *sink, ec)) { return false; } //if (!CustomDispatcher::setup(stream_index + 0x100, *transports.second, ec)) { // return false; //} //×é ssrc std::vector<ppbox::avformat::StreamInfo> info; if (!CustomDispatcher::get_stream_info(info, ec)) { return false; } ppbox::mux::RtpStreamDesc rtp_desc; rtp_desc.from_data(info[stream_index].format_data); out_transport += ";ssrc="; out_transport += framework::string::format(rtp_desc.ssrc); return true; }
static BOOL create_transports(Remote* remote, MetsrvTransportCommon* transports, LPDWORD parsedSize) { DWORD totalSize = 0; MetsrvTransportCommon* current = transports; // The first part of the transport is always the URL, if it's NULL, we are done. while (current->url[0] != 0) { DWORD size; if (create_transport(remote, current, &size) != NULL) { dprintf("[TRANS] transport created of size %u", size); totalSize += size; // go to the next transport based on the size of the existing one. current = (MetsrvTransportCommon*)((LPBYTE)current + size); } else { // This is not good return FALSE; } } // account for the last terminating NULL wchar *parsedSize = totalSize + sizeof(wchar_t); return TRUE; }
pdp_t *create_domain_control(mrp_context_t *ctx, const char *extaddr, const char *intaddr, const char *wrtaddr, const char *httpdir) { pdp_t *pdp; pdp = mrp_allocz(sizeof(*pdp)); if (pdp != NULL) { pdp->ctx = ctx; pdp->address = extaddr; if (init_proxies(pdp) && init_tables(pdp)) { if (extaddr && *extaddr) pdp->extt = create_transport(pdp, extaddr); if (intaddr && *intaddr) pdp->intt = create_transport(pdp, intaddr); if (wrtaddr && *wrtaddr) { pdp->wrtt = create_transport(pdp, wrtaddr); if (pdp->wrtt != NULL) { const char *sm_opt = MRP_WSCK_OPT_SENDMODE; const char *sm_val = MRP_WSCK_SENDMODE_TEXT; const char *hd_opt = MRP_WSCK_OPT_HTTPDIR; const char *hd_val = httpdir; mrp_transport_setopt(pdp->wrtt, sm_opt, sm_val); mrp_transport_setopt(pdp->wrtt, hd_opt, hd_val); } } if ((!extaddr || !*extaddr || pdp->extt != NULL) && (!intaddr || !*intaddr || pdp->intt != NULL) && (!wrtaddr || !*wrtaddr || pdp->wrtt != NULL)) return pdp; } destroy_domain_control(pdp); } return NULL; }
static void resolv_result(GResolvResultStatus status, char **results, gpointer user_data) { struct web_session *session = user_data; struct addrinfo hints; char *port; int ret; if (results == NULL || results[0] == NULL) { call_result_func(session, 404); return; } debug(session->web, "address %s", results[0]); memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_flags = AI_NUMERICHOST; hints.ai_family = session->web->family; if (session->addr != NULL) { freeaddrinfo(session->addr); session->addr = NULL; } port = g_strdup_printf("%u", session->port); ret = getaddrinfo(results[0], port, &hints, &session->addr); g_free(port); if (ret != 0 || session->addr == NULL) { call_result_func(session, 400); return; } session->address = g_strdup(results[0]); call_route_func(session); if (create_transport(session) < 0) { call_result_func(session, 409); return; } }
static guint do_request(GWeb *web, const char *url, const char *type, GWebInputFunc input, int fd, gsize length, GWebResultFunc func, GWebRouteFunc route, gpointer user_data) { struct web_session *session; if (web == NULL || url == NULL) return 0; debug(web, "request %s", url); session = g_try_new0(struct web_session, 1); if (session == NULL) return 0; if (parse_url(session, url, web->proxy) < 0) { free_session(session); return 0; } debug(web, "address %s", session->address); debug(web, "port %u", session->port); debug(web, "host %s", session->host); debug(web, "flags %lu", session->flags); debug(web, "request %s", session->request); if (type != NULL) { session->content_type = g_strdup(type); debug(web, "content-type %s", session->content_type); } session->web = web; session->result_func = func; session->route_func = route; session->input_func = input; session->fd = fd; session->length = length; session->offset = 0; session->user_data = user_data; session->receive_buffer = g_try_malloc(DEFAULT_BUFFER_SIZE); if (session->receive_buffer == NULL) { free_session(session); return 0; } session->result.headers = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); if (session->result.headers == NULL) { free_session(session); return 0; } session->receive_space = DEFAULT_BUFFER_SIZE; session->send_buffer = g_string_sized_new(0); session->current_header = g_string_sized_new(0); session->header_done = FALSE; session->body_done = FALSE; if (session->address == NULL && inet_aton(session->host, NULL) == 0) { session->resolv_action = g_resolv_lookup_hostname(web->resolv, session->host, resolv_result, session); if (session->resolv_action == 0) { free_session(session); return 0; } } else { struct addrinfo hints; char *port; int ret; if (session->address == NULL) session->address = g_strdup(session->host); memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_flags = AI_NUMERICHOST; hints.ai_family = session->web->family; if (session->addr != NULL) { freeaddrinfo(session->addr); session->addr = NULL; } port = g_strdup_printf("%u", session->port); ret = getaddrinfo(session->address, port, &hints, &session->addr); g_free(port); if (ret != 0 || session->addr == NULL) { free_session(session); return 0; } if (create_transport(session) < 0) { free_session(session); return 0; } } web->session_list = g_list_append(web->session_list, session); return web->next_query_id++; }
/*** Parse transports section ***/ void parse_transports_section(void) { static int in_section=0; int i; char *ptr1,*ptr2,c; RM_OBJECT room; if (!strcmp(wrd[0],"TRANSPORTS:")) { if (++in_section>1) { fprintf(stderr,"Lotos: Unexpected TRANSPORTS section header on line %d.\n",config_line); boot_exit(1); } return; } if (!wrd[5][0]) { fprintf(stderr,"Lotos: Required parameter(s) missing on line %d.\n",config_line); boot_exit(1); } if (strlen(wrd[0])>ROOM_NAME_LEN) { fprintf(stderr,"Lotos: Room map name too long on line %d.\n",config_line); boot_exit(1); } if (strlen(wrd[1])>ROOM_LABEL_LEN) { fprintf(stderr,"Lotos: Room label too long on line %d.\n",config_line); boot_exit(1); } if (strlen(wrd[2])>ROOM_NAME_LEN) { fprintf(stderr,"Lotos: Room name too long on line %d.\n",config_line); boot_exit(1); } /* Check for duplicate label or name */ for(room=room_first;room!=NULL;room=room->next) { if (!strcmp(room->label,wrd[1])) { fprintf(stderr,"Lotos: Duplicate room label on line %d.\n",config_line); boot_exit(1); } if (!strcmp(room->name,wrd[2])) { fprintf(stderr,"Lotos: Duplicate room name on line %d.\n",config_line); boot_exit(1); } } room=create_room(); room->transp=create_transport(); room->transp->room=room; strcpy(room->map,wrd[0]); strcpy(room->label,wrd[1]); strcpy(room->name,wrd[2]); room->transp->place=atoi(wrd[4]); room->transp->route=atoi(wrd[5]); room->transp->smer=1; room->access=FIXED_PUBLIC; /* Parse internal links bit ie hl,gd,of etc. MUST NOT be any spaces between the commas */ i=0; ptr1=wrd[3]; ptr2=wrd[3]; while (1) { while (*ptr2!=',' && *ptr2!='\0') ++ptr2; if (*ptr2==',' && *(ptr2+1)=='\0') { fprintf(stderr,"Lotos: Missing link label on line %d.\n",config_line); boot_exit(1); } c=*ptr2; *ptr2='\0'; if (!strcmp(ptr1,room->label)) { fprintf(stderr,"Lotos: Room has a link to itself on line %d.\n",config_line); boot_exit(1); } strcpy(room->link_label[i],ptr1); if (c=='\0') break; if (++i>=MAX_LINKS) { fprintf(stderr,"Lotos: Too many links on line %d.\n",config_line); boot_exit(1); } *ptr2=c; ptr1=++ptr2; } }