Example #1
0
// -----------------------------------------------------------------------------
// CFMSServer::CheckPhoneCallActiveL() 
// checks any phone call is there or not at this moment
// -----------------------------------------------------------------------------
void CFMSServer::CheckPhoneCallActiveL(TInt& aStatus)
    {
    FLOG(_L("CFMSServer::CheckPhoneCallActiveL>>"));
    TInt callstatus(KErrNotFound);
    RProperty::Get(KPSUidCtsyCallInformation, KCTsyCallState, callstatus);
    //check ctsydomainpskeys.h for different combinations, below OR condition holds good
    if(EPSCTsyCallStateUninitialized == callstatus || 
            EPSCTsyCallStateNone == callstatus ) // call not active
        {
        aStatus = EFalse;
        }
    else // call active
        {
        aStatus = ETrue;
        }
    FLOG(_L("CFMSServer::CheckPhoneCallActiveL status is %d<<"),aStatus);
    }
Example #2
0
/*
 * Scan outbound, the call status is set in three counters: internet, ISDN and POTS (analogue modems).
 * For all systems the CM and Txx flags are checked and for official
 * FidoNet nodes the Zone Mail Hour wich belongs to the destination zone.
 * All nodes are qualified if there is a way to call them or not on this moment.
 * The method how to call a node is decided as well.
 *
 * On success, return 0.
 */
