UtlBoolean
ValidateMailboxCGIHelper::isNumeric( const UtlString& mailboxIdentity ) const
{
    UtlString userid ;
    getUserId( mailboxIdentity, userid ) ;

    static RegEx sAllDigits("^\\d+$");

    return sAllDigits.Search(userid.data());
}
Esempio n. 2
0
UtlBoolean
SubscriptionAuth::isTargetExemptedFromAuthentication(const UtlString& targetUser) const
{
   UtlBoolean targetExempted = FALSE;
   UtlSListIterator nextTargetRegEx(mTargetsExemptedFromAuthentication);

   RegEx* targetRegEx;
   
   while((targetRegEx = dynamic_cast<RegEx*>(nextTargetRegEx())))
   {
      if(targetRegEx->Search(targetUser.data()))
      {
         targetExempted = TRUE;
         break;
      }
   }

   return targetExempted;
}
Esempio n. 3
0
void cpp_hl_tests(RegEx& e, bool recurse = true)
{
   if(flags[4] & REG_MERGE)
      return;

   if(e.error_code())
   {
      if(search_text != BOOST_RE_STR("!"))
      {
         begin_error();
         cout << "Expression did not compile with class RegEx" << endl;
      }
      return;
   }

   if(recurse)
   {
      // copy and assign test:
      RegEx e2(e);
      cpp_hl_tests(e2, false);
      e2 = e;
      cpp_hl_tests(e2, false);
   }

   if(flags[4] & REG_GREP)
   {
      // try to do grep:
      hl_match_id = 0;
      GrepCallback cb = hl_grep_test_proc;
      e.Grep(cb, search_text.c_str(), flags[3]);
   }
   else
   {
      if(e.Search(search_text.c_str(), flags[3]))
      {
         unsigned int i = 0;
         unsigned int j = 0;
         while(matches[j] != -2)
         {
            if( (matches[j] != (int)e.Position(i))
               || ((matches[j] != -1) && ((matches[j+1] - matches[j] != (int)e.Length(i)))) )
            {
               begin_error();
               cout << "RegEx::Search error in subexpression " << i << ": found [" << e.Position(i) << "," << (e.Position(i) + e.Length(i)) << "] expected [" << matches[j] << "," << matches[j+1] << "]" << endl;
            }
            ++i;
            j += 2;
         }
      }
      else
      {
         if(matches[0] != -1)
         {
            begin_error();
            cout << "match expected but not found with RexEx::Search" << endl;
         }
      }

      //
      // test RegEx::Match only if we expect to match all of the input:
      //
      if((matches[0] == 0) && (matches[1] == search_text.size()))
      {
         if(e.Match(search_text.c_str(), flags[3]))
         {
            unsigned int i = 0;
            unsigned int j = 0;
            while(matches[j] != -2)
            {
               if( (matches[j] != (int)e.Position(i))
                  || ((matches[j] != -1) && ((matches[j+1] - matches[j] != (int)e.Length(i)))) )
               {
                  begin_error();
                  cout << "RegEx::Match error in subexpression " << i << ": found [" << e.Position(i) << "," << (e.Position(i) + e.Length(i)) << "] expected [" << matches[j] << "," << matches[j+1] << "]" << endl;
               }
               ++i;
               j += 2;
            }
         }
         else
         {
            begin_error();
            cout << "Match expected but not found with RegEx::Match" << endl;
         }
      }
   }
}
Esempio n. 4
0
RedirectPlugin::LookUpStatus
SipRedirectorRegDB::lookUp(
   const SipMessage& message,
   const UtlString& requestString,
   const Url& requestUri,
   const UtlString& method,
   ContactList& contactList,
   RequestSeqNo requestSeqNo,
   int redirectorNo,
   SipRedirectorPrivateStorage*& privateStorage,
   ErrorDescriptor& errorDescriptor)
{
   unsigned long timeNow = OsDateTime::getSecsSinceEpoch();
   
   // Local copy of requestUri
   Url requestUriCopy = requestUri;

   // Look for any grid parameter and remove it.
   UtlString gridParameter;
   UtlBoolean gridPresent =
      requestUriCopy.getUrlParameter("grid", gridParameter, 0);
   if (gridPresent)
   {
      requestUriCopy.removeUrlParameter("grid");
   }
   if (Os::Logger::instance().willLog(FAC_SIP, PRI_DEBUG))
   {
      UtlString temp;
      requestUriCopy.getUri(temp);
      Os::Logger::instance().log(FAC_SIP, PRI_DEBUG,
                    "%s::lookUp gridPresent = %d, gridParameter = '%s', "
                    "requestUriCopy after removing grid = '%s'",
                    mLogName.data(), gridPresent, gridParameter.data(),
                    temp.data());
   }

   RegDB::Bindings registrations;

   // Give the ~~in~ URIs separate processing.
   UtlString user;
   requestUriCopy.getUserId(user);
   if (user.index(URI_IN_PREFIX) == 0)
   {
      // This is a ~~in~ URI.
      // Check for an '&' separator.
      ssize_t s = user.last('&');
      if (s != UTL_NOT_FOUND)
      {
         // This is a ~~in~[user]&[instrument] URI.
         const char* instrumentp = user.data() + s + 1;
         UtlString u;
         u.append(user,
                  sizeof (URI_IN_PREFIX) - 1,
                  s - (sizeof (URI_IN_PREFIX) - 1));
         requestUriCopy.setUserId(u);

         //regDB->
         //   getUnexpiredContactsUserInstrument(requestUriCopy, instrumentp, timeNow, registrations);
         UtlString identity;
         requestUriCopy.getIdentity(identity);
         _dataStore.regDB().getUnexpiredContactsUserInstrument(identity.str(), instrumentp, timeNow, registrations);
      }
      else
      {
         // This is a ~~in~[instrument] URI.
         const char* instrumentp = user.data() + sizeof (URI_IN_PREFIX) - 1;

          _dataStore.regDB().getUnexpiredContactsInstrument(instrumentp, timeNow, registrations);
      }         
   }
   else
   {
      // Note that getUnexpiredContactsUser will reduce the requestUri to its
      // identity (user/host/port) part before searching in the
      // database.  The requestUri identity is matched against the
      // "identity" column of the database, which is the identity part of
      // the "uri" column which is stored in registration.xml.

      UtlString identity;
     requestUriCopy.getIdentity(identity);
     _dataStore.regDB().getUnexpiredContactsUser(identity.str(), timeNow, registrations);

   }

   int numUnexpiredContacts = registrations.size();

   Os::Logger::instance().log(FAC_SIP, PRI_DEBUG,
                 "%s::lookUp got %d unexpired contacts",
                 mLogName.data(), numUnexpiredContacts);

   // Check for a per-user call forward timer.
   // Don't set timer if we're not going to forward to voicemail.
   std::ostringstream userCfwdTimer;
   bool foundUserCfwdTimer = false;

   if (method.compareTo(SIP_INVITE_METHOD) == 0)
   {
      UtlString noRoute;
      requestUriCopy.getUrlParameter("sipx-noroute", noRoute);

      if ((!noRoute.isNull()) && (noRoute.compareTo("Voicemail") == 0))
      {
          // This is not a call scenerio controlled by this users "forward to voicemail" timer
      }
      else
      {
          UtlString identity;
          requestUriCopy.getIdentity(identity);
          EntityRecord entity;

          foundUserCfwdTimer = _dataStore.entityDB().findByIdentity(identity.str(), entity);
          if (foundUserCfwdTimer)
            userCfwdTimer << entity.callForwardTime();
      }
   }

   for (RegDB::Bindings::const_iterator iter = registrations.begin(); iter != registrations.end(); iter++)
   {
      // Query the Registration DB for the contact, expires and qvalue columns.

      Os::Logger::instance().log(FAC_SIP, PRI_DEBUG,
                    "%s::lookUp contact = '%s', qvalue = '%s', path = '%s'",
                    mLogName.data(), iter->getContact().c_str(), iter->getQvalue().c_str(), iter->getPath().c_str() );
      Url contactUri(iter->getContact().c_str());

      // If available set the per-user call forward timer.
      if (foundUserCfwdTimer)
      {
          contactUri.setHeaderParameter("expires", userCfwdTimer.str().c_str());
      }

      // If the contact URI is the same as the request URI, ignore it.
      if (!contactUri.isUserHostPortEqual(requestUriCopy))
      {
         // Check if the q-value from the database is valid, and if so,
         // add it into contactUri.
         if (!iter->getQvalue().empty())
         {
            // :TODO: (XPL-3) need a RegEx copy constructor here
            // Check if q value is numeric and between the range 0.0 and 1.0.
            static RegEx qValueValid("^(0(\\.\\d{0,3})?|1(\\.0{0,3})?)$");
            if (qValueValid.Search(iter->getQvalue().c_str()))
            {
               contactUri.setFieldParameter(SIP_Q_FIELD, iter->getQvalue().c_str());
            }
         }

         // Re-apply any grid parameter.
         if (gridPresent)
         {
            contactUri.setUrlParameter("grid", gridParameter);
         }

         contactUri.setUrlParameter(SIP_SIPX_CALL_DEST_FIELD, "INT");
         // Check if database contained a Path value.  If so, add a Route
         // header parameter to the contact with the Path vector taken from
         // the registration data.
         if (!iter->getPath().empty())
         {
            UtlString existingRouteValue;
            std::string pathVector = iter->getPath();
            if ( contactUri.getHeaderParameter(SIP_ROUTE_FIELD, existingRouteValue))
            {
               // there is already a Route header parameter in the contact; append it to the
               // Route derived from the Path vector.
                pathVector += SIP_MULTIFIELD_SEPARATOR;
                pathVector += existingRouteValue.str();
            }
            contactUri.setHeaderParameter(SIP_ROUTE_FIELD, pathVector.c_str());
         }

         // Add the contact.
         contactList.add( contactUri, *this );
      }
   }

   return RedirectPlugin::SUCCESS;
}
Esempio n. 5
0
UtlBoolean UtlString::findToken(const char* token,
                                const char* delimiter,
                                const char* suffix,
                                bool regex) const
{
    RegEx*   ptmpRegEx = NULL;
    UtlBoolean  matched = FALSE;

    // build regular expression
    UtlString regExpStr;
    // find beginning of line or delimiter
    regExpStr.append("(^|");
    regExpStr.append(delimiter);
    regExpStr.append(')');

    // allow whitespace around token
    regExpStr.append(SWS);

    // Insert 'token' correctly, based on the value of 'regex'.
    if (regex)
    {
       // 'token' is a regexp.
       // Must parenthesize 'token', as it may contain operations with
       // low precedence.
       regExpStr.append('(');
       regExpStr.append(token);
       regExpStr.append(')');
    }
    else
    {
       // 'token' is a literal string and must be quoted.
       UtlString quoted;
       RegEx::Quotemeta(token, quoted);
       regExpStr.append(quoted);
    }

    // More whitespace.
    regExpStr.append(SWS);

    // find another delimiter, end of line or (optional) suffix
    regExpStr.append('(');
    regExpStr.append(delimiter);
    if (suffix)
    {
       regExpStr.append('|');
       regExpStr.append(suffix);
    }
    regExpStr.append("|$)");
    // "(^|" delimiter ")" SWS "\Q" token "\E" SWS "(" delimiter "|" suffix "|$)");
    // e.g., with delimiter = "," and suffix= ";" 
    //      '( ^|,) SWS \Q token \E SWS (,|;|$)'
    // e.g., with delimiter = "," and without suffix
    //      '( ^|,) SWS \Q token \E SWS (,|$)'

#ifdef TEST_FINDTOKEN
    OsSysLog::add( FAC_LOG, PRI_DEBUG
                  ,"UtlString::findToken: "
                   "built regexp '%s' to find '%s' with delimiter '%s' "
                   "suffix '%s'"
                  ,regExpStr.data(),token, delimiter,
                   suffix);
#endif

    try
    {
       // Compile regExpStr into a RegEx, set the case-insensitive flag.
       ptmpRegEx = new RegEx(regExpStr.data(), PCRE_CASELESS);
    }
    catch(const char* compileError)
    {
        OsSysLog::add( FAC_LOG, PRI_ERR
                      ,"UtlString::findToken: "
                       "Invalid regexp '%s' for '%s': "
                       "compile error '%s'"
                      ,regExpStr.data()
                      ,data()
                      ,compileError
                      );
    }

    if (ptmpRegEx)
    {
        matched = ptmpRegEx->Search(data());
        delete ptmpRegEx;
    }

#ifdef TEST_FINDTOKEN
    OsSysLog::add( FAC_LOG, PRI_DEBUG
                  ,"UtlString::findToken: "
                   "'%s' with delimiter '%s' %sfound in '%s': "
                  ,token
                  ,delimiter
                  ,(matched ? "":"not ")
                  ,data()
                  );
#endif
    return matched;
}