Esempio n. 1
0
static int vlclua_net_connect_tcp( lua_State *L )
{
    vlc_object_t *p_this = vlclua_get_this( L );
    const char *psz_host = luaL_checkstring( L, 1 );
    int i_port = luaL_checkint( L, 2 );
    int i_fd = net_Connect( p_this, psz_host, i_port, SOCK_STREAM, IPPROTO_TCP );
    lua_pushinteger( L, vlclua_fd_map_safe( L, i_fd ) );
    return 1;
}
Esempio n. 2
0
static pwr_tStatus
start (
  ini_sContext *cp
)
{
  pwr_tStatus sts;
  char console[80];

#if defined OS_POSIX
  int	fd;

  if ( strcmp( cp->console, "") == 0)
    strcpy( console, "/dev/console");
  else
    strcpy( console, cp->console);
  if ((fd = open(console, O_APPEND | O_WRONLY)) == -1)
    errl_Init(NULL, ini_errl_cb, cp);
  else {
    close(fd);
    errl_Init(console, ini_errl_cb, cp);
  }
#else
  errl_Init("CONSOLE:", ini_errl_cb, cp);
#endif

  errh_Init("pwr_ini", errh_eAnix_ini);

  if ( cp->flags.b.interactive)    
    errh_Interactive();

  mh_UtilCreateEvent();

  ini_CheckContext(&sts, cp);

  ini_ReadBootFile(&sts, cp);
  ini_ReadNodeFile(&sts, cp);
  ini_CheckNode(&sts, cp);

  cp->me = tree_Find(&sts, cp->nid_t, &cp->node.nid);
  if (cp->me == NULL) {
    errh_LogFatal(&cp->log, "Cannot find my own node in %s\n", cp->nodefile.name);
    exit(QCOM__WEIRD);
  }

  if (!checkErrors(cp))
    exit(0);

  if (cp->flags.b.verbose)
    logCardinality(cp);

  ini_CreateDb(&sts, cp);

  ini_LoadNode(&sts, cp);

  ini_BuildNode(&sts, cp);

  if (cp->np != NULL) {
    if (cp->np->ErrLogTerm[0] != '\0') {
      errh_LogInfo(&cp->log, "Setting log terminal to: %s", cp->np->ErrLogTerm);
      errl_SetTerm(cp->np->ErrLogTerm);
    }

/* Logfile is always $pwrp_log/pwr.log from V4.0.0 and handled by Linux log rotation */ 

    char fname[256];
    sprintf(fname, "$pwrp_log/pwr_%s.log", cp->nodename);
    dcli_translate_filename(fname, fname);
    errl_SetFile(fname);
    errh_LogInfo(&cp->log, "Setting log file to: %s", fname);

/*
    if (cp->np->ErrLogFile[0] != '\0') {
      struct tm *tp;
      char fname[256];
      time_t t;

      time(&t);
      tp = localtime(&t);
      strftime(fname, sizeof(fname), cp->np->ErrLogFile, tp );
      dcli_translate_filename( fname, fname);
      errl_SetFile(fname);
      errh_LogInfo(&cp->log, "Setting log file to: %s", cp->np->ErrLogFile);
    }
*/
  }

  ini_SetSystemStatus( cp, PWR__STARTUP);
  errh_SetStatus( PWR__STARTUP);

  sts = ini_RcReadAndSet(cp->dir, cp->nodename, cp->busid);
  if (EVEN(sts))
    errh_LogError(&cp->log, "ini_RcReadAndSet, %m", sts);

  sts = ini_SetAttribute(cp->aliasfile.name, cp->nodename, 0);
  if (EVEN(sts) && sts != INI__FILE)
    errh_LogError(&cp->log, "ini_SetAttribute, %m", sts);

  qini_BuildDb(&sts, cp->nid_t, cp->me, NULL, cp->busid);

  io_init_signals();

  load_backup();

#if defined OS_ELN
  ker$initialization_done(NULL);
#endif

  ini_ProcTable(&sts, cp);
  ini_ProcIter(&sts, cp, proc_mProcess_system, 0, ini_ProcLoad);
  ini_ProcIter(&sts, cp, proc_mProcess_system, 0, ini_ProcStart);
  ini_ProcIter(&sts, cp, proc_mProcess_system, 0, ini_ProcPrio);

  net_Connect(&sts, &gdbroot->my_aid, &gdbroot->my_qid, NULL, "pwr_ini");
  /*if (!qcom_Init(&sts, 0)) {*/
  if (EVEN(sts)) {
    errh_LogFatal(&cp->log, "net_Connect, %m", sts);
    exit(sts);
  }   

  qcom_SignalOr(&sts, &qcom_cQini, ini_mEvent_newPlcInit | ini_mEvent_newPlcStart);

  ini_ProcIter(&sts, cp, proc_mProcess_user, 0, ini_ProcLoad);
  ini_ProcIter(&sts, cp, proc_mProcess_user, 0, ini_ProcStart);
  ini_ProcIter(&sts, cp, proc_mProcess_user, 0, ini_ProcPrio);

  qcom_CreateQ(&sts, &cp->eventQ, NULL, "iniEvent");
  if (EVEN(sts)) {
    errh_LogFatal(&cp->log, "qcom_CreateQ, %m", sts);
    exit(sts);
  }

  qcom_WaitAnd(&sts, &cp->eventQ, &qcom_cQini, ini_mEvent_newPlcStartDone | cp->plc_sigmask, qcom_cTmoEternal);

  sts = ini_SetAttributeAfterPlc(cp->aliasfile.name, cp->nodename, 0);
  if (EVEN(sts) && sts != INI__FILE)
    errh_LogError(&cp->log, "ini_SetAttributeAfterPlc, %m", sts);
         
  ini_SetSystemStatus( cp, PWR__RUNNING);
  errh_SetStatus( PWR__SRUN);

  return sts;
}
Esempio n. 3
0
File: rtp.c Progetto: Geal/vlc
/**
 * Probes and initializes.
 */