int outstat()
{
    int		    rc, first = TRUE, T_window, iszmh = FALSE;
    struct _alist   *tmp, *old;
    char	    digit[6], flstr[15], *temp, as[6], be[6], utc[6], flavor, *temp2, *fmt, *buf;
    time_t	    now;
    struct tm	    tm;
    int		    uhour, umin, thour, tmin;
    pp_list	    *tpl;
    faddr	    *fa;
    FILE	    *fp;
    DIR		    *dp = NULL;
    struct dirent   *de;
    struct stat	    sb;
    unsigned int    ibnmask = 0, ifcmask = 0, itnmask = 0, outsize = 0;
    nodelist_modem  **tmpm;

    for (tmpm = &nl_tcpip; *tmpm; tmpm=&((*tmpm)->next)) {
        if (strcmp((*tmpm)->name, "IBN") == 0)
            ibnmask = (*tmpm)->mask;
        if (strcmp((*tmpm)->name, "IFC") == 0)
            ifcmask = (*tmpm)->mask;
        if (strcmp((*tmpm)->name, "ITN") == 0)
            itnmask = (*tmpm)->mask;
    }
    now = time(NULL);
    gmtime_r(&now, &tm);    // UTC time
    uhour = tm.tm_hour;
    umin  = tm.tm_min;
    snprintf(utc, 6, "%02d:%02d", uhour, umin);
    Syslog('+', "Scanning outbound at %s UTC.", utc);
    nxt_hour = 24;
    nxt_min  = 0;
    inet_calls = isdn_calls = pots_calls = 0;

    /*
     *  Clear current table
     */
    for (tmp = alist; tmp; tmp = old) {
        old = tmp->next;
        free(tmp);
    }
    alist = NULL;

    if ((rc = scanout(each))) {
        Syslog('?', "Error scanning outbound, aborting");
        return rc;
    }

    /*
     * Check private outbound box for nodes in the setup.
     */
    temp = calloc(PATH_MAX, sizeof(char));
    snprintf(temp, PATH_MAX, "%s/etc/nodes.data", getenv("FTND_ROOT"));
    if ((fp = fopen(temp, "r")) == NULL) {
        Syslog('?', "Error open %s, aborting", temp);
        free(temp);
        return 1;
    }
    fread(&nodeshdr, sizeof(nodeshdr), 1, fp);
    fseek(fp, 0, SEEK_SET);
    fread(&nodeshdr, nodeshdr.hdrsize, 1, fp);

    while ((fread(&nodes, nodeshdr.recsize, 1, fp)) == 1) {
        if (strlen(nodes.OutBox)) {
            if (nodes.Crash)
                flavor = 'c';
            else if (nodes.Hold)
                flavor = 'h';
            else
                flavor = 'o';

            fa = (faddr *)malloc(sizeof(faddr));
            fa->name   = NULL;
            fa->domain = xstrcpy(nodes.Aka[0].domain);
            fa->zone   = nodes.Aka[0].zone;
            fa->net    = nodes.Aka[0].net;
            fa->node   = nodes.Aka[0].node;
            fa->point  = nodes.Aka[0].point;

            checkdir(nodes.OutBox, fa, flavor);
            if (fa->domain)
                free(fa->domain);
            free(fa);
        }
        fseek(fp, nodeshdr.filegrp + nodeshdr.mailgrp, SEEK_CUR);
    }
    fclose(fp);

    /*
     * Start checking T-Mail fileboxes
     */
    if (strlen(CFG.tmailshort) && (dp = opendir(CFG.tmailshort))) {
        Syslog('o', "Checking T-Mail short box \"%s\"", CFG.tmailshort);
        while ((de = readdir(dp))) {
            if (strcmp(de->d_name, ".") && strcmp(de->d_name, "..")) {
                snprintf(temp, PATH_MAX, "%s/%s", CFG.tmailshort, de->d_name);
                if (stat(temp, &sb) == 0) {
                    Syslog('o' ,"checking \"%s\"", de->d_name);
                    if (S_ISDIR(sb.st_mode)) {
                        int i;
                        char b=0;
                        for (i=0; (i<8) && (!b); ++i) {
                            char c = tolower(de->d_name[i]);
                            if ( (c<'0') || (c>'v') || ((c>'9') && (c<'a')) ) b=1;
                        }
                        if (de->d_name[8]!='.') b=1;
                        for (i=9; (i<11) && (!b); ++i) {
                            char c = tolower(de->d_name[i]);
                            if ( (c<'0') || (c>'v') || ((c>'9') && (c<'a')) ) b=1;
                        }
                        if (b) continue;
                        if (de->d_name[11]==0) flavor='o';
                        else if ((tolower(de->d_name[11])=='h') && (de->d_name[12]==0)) flavor='h';
                        else continue;
                        fa = (faddr*)malloc(sizeof(faddr));
                        fa->name = NULL;
                        fa->domain = NULL;
                        memset(&digit, 0, sizeof(digit));
                        digit[0] = de->d_name[0];
                        digit[1] = de->d_name[1];
                        fa->zone = strtol(digit, NULL, 32);
                        memset(&digit, 0, sizeof(digit));
                        digit[0] = de->d_name[2];
                        digit[1] = de->d_name[3];
                        digit[2] = de->d_name[4];
                        fa->net = strtol(digit, NULL, 32);
                        memset(&digit, 0, sizeof(digit));
                        digit[0] = de->d_name[5];
                        digit[1] = de->d_name[6];
                        digit[2] = de->d_name[7];
                        fa->node = strtol(digit, NULL, 32);
                        memset(&digit, 0, sizeof(digit));
                        digit[0] = de->d_name[9];
                        digit[1] = de->d_name[10];
                        fa->point = strtol(digit, NULL, 32);
                        if (SearchFidonet(fa->zone)) {
                            fa->domain = xstrcpy(fidonet.domain);
                            checkdir(temp, fa, flavor);
                        }
                        if (fa->domain)
                            free(fa->domain);
                        free(fa);
                    }
                }
            }
        }
        closedir(dp);
    }
    if (strlen(CFG.tmaillong) && (dp = opendir(CFG.tmaillong))) {
        temp2 = calloc(PATH_MAX, sizeof(char));
        Syslog('o', "Checking T-Mail long box \"%s\"", CFG.tmaillong);
        while ((de = readdir(dp))) {
            if (strcmp(de->d_name, ".") && strcmp(de->d_name, "..")) {
                snprintf(temp, PATH_MAX, "%s/%s", CFG.tmaillong, de->d_name);
                if (stat(temp, &sb) == 0) {
                    Syslog('o' ,"checking \"%s\"", de->d_name);
                    if (S_ISDIR(sb.st_mode)) {
                        char c, d;
                        int n;
                        snprintf(temp2, PATH_MAX, "%s", de->d_name);
                        fa = (faddr*)malloc(sizeof(faddr));
                        fa->name = NULL;
                        fa->domain = NULL;
                        n = sscanf(temp2, "%u.%u.%u.%u.%c%c", &(fa->zone), &(fa->net), &(fa->node), &(fa->point), &c, &d);
                        if ((n==4) || ((n==5) && (tolower(c)=='h'))) {
                            if (SearchFidonet(fa->zone)) {
                                fa->domain = xstrcpy(fidonet.domain);
                                if (n==4)
                                    flavor = 'o';
                                else
                                    flavor = 'h';
                                checkdir(temp, fa, flavor);
                            }
                        }
                        if (fa->domain)
                            free(fa->domain);
                        free(fa);
                    }
                }
            }
        }
        closedir(dp);
        free(temp2);
    }

    /*
     * During processing the outbound list, determine when the next event will occur,
     * ie. the time when the callout status of a node changes because of starting a
     * ZMH, or changeing the time window for Txx flags.
     */
    for (tmp = alist; tmp; tmp = tmp->next) {
        if (first) {
            Syslog('+', "Flavor Out        Size    Online    Modem     ISDN   TCP/IP Calls Status  Mode    Address");
            first = FALSE;
        }

        rc = load_node(tmp->addr);

        /*
         * Zone Mail Hours, only use Fidonet Hours.
         * Other nets use your default ZMH.
         */
        T_window = iszmh = FALSE;
        switch (tmp->addr.zone) {
        case 1:
            if (uhour == 9)
                iszmh = TRUE;
            set_next(9, 0);
            set_next(10, 0);
            break;
        case 2:
            if (((uhour == 2) && (umin >= 30)) || ((uhour == 3) && (umin < 30)))
                iszmh = TRUE;
            set_next(2, 30);
            set_next(3, 30);
            break;
        case 3:
            if (uhour == 18)
                iszmh = TRUE;
            set_next(18, 0);
            set_next(19, 0);
            break;
        case 4:
            if (uhour == 8)
                iszmh = TRUE;
            set_next(8, 0);
            set_next(9, 0);
            break;
        case 5:
            if (uhour == 1)
                iszmh = TRUE;
            set_next(1, 0);
            set_next(2, 0);
            break;
        case 6:
            if (uhour == 20)
                iszmh = TRUE;
            set_next(20, 0);
            set_next(21, 0);
            break;
        default:
            if (get_zmh())
                iszmh = TRUE;
            break;
        }

        if (tmp->t1 && tmp->t2) {
            /*
             * Txx flags, check callwindow
             */
            thour = toupper(tmp->t1) - 'A';
            if (isupper(tmp->t1))
                tmin = 0;
            else
                tmin = 30;
            snprintf(as, 6, "%02d:%02d", thour, tmin);
            set_next(thour, tmin);
            thour = toupper(tmp->t2) - 'A';
            if (isupper(tmp->t2))
                tmin = 0;
            else
                tmin = 30;
            snprintf(be, 6, "%02d:%02d", thour, tmin);
            set_next(thour, tmin);
            if (strcmp(as, be) > 0) {
                /*
                 * Time window is passing midnight
                 */
                if ((strcmp(utc, as) >= 0) || (strcmp(utc, be) < 0))
                    T_window = TRUE;
            } else {
                /*
                 * Time window is not passing midnight
                 */
                if ((strcmp(utc, as) >= 0) && (strcmp(utc, be) < 0))
                    T_window = TRUE;
            }
        }
        memset(&flstr, 0, sizeof(flstr));
        strncpy(flstr, "...... .... ..", 14);

        /*
         * If the node has internet and we have internet configured,
         * check if we can send immediatly. Works for CM and ICM.
         */
        if (TCFG.max_tcp && (tmp->can_ip && tmp->is_icm)  &&
                (((tmp->flavors) & F_IMM) || ((tmp->flavors) & F_CRASH) || ((tmp->flavors) & F_NORMAL)) &&
                ((tmp->ipflags & ibnmask) || (tmp->ipflags & ifcmask) || (tmp->ipflags & itnmask))) {
            tmp->flavors |= F_CALL;
        }

        /*
         * Immediate Mail check
         */
        if ((tmp->flavors) & F_IMM) {
            flstr[0]='D';
            /*
             * Immediate mail, send if node is CM or is in a Txx window or is in ZMH.
             */
            if (tmp->is_cm || T_window || iszmh) {
                tmp->flavors |= F_CALL;
            }
            /*
             * Now check again for the ICM flag.
             */
            if (tmp->is_icm && TCFG.max_tcp &&
                    ((tmp->ipflags & ibnmask) || (tmp->ipflags & ifcmask) || (tmp->ipflags & itnmask))) {
                tmp->flavors |= F_CALL;
            }
        }

        if ((tmp->flavors) & F_CRASH ) {
            flstr[1]='C';
            /*
             * Crash mail, send if node is CM or is in a Txx window or is in ZMH.
             */
            if (tmp->is_cm || T_window || iszmh) {
                tmp->flavors |= F_CALL;
            }
            /*
             * Now check again for the ICM flag.
             */
            if (tmp->is_icm && TCFG.max_tcp &&
                    ((tmp->ipflags & ibnmask) || (tmp->ipflags & ifcmask) || (tmp->ipflags & itnmask))) {
                tmp->flavors |= F_CALL;
            }
        }

        if ((tmp->flavors) & F_NORMAL)
            flstr[2]='N';
        if ((tmp->flavors) & F_HOLD  )
            flstr[3]='H';
        if ((tmp->flavors) & F_FREQ  )
            flstr[4]='R';
        if ((tmp->flavors) & F_POLL  ) {
            flstr[5]='P';
            tmp->flavors |= F_CALL;
        }

        if ((tmp->flavors) & F_ISFIL ) {
            flstr[7]='A';
            /*
             * Arcmail and maybe file attaches, send during ZMH or if node has a Txx window.
             */
            if ((iszmh || T_window) && !((tmp->flavors) & F_HOLD)) {
                tmp->flavors |= F_CALL;
            }
        }

        if ((tmp->flavors) & F_ISPKT ) {
            flstr[8]='M';
            /*
             * Normal mail, send during ZMH or if node has a Txx window.
             */
            if ((iszmh || T_window) && !((tmp->flavors) & F_HOLD)) {
                tmp->flavors |= F_CALL;
            }
        }

        if ((tmp->flavors) & F_ISFLO )
            flstr[9]='F';

        if (tmp->cst.tryno >= 30) {
            /*
             * Node is undialable, clear callflag
             */
            tmp->flavors &= ~F_CALL;
        }
        if (tmp->t1)
            flstr[12] = tmp->t1;
        if (tmp->t2)
            flstr[13] = tmp->t2;

        /*
         * If forbidden to call from setup, clear callflag.
         */
        if (nodes.NoCall)
            tmp->flavors &= ~F_CALL;

        /*
         * If we must call this node, figure out how to call this node.
         */
        if ((tmp->flavors) & F_CALL) {
            tmp->callmode = CM_NONE;

            if (TCFG.max_tcp && ((tmp->ipflags & ibnmask) || (tmp->ipflags & ifcmask) || (tmp->ipflags & itnmask))) {
                inet_calls++;
                tmp->callmode = CM_INET;
            }

            if ((tmp->callmode == CM_NONE) && isdn_lines) {
                /*
                 * If any matching port found, mark node ISDN
                 */
                for (tpl = pl; tpl; tpl = tpl->next) {
                    if (tmp->diflags & tpl->dflags) {
                        isdn_calls++;
                        tmp->callmode = CM_ISDN;
                        break;
                    }
                }
            }

            if ((tmp->callmode == CM_NONE) && pots_lines) {
                /*
                 * If any matching ports found, mark node POTS
                 */
                for (tpl = pl; tpl; tpl = tpl->next) {
                    if (tmp->moflags & tpl->mflags) {
                        pots_calls++;
                        tmp->callmode = CM_POTS;
                        break;
                    }
                }
            }

            /*
             * Here we are out of options, clear callflag.
             */
            if (tmp->callmode == CM_NONE) {
                buf = calloc(81, sizeof(char));
                fido2str_r(tmp->addr, 0x0f, buf);
                Syslog('!', "No method to call %s available", buf);
                free(buf);
                tmp->flavors &= ~F_CALL;
            }
        }

        if ((tmp->flavors) & F_CALL)
            flstr[10]='C';
        else
            /*
             * Safety, clear callmode.
             */
            tmp->callmode = CM_NONE;

        /*
         * Show callresult for this node.
         */
        outsize += (unsigned int)tmp->size;
        fmt = calloc(81, sizeof(char));
        buf = calloc(81, sizeof(char));
        size_str_r(tmp->size, fmt);
        fido2str_r(tmp->addr, 0x0f, buf);
        snprintf(temp, PATH_MAX, "%s %8s %08x %08x %08x %08x %5d %s %s %s", flstr, fmt,
                 (unsigned int)tmp->olflags, (unsigned int)tmp->moflags,
                 (unsigned int)tmp->diflags, (unsigned int)tmp->ipflags,
                 tmp->cst.tryno, callstatus(tmp->cst.trystat), callmode(tmp->callmode), buf);
        Syslog('+', "%s", temp);
        free(fmt);
        free(buf);

    } /* All nodes scanned. */

    if (nxt_hour == 24) {
        /*
         * 24:00 hours doesn't exist
         */
        nxt_hour = 0;
        nxt_min  = 0;
    }

    /*
     * Always set/reset semafore do_inet if internet is needed.
     */
    if (!IsSema((char *)"do_inet") && inet_calls) {
        CreateSema((char *)"do_inet");
        s_do_inet = TRUE;
        Syslog('c', "Created semafore do_inet");
    } else if (IsSema((char *)"do_inet") && !inet_calls) {
        RemoveSema((char *)"do_inet");
        s_do_inet = FALSE;
        Syslog('c', "Removed semafore do_inet");
    }

    /*
     * Update outbound size MIB
     */
    mib_set_outsize(outsize);

    /*
     * Log results
     */
    snprintf(waitmsg, 81, "Next event at %02d:%02d UTC", nxt_hour, nxt_min);
    Syslog('+', "Systems to call: Inet=%d, ISDN=%d, POTS=%d, Next event at %02d:%02d UTC",
           inet_calls, isdn_calls, pots_calls, nxt_hour, nxt_min);
    free(temp);
    return 0;
}