Example #1
0
/**
 * Returns the pathname of the memory-file corresponding to a server and a
 * multicast group. This function is reentrant.
 *
 * @param[in] servAddr  The address of the server associated with the multicast
 *                      group.
 * @param[in] feedtype  Feedtype of multicast group.
 * @retval    NULL      Failure. `log_start()` called.
 * @return              The path of the corresponding memory-file. The caller
 *                      should free when it's no longer needed.
 */
static char*
getSessionPath(
    const ServiceAddr* const servAddr,
    const feedtypet          feedtype)
{
    char* path;
    char  ftBuf[256];

    if (sprint_feedtypet(ftBuf, sizeof(ftBuf), feedtype) < 0) {
        LOG_START0("sprint_feedtypet() failure");
        path = NULL;
    }
    else {
        path = ldm_format(256, "%s/%s_%s.yaml", getLdmLogDir(),
                servAddr->inetId, ftBuf);
    }

    return path;
}
Example #2
0
/*
 * Adds a filter-component to an upstream-filter.
 *
 * Arguments:
 *      upFilter        Pointer to the upstream-filter to which to add the 
 *                      component.
 *      feedtype        The feedtype of the filter-component.
 *      okPattern       Pointer to the "OK pattern" of the filter-component to 
 *                      be added.  Caller may free upon return.
 *      notPattern      Pointer to the "not pattern" of the filter-component to
 *                      be added.  May be NULL to indicate that such matching
 *                      should be disabled.  Caller may free upon return.
 * Returns:
 *      NULL            Success.
 *      else            Error object.
 */
ErrorObj*
upFilter_addComponent(
    UpFilter* const             upFilter,
    const feedtypet             feedtype,
    const Pattern* const        okPattern,
    const Pattern* const        notPattern)
{
    ErrorObj*   errObj = NULL;          /* success */
    Element*    elt;

    /*
     * Ensure that the given feedtype is disjoint from all feedtypes already
     * in the filter.
     */
    for (elt = upFilter->head; NULL != elt; elt = elt->next) {
        if (feedtype & elt->ft) {
            char        ftSpec[512];

            (void)sprint_feedtypet(ftSpec, sizeof(ftSpec), feedtype);

            errObj = ERR_NEW2(0, NULL,
                "Feedtype %s overlaps with feedtype %s",
                ftSpec, s_feedtypet(elt->ft));

            break;
        }
    }

    if (NULL == errObj) {
        size_t          nbytes = sizeof(Element);

        elt = (Element*)malloc(nbytes);

        if (NULL == elt) {
            errObj = ERR_NEW2(0, NULL, "Couldn't allocate %lu-bytes: %s",
                (unsigned long)nbytes, strerror(errno));
        }
        else {
            if ((errObj = pat_clone(&elt->okPattern, okPattern))) {
                errObj = ERR_NEW(0, errObj, "Couldn't clone \"OK\" pattern");
                free(elt);
            }
            else {
                if (NULL == notPattern) {
                    elt->notPattern = NULL;
                }
                else {
                    if ((errObj = pat_clone(&elt->notPattern, notPattern))) {
                        errObj = ERR_NEW(0, errObj,
                            "Couldn't clone \"not\" pattern");
                        pat_free(elt->okPattern);
                        free(elt);
                        elt = NULL;
                    }
                }

                if (elt) {
                    elt->ft = feedtype;
                    elt->next = upFilter->head;
                    upFilter->head = elt;
                    upFilter->stringOutOfDate = 1;
                    upFilter->count++;
                }
            }                           /* "elt->okPattern" allocated */
        }                               /* "elt" allocated */
    } // given feedtype is disjoint from those already in filter

    return errObj;
}