static int Open (vlc_object_t *obj)
{
    demux_t *demux = (demux_t *)obj;
    int tp; /* transport protocol */

    if (!strcmp (demux->psz_access, "dccp"))
        tp = IPPROTO_DCCP;
    else
    if (!strcmp (demux->psz_access, "rtptcp"))
        tp = IPPROTO_TCP;
    else
    if (!strcmp (demux->psz_access, "rtp"))
        tp = IPPROTO_UDP;
    else
    if (!strcmp (demux->psz_access, "udplite"))
        tp = IPPROTO_UDPLITE;
    else
        return VLC_EGENERIC;

    char *tmp = strdup (demux->psz_location);
    if (tmp == NULL)
        return VLC_ENOMEM;

    char *shost;
    char *dhost = strchr (tmp, '@');
    if (dhost != NULL)
    {
        *(dhost++) = '\0';
        shost = tmp;
    }
    else
    {
        dhost = tmp;
        shost = NULL;
    }

    /* Parses the port numbers */
    int sport = 0, dport = 0;
    if (shost != NULL)
        sport = extract_port (&shost);
    if (dhost != NULL)
        dport = extract_port (&dhost);
    if (dport == 0)
        dport = 5004; /* avt-profile-1 port */

    int rtcp_dport = var_CreateGetInteger (obj, "rtcp-port");

    /* Try to connect */
    int fd = -1, rtcp_fd = -1;

    switch (tp)
    {
        case IPPROTO_UDP:
        case IPPROTO_UDPLITE:
            fd = net_OpenDgram (obj, dhost, dport, shost, sport, tp);
            if (fd == -1)
                break;
            if (rtcp_dport > 0) /* XXX: source port is unknown */
                rtcp_fd = net_OpenDgram (obj, dhost, rtcp_dport, shost, 0, tp);
            break;

         case IPPROTO_DCCP:
#ifndef SOCK_DCCP /* provisional API (FIXME) */
# ifdef __linux__
#  define SOCK_DCCP 6
# endif
#endif
#ifdef SOCK_DCCP
            var_Create (obj, "dccp-service", VLC_VAR_STRING);
            var_SetString (obj, "dccp-service", "RTPV"); /* FIXME: RTPA? */
            fd = net_Connect (obj, dhost, dport, SOCK_DCCP, tp);
#else
            msg_Err (obj, "DCCP support not included");
#endif
            break;

        case IPPROTO_TCP:
            fd = net_Connect (obj, dhost, dport, SOCK_STREAM, tp);
            break;
    }

    free (tmp);
    if (fd == -1)
        return VLC_EGENERIC;
    net_SetCSCov (fd, -1, 12);

    /* Initializes demux */
    demux_sys_t *p_sys = malloc (sizeof (*p_sys));
    if (p_sys == NULL)
    {
        net_Close (fd);
        if (rtcp_fd != -1)
            net_Close (rtcp_fd);
        return VLC_EGENERIC;
    }

    p_sys->chained_demux = NULL;
#ifdef HAVE_SRTP
    p_sys->srtp         = NULL;
#endif
    p_sys->fd           = fd;
    p_sys->rtcp_fd      = rtcp_fd;
    p_sys->max_src      = var_CreateGetInteger (obj, "rtp-max-src");
    p_sys->timeout      = var_CreateGetInteger (obj, "rtp-timeout")
                        * CLOCK_FREQ;
    p_sys->max_dropout  = var_CreateGetInteger (obj, "rtp-max-dropout");
    p_sys->max_misorder = var_CreateGetInteger (obj, "rtp-max-misorder");
    p_sys->thread_ready = false;
    p_sys->autodetect   = true;

    demux->pf_demux   = NULL;
    demux->pf_control = Control;
    demux->p_sys      = p_sys;

    p_sys->session = rtp_session_create (demux);
    if (p_sys->session == NULL)
        goto error;

#ifdef HAVE_SRTP
    char *key = var_CreateGetNonEmptyString (demux, "srtp-key");
    if (key)
    {
        vlc_gcrypt_init ();
        p_sys->srtp = srtp_create (SRTP_ENCR_AES_CM, SRTP_AUTH_HMAC_SHA1, 10,
                                   SRTP_PRF_AES_CM, SRTP_RCC_MODE1);
        if (p_sys->srtp == NULL)
        {
            free (key);
            goto error;
        }

        char *salt = var_CreateGetNonEmptyString (demux, "srtp-salt");
        int val = srtp_setkeystring (p_sys->srtp, key, salt ? salt : "");
        free (salt);
        free (key);
        if (val)
        {
            msg_Err (obj, "bad SRTP key/salt combination (%s)",
                     vlc_strerror_c(val));
            goto error;
        }
    }
#endif

    if (vlc_clone (&p_sys->thread,
                   (tp != IPPROTO_TCP) ? rtp_dgram_thread : rtp_stream_thread,
                   demux, VLC_THREAD_PRIORITY_INPUT))
        goto error;
    p_sys->thread_ready = true;
    return VLC_SUCCESS;

error:
    Close (obj);
    return VLC_EGENERIC;
}