예제 #1
0
int UtlDateTime::compareTo(UtlContainable const * inVal) const
{
   int result ; 
   
   if (inVal->isInstanceOf(UtlDateTime::TYPE))
    {
        UtlDateTime* temp = (UtlDateTime*)inVal ;
        OsDateTime inTime;
        temp->getTime(inTime);
        int tempValue = inTime.getSecsSinceEpoch() ;
        result = tempValue - mTime.getSecsSinceEpoch() ;
    }
    else
    {
        result = 1 ; 
    }

    return result ;
}
예제 #2
0
/// Encodes identity info
void SipXauthIdentity::encode(UtlString        & identityValue,
                              const UtlString  & callId,
                              const UtlString  & fromTag,
                              const OsDateTime & timestamp,
                              DialogRule       bindRule
                              )
{

   // calculate timestamp
   OsTime osTime;
   timestamp.cvtToTimeSinceEpoch(osTime);
   long seconds = osTime.seconds();
   char stamp[65];
   sprintf(stamp, "%lX", seconds);
   UtlString strSignature(stamp);

   strSignature.append(SignatureFieldSeparator);

   // signature-hash=MD5(<timestamp><secret><from-tag><call-id><identity>)
   NetMd5Codec signatureHash;
   signatureHash.hash(stamp);
   signatureHash.hash(sSignatureSecret);
   if (requireDialogBinding == bindRule)
   {
      signatureHash.hash(fromTag);
      signatureHash.hash(callId);
   }
   else
   {
      strSignature.append(SignatureFieldSeparator);
   }
   signatureHash.hash(mIdentity);

   UtlString strSignatureHash;
   signatureHash.appendHashValue(strSignature);

   Url encodedUrl(mIdentity);
   encodedUrl.setScheme(Url::SipUrlScheme);
   encodedUrl.setUrlParameter(SignatureUrlParamName, strSignature.data());

   encodedUrl.toString(identityValue);

   Os::Logger::instance().log(FAC_SIP, PRI_DEBUG,
                 "SipXauthIdentity::encode "
                 "identity '%s'",
                 identityValue.data()
                 );
}
예제 #3
0
OsStatus MpodBufferRecorder::disableDevice()
{
   assert(isEnabled());

   if (mpTickerTimer != NULL)
   {
      mpTickerTimer->stop(TRUE);
      delete mpTickerTimer;
      mpTickerTimer = NULL;
   }

   if (mpBuffer != NULL)
   {
#ifdef FINAL_RECORDED_DATA_WRITE // [
      OsDateTime now;
      OsDateTime::getCurTime(now);
      char fileName[1024];

      snprintf(fileName,
               1024, "MpodBufferRecorder-%4d.%02d.%02d.%02d-%02d-%02d.%03d.s16",
               now.getYear(), now.getMonth(), now.getDay(),
               now.getHour(), now.getMinute(), now.getSecond(),
               now.getMicrosecond()/1000);

      OsFile::openAndWrite(fileName,
                           (char*)mpBuffer,
                           mBufferEnd*sizeof(MpAudioSample));
#endif // FINAL_RECORDED_DATA_WRITE ]

      delete[] mpBuffer;
      mpBuffer = NULL;
      mBufferLength = 0;
      mBufferEnd = 0;
   }

   mIsEnabled = FALSE;

   return OS_SUCCESS;
}
예제 #4
0
/// Start the timer to fire once at the indicated date/time
bool OsTimer::Timer::oneshotAt(const OsDateTime& t)
{
  OsTimer::Time now = OsTimer::now();
  OsTime t_os;
  t.cvtToTimeSinceEpoch(t_os);
  OsTimer::Time expireFromNow = (OsTimer::Time)(t_os.seconds()) * TIMER_TIME_UNIT + t_os.usecs();

  {
    mutex_lock lock(_mutex);
    if (_isRunning)
      return false;
    else
      _isRunning = true;
 
    if (expireFromNow <= now)
    {
      OS_LOG_ERROR(FAC_KERNEL, "OsTimer::Timer::oneshotAt timer expiration is in the past.  Call ignored.");
      _isRunning = false;
      return false;
    }
    _expiresAt = expireFromNow;
  }


  //
  // This function sets the expiry time. Any pending asynchronous wait 
  // operations will be cancelled. The handler for each cancelled operation will
  // be invoked with the boost::asio::error::operation_aborted error code.
  //
  {
    mutex_lock lock(gTimerServiceMutex);
    boost::system::error_code ec;
    _pDeadline->expires_from_now(boost::posix_time::microseconds(expireFromNow - now), ec);
    //
    // Perform an assynchronous wait on the timer
    //
    _pDeadline->async_wait(boost::bind(&OsTimer::Timer::onTimerFire, shared_from_this(), boost::asio::placeholders::error, &_owner));
  }  
  return _isRunning;
}
예제 #5
0
bool EventCallBack(SIPX_EVENT_CATEGORY category,
                   void* pInfo,
                   void* pUserData)
{
    assert (pInfo != NULL);

    // Dump event
    char cBuf[1024] ;

    // Print the timestamp if requested.
    if (g_timestamp)
    {
       OsDateTime d;
       OsDateTime::getCurTime(d);
       UtlString s;
       d.getIsoTimeStringZ(s);
       printf("%s ", s.data());
    }

    printf("%s\n", sipxEventToString(category, pInfo, cBuf, sizeof(cBuf))) ;

    if (category == EVENT_CATEGORY_CALLSTATE)
    {
        SIPX_CALLSTATE_INFO* pCallInfo = static_cast<SIPX_CALLSTATE_INFO*>(pInfo);
        printf("    hCall=%d, hAssociatedCall=%d\n", pCallInfo->hCall, pCallInfo->hAssociatedCall) ;

        switch (pCallInfo->event)
        {
        case CALLSTATE_OFFERING:
           // Get and print the From: URI.
        {
            char remote[200];
            sipxCallGetRemoteID(pCallInfo->hCall, remote, sizeof (remote));
            printf("    From: %s\n", remote);
        }
            sipxCallAccept(pCallInfo->hCall) ;
            break ;
        case CALLSTATE_ALERTING:
            clearLoopback() ;
            {
               // Determine the answering delay.
               int delay;
               if (g_callAnswerDelay == NULL || g_callAnswerDelay[0] == '\0')
               {
                  // No answer string is active, so delay is 0.
                  delay = 0;
               }
               else
               {
                  // Get the delay to be used from the delay string.
                  delay = atoi(g_callAnswerDelay);
                  // Remove the first number, if there is a comma.
                  char* p = strchr(g_callAnswerDelay, ',');
                  if (p != NULL)
                  {
                     g_callAnswerDelay = p + 1;
                  }
               }
               if (delay == 0)
               {
                  // If the delay is 0, answer immediately.
                  sipxCallAnswer(pCallInfo->hCall);
               }
               else
               {
                  // The delay is non-0, so set the timer to answer.
                  // Stop the timer in case it is running.
                  callAnswerTimer.stop();
                  // Record the call to be answered.
                  callAnswerNotification.setHCall(pCallInfo->hCall);
                  // Construct the delay to be used.
                  OsTime d(delay, 0);
                  // Start the timer.
                  callAnswerTimer.oneshotAfter(d);
               }
            }
            break ;
        case CALLSTATE_CONNECTED:
           // Per conversation with Bob A., commented this sleep out
           // to prevent trouble with processing re-INVITEs that come
           // just after INVITEs.  This should be replaced with a proper
           // timer-wait event.  But that leads to the open question
           // of whether to use the sipX OsTimer system, or the underlying
           // OS mechanisms (to avoid dependency on sipXportLib).  Ugh.
           //SLEEP(1000) ;   // BAD: Do not block the callback thread

           // Start the timer that limits the length of the call.
        {
           // Stop the timer in case it is running.
           callHangupTimer.stop();
           // Record the call to be answered.
           callHangupNotification.setHCall(pCallInfo->hCall);
           // Start the timer, scaled to seconds.
           OsTime delay(iDuration, 0);
           callHangupTimer.oneshotAfter(delay);
        }

            // Play file if provided
            if (g_szFile)
            {
                if (!playFile(g_szFile, pCallInfo->hCall))
                {
                    printf("Failed to play file: %s\n", g_szFile) ;
                }
            }

            // Play tones if provided
            if (g_szPlayTones)
            {
                if (!playTones(g_szPlayTones, pCallInfo->hCall))
                {
                    printf("Failed to play tones: %s\n", g_szPlayTones) ;
                }
            }
            break ;
        case CALLSTATE_DISCONNECTED:
           // Stop the timers in case they are running.
           callAnswerTimer.stop();
           callHangupTimer.stop();
           // Destroy the call.
           sipxCallDestroy(pCallInfo->hCall) ;
           break ;
        case CALLSTATE_AUDIO_EVENT:
            if (pCallInfo->cause == CALLSTATE_AUDIO_START)
            {
                printf("* Negotiated codec: %s, payload type %d\n", pCallInfo->codecs.audioCodec.cName, pCallInfo->codecs.audioCodec.iPayloadType);
            }
            break;
        case CALLSTATE_DESTROYED:
           // Stop the timer in case it is running.
           callAnswerTimer.stop();
           break ;
        default:
           // There are many other events which we ignore.
           break;
        }
    }

    // Ensure the output is not delayed by buffering.
    fflush(stdout);

    return true;
}
예제 #6
0
UtlString MailMessage::FormatForSending()
{
    unsigned int i;
    int lineLength = 4;

    // From: "Name" <Address>
    UtlString data = "From: " + m_From.toString() + CRLF;

    // To: "Name" <Address>, "Name" <Address>
    data += "To: ";
    for (i = 0; i < m_vecTo.size(); i++)
    {
        if (lineLength + m_vecTo[i].toString().length() > 998)
        {
            data += "\r\n ";
            lineLength = 1;
        }

        data += m_vecTo[i].toString();
        lineLength += m_vecTo[i].toString().length();

        if (i < m_vecTo.size()-1)
        {
            data += ", ";
            lineLength += 2;
        }
    }
    data += CRLF;
    
    // Cc: "Name" <Address>, "Name" <Address>
    data += "Cc: ";
    for (i = 0; i < m_vecCc.size(); i++)
    {
        if (lineLength + m_vecCc[i].toString().length() > 998)
        {
            data += "\r\n ";
            lineLength = 1;
        }

        data += m_vecCc[i].toString();
        lineLength += m_vecCc[i].toString().length();

        if (i < m_vecCc.size()-1)
        {
            data += ", ";
            lineLength += 2;
        }
    }
    data += CRLF;
    
    // Subject: Subject text
    data += "Subject: " + m_Subject + CRLF;

    // Date: Mon, 25 Sep 2001 11:11:11 -0600\r\n
    UtlString dateString;
    OsDateTime now;
    OsDateTime::getCurTime(now);
    now.getHttpTimeString(dateString);
/*
    SYSTEMTIME now; GetLocalTime(&now);
    TIME_ZONE_INFORMATION tzinfo; GetTimeZoneInformation(&tzinfo);
    char *day[] = { "Sun","Mon","Tue","Wed","Thu","Fri","Sat" };
    char *month[] = { "Jan","Feb","Mar","Apr","May","Jun","Jul",
                      "Aug","Sep","Oct","Nov","Dec" };
    char buf[128];
    wsprintf(buf, "Date: %s, %u %s %u %02u:%02u:%02u %c%02u%02u",
        day[now.wDayOfWeek],
        now.wDay,
        month[now.wMonth],
        now.wYear,
        now.wHour,
        now.wMinute,
        now.wSecond,
        tzinfo.Bias > 0 ? '-' : '+',
        abs(tzinfo.Bias/60),
        abs(tzinfo.Bias%60));
*/
    char buf[128];
    sprintf(buf, "Date: %s",dateString.data());

    data += buf + CRLF;

    // MIME version header
    data += "Mime-Version: 1.0" + CRLF;

    // If attachments...
    if (m_vecAttachment.size() > 0)
    {
        UtlString boundary = "---=_Next_Part_of_Message_987456321147852369";

        // MIME content type header and separator line
        data += "Content-Type: multipart/mixed; boundary=\"" + boundary + "\""
                + CRLFCRLF;

        // Message body
        data += "--" + boundary + CRLF;
        data += "Content-Type: " + m_ContentType + CRLF;
        data += "Content-Transfer-Encoding: quoted-printable" + CRLFCRLF;
        data += m_Body + CRLF;

        // Attachments
        for (int i = 0; i < ((int)(m_vecAttachment.size())); i++)
        {
            data += "--" + boundary + CRLF;
            data += "Content-Type: " + m_vecAttachment[i].MIMEtype()
                    + "; name=\"" + m_vecAttachment[i].Filename() + "\"" + CRLF;
            data += "Content-Transfer-Encoding: base64" + CRLF;
            data += "Content-Disposition: attachment; filename=\""
                    + m_vecAttachment[i].Filename() + "\"" + CRLFCRLF;
            data += m_vecAttachment[i].Base64Data() + CRLF;
        }
        data += "--" + boundary + "--";
    }
    // No attachments
    else
    {
        // MIME content type header
        data += "Content-Type: " + m_ContentType + CRLF;

        // Separator line, body
        data += CRLF + m_Body;
    }
    data += CRLF + ".";
    data += CRLF;
    return data;
}
예제 #7
0
// Arm the timer to fire periodically starting at the indicated date/time
OsStatus OsTimer::periodicAt(const OsDateTime& when, const OsTime &period)
{
   OsTime whenTime;
   when.cvtToTimeSinceEpoch(whenTime);
   return startTimer(whenTime, TRUE, period);
}
예제 #8
0
// Arm the timer to fire once at the indicated date and time
OsStatus OsTimer::oneshotAt(const OsDateTime& when)
{
   OsTime whenTime;
   when.cvtToTimeSinceEpoch(whenTime);
   return startTimer(whenTime, FALSE, OsTime::NO_WAIT_TIME);
}