static int module_init(void) { struct pl pl; int err; if (0 == conf_get(conf_cur(), "pcp_server", &pl)) { err = sa_decode(&pcp_srv, pl.p, pl.l); if (err) return err; } else { err = net_default_gateway_get(net_af(baresip_network()), &pcp_srv); if (err) return err; sa_set_port(&pcp_srv, PCP_PORT_SRV); } info("pcp: using PCP server at %J\n", &pcp_srv); #if 1 /* todo: if multiple applications are listening on port 5350 then this will not work */ err = pcp_listen(&lsnr, &pcp_srv, pcp_msg_handler, 0); if (err) { info("pcp: could not enable listener: %m\n", err); err = 0; } #endif return mnat_register(&mnat, "pcp", NULL, session_alloc, media_alloc, NULL); }
int prepare(struct httpd *httpd, const char *to_bind) { int err; struct sa local_addr; err = sa_decode(&local_addr, to_bind, strlen(to_bind)); if(err != 0) return err; err = http_listen(&httpd->hsp, &local_addr, http_request_h, httpd); return err; }
int conf_get_sa(const struct conf *conf, const char *name, struct sa *sa) { struct pl opt; int err; if (!conf || !name || !sa) return EINVAL; err = conf_get(conf, name, &opt); if (err) return err; return sa_decode(sa, opt.p, opt.l); }
static int dns_server_handler(const struct pl *pl, void *arg) { struct sa sa; int err; (void)arg; err = sa_decode(&sa, pl->p, pl->l); if (err) { DEBUG_WARNING("dns_server: could not decode `%r'\n", pl); return err; } err = net_dnssrv_add(&sa); if (err) { DEBUG_WARNING("failed to add nameserver %r: %m\n", pl, err); } return err; }
static int listen_handler(const struct pl *addrport, void *arg) { uint32_t sockbuf_size = *(uint32_t *)arg; struct udp_lstnr *ul = NULL; int err = ENOMEM; ul = mem_zalloc(sizeof(*ul), destructor); if (!ul) { restund_warning("udp listen error: %s\n", strerror(err)); goto out; } list_append(&lstnrl, &ul->le, ul); err = sa_decode(&ul->bnd_addr, addrport->p, addrport->l); if (err || sa_is_any(&ul->bnd_addr) || !sa_port(&ul->bnd_addr)) { restund_warning("bad udp_listen directive: '%r'\n", addrport); err = EINVAL; goto out; } err = udp_listen(&ul->us, &ul->bnd_addr, udp_recv, ul); if (err) { restund_warning("udp listen %J: %s\n", &ul->bnd_addr, strerror(err)); goto out; } if (sockbuf_size > 0) (void)udp_sockbuf_set(ul->us, sockbuf_size); restund_debug("udp listen: %J\n", &ul->bnd_addr); out: if (err) mem_deref(ul); return err; }
void http_send(struct request *request) { int ok; if(request->state == START) { ok = sa_decode(&request->dest, request->host, strlen(request->host)); if(ok == 0) { request->state = RESOLVED; } else { http_resolve(request); return; } } tcp_connect(&request->tcp, &request->dest, tcp_estab_handler, tcp_recv_handler, tcp_close_handler, request); if(request->secure) { ok = tls_start_tcp(&request->ssl, request->app->tls, request->tcp, 0); DEBUG_INFO("start ssl %d\n", ok); } }
static int add_transp_af(const struct sa *laddr) { struct sa local; int err = 0; if (str_isset(uag.cfg->local)) { err = sa_decode(&local, uag.cfg->local, str_len(uag.cfg->local)); if (err) { err = sa_set_str(&local, uag.cfg->local, 0); if (err) { warning("ua: decode failed: '%s'\n", uag.cfg->local); return err; } } if (!sa_isset(&local, SA_ADDR)) { uint16_t port = sa_port(&local); (void)sa_set_sa(&local, &laddr->u.sa); sa_set_port(&local, port); } if (sa_af(laddr) != sa_af(&local)) return 0; } else { sa_cpy(&local, laddr); sa_set_port(&local, 0); } if (uag.use_udp) err |= sip_transp_add(uag.sip, SIP_TRANSP_UDP, &local); if (uag.use_tcp) err |= sip_transp_add(uag.sip, SIP_TRANSP_TCP, &local); if (err) { warning("ua: SIP Transport failed: %m\n", err); return err; } #ifdef USE_TLS if (uag.use_tls) { /* Build our SSL context*/ if (!uag.tls) { const char *cert = NULL; if (str_isset(uag.cfg->cert)) { cert = uag.cfg->cert; info("SIP Certificate: %s\n", cert); } err = tls_alloc(&uag.tls, TLS_METHOD_SSLV23, cert, NULL); if (err) { warning("ua: tls_alloc() failed: %m\n", err); return err; } } if (sa_isset(&local, SA_PORT)) sa_set_port(&local, sa_port(&local) + 1); err = sip_transp_add(uag.sip, SIP_TRANSP_TLS, &local, uag.tls); if (err) { warning("ua: SIP/TLS transport failed: %m\n", err); return err; } } #endif return err; }