Пример #1
0
UtlBoolean SipLine::getPreferredContactUri(Url& preferredContactUri) const
{
    UtlString host ; 

    preferredContactUri = mPreferredContactUri ;
    preferredContactUri.getHostAddress(host) ;

    return (host.length() > 0) ;
}
Пример #2
0
int AuthCommand::execute(int argc, char* argv[])
{
  int commandStatus = CommandProcessor::COMMAND_FAILED;
  Url      identity;
  UtlString user;
  UtlString realm;
  UtlString password;

  switch ( argc )
    {
    case 2:
      // Delete Identity
      identity = argv[1];

      printf( "Deleting identity '%s'\n", argv[1] );
      mLineMgr.deleteLine( identity );
      break;

    case 3: // <identity-url> <password>
    case 5: // <identity-url> <user> <realm> <password>
      {
        // Add Identity
        identity = argv[1];

        if ( 3 == argc )
          {
            identity.getHostAddress( realm );
            identity.getUserId( user );
            user.append("@");
            user.append(realm);
            password = argv[2];
          }
        else
          {
            user     = argv[2];
            realm    = argv[3];
            password = argv[4];
          }

        SipLine  line( identity // user entered url
                      ,identity // identity url
                      ,user     // user
                      ,TRUE     // visible
                      ,SipLine::LINE_STATE_PROVISIONED
                      ,TRUE     // auto enable
                      ,FALSE    // use call handling
                      );

        mLineMgr.addLine( line );

        UtlString cred_input;
        UtlString cred_digest;

        cred_input.append( user );
        cred_input.append( ":" );
        cred_input.append( realm );
        cred_input.append( ":" );
        cred_input.append( password );

        NetMd5Codec::encode( cred_input.data(), cred_digest );

        printf("Adding identity '%s': user='******' realm='%s' password='******'\n"
               "                      H(A1)='%s'\n"
               ,identity.toString().data(), user.data(), realm.data()
               ,password.data(), cred_digest.data()
               );

        commandStatus = (   mLineMgr.addCredentialForLine( identity, realm, user, cred_digest
                                                          ,HTTP_DIGEST_AUTHENTICATION
                                                          )
                         )
          ? CommandProcessor::COMMAND_SUCCESS
          : CommandProcessor::COMMAND_FAILED
          ;
      }
      break;

    default:
      fprintf( stderr, "%s: Invalid number of arguments\n", argv[0] );
      fprintf( stderr, "%s%s", argv[0], UsageMsg );
      break;
    }

  return(commandStatus);
}
bool
SipRedirectorAliasDB::resolveAlias(
   const SipMessage& message,
   UtlString& requestString,
   Url& requestUri
)
{
  bool isDomainAlias = false;
  bool isUserAlias = false;

  UtlString domain;
  UtlString hostAlias;
  UtlString userAlias;

  requestUri.getHostAddress(domain);
  UtlBoolean isMyHostAlias = mpSipUserAgent->isMyHostAlias(requestUri);
  if (mpSipUserAgent && domain != _localDomain && isMyHostAlias)
  {
    isDomainAlias = true;
    hostAlias = domain;
  }

  UtlString requestIdentity;
  requestUri.getIdentity(requestIdentity);

  EntityDB::Aliases aliases;
  bool isUserIdentity = false;
  EntityDB* entityDb = SipRegistrar::getInstance(NULL)->getEntityDB();
  entityDb->getAliasContacts(requestUri, aliases, isUserIdentity);
  int numAliasContacts = aliases.size();
  EntityDB::Aliases::iterator iter = aliases.begin();

  if (numAliasContacts == 1 && iter != aliases.end())
  {
    // If disableForwarding and the relation value is "userforward",
    // do not record this contact.
    if (isUserIdentity && iter->relation != ALIASDB_RELATION_USERFORWARD && iter->relation != "callgroup")
    {
      UtlString contact = iter->contact.c_str();
      Url contactUri(contact);
      isUserAlias = true;
      contactUri.getUserId(userAlias);
    }
  }


  if (isUserAlias)
  {
    requestUri.setUserId(userAlias.data());
    requestUri.getUri(requestString);
  }

  if (isDomainAlias)
  {
    requestUri.setHostAddress(hostAlias);
    requestUri.getUri(requestString);
  }

  if (isUserAlias || isDomainAlias)
  {
    OS_LOG_NOTICE(FAC_SIP, "SipRedirectorAliasDB::lookUp normalized request-uri to " << requestString.data());
  }


  return isUserAlias || isDomainAlias;
}
Пример #4
0
OsStatus ForwardRules::parseRouteMatchContainer(const Url& requestUri,
                                              const SipMessage& request,
                                              UtlString& routeToString,
                                              UtlString& mappingType,
                                              bool& authRequired,
                                              TiXmlNode* routesNode,
                                              TiXmlNode* previousRouteMatchNode)
{
   UtlString testHost;
   requestUri.getHostAddress(testHost);
   int testPort = requestUri.getHostPort();
   if(testPort == SIP_PORT)
   {
      testPort = PORT_NONE;
   }
   
   UtlBoolean routeMatchFound = false;
   OsStatus methodMatchFound = OS_FAILED;
   
  	TiXmlElement* routesElement = routesNode->ToElement();

   TiXmlNode* routeMatchNode = previousRouteMatchNode;
   // Iterate through routes container children looking for 
   // route tags
   while ( (routeMatchNode = routesElement->IterateChildren(routeMatchNode)) 
      && methodMatchFound != OS_SUCCESS)
   {
      // Skip non-elements
      if(routeMatchNode && routeMatchNode->Type() != TiXmlNode::ELEMENT)
      {
         continue;
      }

      // Skip non-route elements
      TiXmlElement* routeMatchElement = routeMatchNode->ToElement();
      UtlString tagValue =  routeMatchElement->Value();
      if(tagValue.compareTo(XML_TAG_ROUTEMATCH) != 0 )
      {
         continue;
      }

      mappingType.remove(0);
      routeToString.remove(0);
      const char* mappingTypePtr = 
          routeMatchElement->Attribute(XML_ATT_MAPPINGTYPE);

      //get the mapping Type attribute
      mappingType.append(mappingTypePtr ? mappingTypePtr : "");

      // Iterate through the route container's children looking
      // for routeFrom, routeIPv4subnet, or routeDnsWildcard elements
      TiXmlNode* routeFromPatternNode = NULL;
      for( routeFromPatternNode = routeMatchElement->FirstChildElement();
         routeFromPatternNode;
         routeFromPatternNode = routeFromPatternNode->NextSiblingElement() )
      {
         // Skip elements that aren't of the "domainMatches" family 
         enum {ret_from, ret_ip, ret_dns} routeElementType ;

         const char *name = routeFromPatternNode->Value() ;
         if (strcmp(name, XML_TAG_ROUTEFROM) == 0)
         {
            routeElementType = ret_from;
         }
         else if (strcmp(name, XML_TAG_ROUTEIPV4SUBNET) == 0)
         {
            routeElementType = ret_ip;
         }
         else if (strcmp(name, XML_TAG_ROUTEDNSWILDCARD) == 0)
         {
            routeElementType = ret_dns;
         }
         else
         {
            continue ;
         }


         //found "domainMatches" pattern tag
         TiXmlElement* routeFromPatternElement = routeFromPatternNode->ToElement();
         //get the text value from it
         TiXmlNode* routeFromPatternText = routeFromPatternElement->FirstChild();
         if(routeFromPatternText && routeFromPatternText->Type() == TiXmlNode::TEXT)
         {
            TiXmlText* Xmlpattern = routeFromPatternText->ToText();
            if (Xmlpattern)
            {
               UtlString pattern = Xmlpattern->Value();

               switch(routeElementType)
               {
                  case ret_from: // a routeFrom element matches host and port
                  {
                     Url xmlUrl(pattern.data());
                     UtlString xmlHost;
                     xmlUrl.getHostAddress(xmlHost);
                     int xmlPort = xmlUrl.getHostPort();

                     // See if the host and port of the routeFrom elelment
                     // match that of the URI
                     if( (xmlHost.compareTo(testHost, UtlString::ignoreCase) == 0) &&
                        ((xmlPort == SIP_PORT && testPort == PORT_NONE) ||
                         xmlPort == testPort) )
                     {
                        routeMatchFound = true;
                        Os::Logger::instance().log(FAC_SIP, PRI_DEBUG, "ForwardRules::parseRouteMatchContainer - routeFrom %s matches %s", testHost.data(), pattern.data());
                     }
                  }
                  break ;

                  case ret_ip: // a routeIPv4subnet matches if the subnet does
                  {
                     // "pattern" is a subnet in CIDR notation (x.y.z.q/size)
                     // "testHost is supposed to be an IPv4 dotted quad

                     routeMatchFound = mPatterns->
                                          IPv4subnet(testHost, pattern);
                  }
                  break ;

                  case ret_dns: // a routeDnsWildcard matches if the domain name does
                  {
                     // "pattern" is a wildcard DNS (*.pingtel.com)
                     // "testHost is a FQDN
                     routeMatchFound = mPatterns->
                                          DnsWildcard(testHost, pattern);
  
                  }
                  break ;
               }

               if (routeMatchFound)
               {
                  previousRouteMatchNode = routeMatchNode;
                  // Find a match to the request method and recurse
                  // to find child element field(s) matches  and
                  // get the routeTo value
                  methodMatchFound = parseMethodMatchContainer(request,
                     routeToString,
                     authRequired,
                     routeMatchNode);

                  if( methodMatchFound == OS_SUCCESS)
                     break;
               }
            }
         }
      }
   }
   return methodMatchFound;
}
Пример #5
0
RedirectPlugin::LookUpStatus
SipRedirectorAliasDB::lookUp(
   const SipMessage& message,
   UtlString& requestString,
   Url& requestUri,
   const UtlString& method,
   ContactList& contactList,
   RequestSeqNo requestSeqNo,
   int redirectorNo,
   SipRedirectorPrivateStorage*& privateStorage,
   ErrorDescriptor& errorDescriptor)
{
   // If url param sipx-userforward = false, do not redirect to user-forward
   // aliases.
   UtlString userforwardParam;
   requestUri.getUrlParameter("sipx-userforward", userforwardParam);
   bool disableForwarding =
      userforwardParam.compareTo("false", UtlString::ignoreCase) == 0;
   if (disableForwarding)
   {
      Os::Logger::instance().log(FAC_SIP, PRI_DEBUG, "%s::lookUp user forwarding disabled by parameter",
                    mLogName.data());
   }

   bool isDomainAlias = false;
   UtlString domain;
   UtlString hostAlias;
   requestUri.getHostAddress(domain);
   UtlBoolean isMyHostAlias = mpSipUserAgent->isMyHostAlias(requestUri);
   if (mpSipUserAgent && domain != _localDomain && isMyHostAlias)
   {
     isDomainAlias = true;
     hostAlias = domain;
     requestUri.setHostAddress(_localDomain);
   }

   UtlString requestIdentity;
   requestUri.getIdentity(requestIdentity);

   OS_LOG_DEBUG(FAC_SIP, mLogName.data() << "::lookUp identity: " << requestIdentity.data()
           << " domain: " << domain.data()
           << " local-domain: " << _localDomain.data()
           << " isHostAlias: " << isMyHostAlias);

   
   //ResultSet aliases;
   //AliasDB::getInstance()->getContacts(requestUri, aliases);
   //int numAliasContacts = aliases.getSize();

   EntityDB::Aliases aliases;
   bool isUserIdentity = false;
   EntityDB* entityDb = SipRegistrar::getInstance(NULL)->getEntityDB();
   entityDb->getAliasContacts(requestUri, aliases, isUserIdentity);
   int numAliasContacts = aliases.size();

   if (numAliasContacts > 0)
   {
      Os::Logger::instance().log(FAC_SIP, PRI_DEBUG, "%s::lookUp "
                    "got %d AliasDB contacts", mLogName.data(),
                    numAliasContacts);

      // Check if the request identity is a real user/extension
      UtlString realm;
      UtlString authType;
      

      SipXauthIdentity authIdentity;
      authIdentity.setIdentity(requestIdentity);

      for (EntityDB::Aliases::iterator iter = aliases.begin(); iter != aliases.end(); iter++)
      {

            // If disableForwarding and the relation value is "userforward",
            // do not record this contact.
            if (!(disableForwarding && iter->relation == ALIASDB_RELATION_USERFORWARD))
            {
               UtlString contact = iter->contact.c_str();
               Url contactUri(contact);

               // if the request identity is a real user
               if (isUserIdentity)
               {
                  // Encode AuthIdentity into the URI
                  authIdentity.encodeUri(contactUri, message);
               }

               contactUri.setUrlParameter(SIP_SIPX_CALL_DEST_FIELD, "AL");
               
               
               if (numAliasContacts == 1 && isDomainAlias && isUserIdentity)
               {

                 UtlString userId;
                 contactUri.getUserId(userId);
                 requestUri.setUserId(userId.data());
                 requestUri.getUri(requestString);
                 OS_LOG_NOTICE(FAC_SIP, "SipRedirectorAliasDB::lookUp normalized request-uri to " << requestString.data());
               }
               else
               {
                 // Add the contact.
                 contactList.add( contactUri, *this );
               }
            }
      }
   }
   else if (isDomainAlias)
   {
     //
     // No alias found.  If this is was towards a domain alias, make sure to reset it back to
     // the old value prior to feeding it to the rest of the redirectors.
     //
     requestUri.setHostAddress(hostAlias);
     requestUri.getUri(requestString);
   }

   return RedirectPlugin::SUCCESS;
}