예제 #1
0
/* The class */
Opal::Sip::EndPoint::EndPoint (Opal::CallManager & _manager,
                               Ekiga::ServiceCore& core):
  SIPEndPoint (_manager),
  manager (_manager)
{
  boost::shared_ptr<Ekiga::ChatCore> chat_core = core.get<Ekiga::ChatCore> ("chat-core");
  boost::shared_ptr<Ekiga::PresenceCore> presence_core = core.get<Ekiga::PresenceCore> ("presence-core");

  protocol_name = "sip";
  uri_prefix = "sip:";

  dialect = boost::shared_ptr<SIP::Dialect>(new SIP::Dialect (presence_core, boost::bind (&Opal::Sip::EndPoint::send_message, this, _1, _2)));
  chat_core->add_dialect (dialect);

  /* Timeouts */
  SetAckTimeout (PTimeInterval (0, 32));
  SetPduCleanUpTimeout (PTimeInterval (0, 1));
  SetInviteTimeout (PTimeInterval (0, 60));
  SetNonInviteTimeout (PTimeInterval (0, 6));
  SetRetryTimeouts (500, 4000);
  SetMaxRetries (8);

  /* Update the User Agent */
  SetUserAgent ("Ekiga/" PACKAGE_VERSION);

  /* Ready to take calls */
  manager.AddRouteEntry("sip:.* = pc:*");
  manager.AddRouteEntry("pc:.* = sip:<da>");

  /* NAT Binding */
  SetNATBindingRefreshMethod (SIPEndPoint::Options);

  settings = boost::shared_ptr<Ekiga::Settings> (new Ekiga::Settings (SIP_SCHEMA));
  settings->changed.connect (boost::bind (&EndPoint::setup, this, _1));
}
예제 #2
0
파일: jaiku.cpp 프로젝트: SATOSHI-G/Chirrup
bool
CJaiku::GetRequestToken(
        const char *consumerKey,
        const char *consumerSecret,
        CString    &oauthToken,
        CString    &oauthTokenSecret
    )
{
    bool    ret = false;

    time_t  t  = time( NULL );
    size_t  sz = MAX_CONTENT_SIZE * 16;
    char    base[MAX_CONTENT_SIZE];
    char    param[MAX_CONTENT_SIZE];
    char    nonce[MAX_KEYLENGTH];
    char    key[MAX_KEYLENGTH * 2];

    char    *request  = new char[sz];
    char    *response = new char[sz];

    CString targetURL = _T("");
    targetURL.LoadString(IDS_URL_JAIKU_REQUEST_TOKEN);

    strcpy( nonce, getNonce(NULL) );

    sprintf( key, "%s&", encodeURLi( consumerSecret, FALSE ) );

    sprintf( base,
             "GET&"
             "%s&",
             encodeURLi( targetURL, FALSE ) );
    sprintf( param,
             "oauth_consumer_key=%s&"
             "oauth_nonce=%s&"
             "oauth_signature_method=HMAC-SHA1&"
             "oauth_timestamp=%ld&"
             "oauth_version=1.0",
             consumerKey,
             nonce,
             t );

    MakeOAuthRequest( targetURL, "GET", request, key, base, param );

    SetUserAgent();
    setUpReceiveBuffer( response, sz );
    _http_getBASIC( request, NULL, NULL, response, NULL, NULL );
    ret = GetToken( response, oauthToken, oauthTokenSecret );

    delete [] response;
    delete [] request;

    return ( ret );
}
예제 #3
0
/* The class */
Opal::Sip::EndPoint::EndPoint (Opal::CallManager & _manager, 
                               Ekiga::ServiceCore & _core, 
                               unsigned _listen_port)
:   SIPEndPoint (_manager),
    manager (_manager), 
    core (_core),
    presence_core (*(dynamic_cast<Ekiga::PresenceCore *> (core.get ("presence-core")))),
    runtime (*(dynamic_cast<Ekiga::Runtime *> (core.get ("runtime")))),
    account_core (*(dynamic_cast<Ekiga::AccountCore *> (core.get ("account-core"))))
{
  Ekiga::ChatCore* chat_core;

  protocol_name = "sip";
  uri_prefix = "sip:";
  listen_port = _listen_port;

  chat_core = dynamic_cast<Ekiga::ChatCore *> (core.get ("chat-core"));
  dialect = new SIP::Dialect (core, sigc::mem_fun (this, &Opal::Sip::EndPoint::send_message));
  chat_core->add_dialect (*dialect);

  /* Timeouts */
  SetAckTimeout (PTimeInterval (0, 32));
  SetPduCleanUpTimeout (PTimeInterval (0, 1));
  SetInviteTimeout (PTimeInterval (0, 6));
  SetNonInviteTimeout (PTimeInterval (0, 6));
  SetRetryTimeouts (500, 4000);
  SetMaxRetries (8);

  /* Start listener */
  set_listen_port (listen_port);

  /* Update the User Agent */
  SetUserAgent ("Ekiga/" PACKAGE_VERSION);

  /* Ready to take calls */
  manager.AddRouteEntry("sip:.* = pc:<db>");
  manager.AddRouteEntry("pc:.* = sip:<da>");

  /* NAT Binding */
  SetNATBindingRefreshMethod (SIPEndPoint::EmptyRequest);

  Ekiga::PersonalDetails *details = dynamic_cast<Ekiga::PersonalDetails *> (_core.get ("personal-details"));
  if (details)
    publish (*details);
}
예제 #4
0
/* The class */
Opal::Sip::EndPoint::EndPoint (Opal::EndPoint & _endpoint,
                               const Ekiga::ServiceCore& _core): SIPEndPoint (_endpoint),
                                                                 core (_core)
{
  /* Timeouts */
  SetRetryTimeouts (500, 4000);
  SetMaxRetries (20);

  /* Update the User Agent */
  SetUserAgent ("Ekiga/" PACKAGE_VERSION);

  /* Ready to take calls */
  GetManager ().AddRouteEntry("sip:.* = pc:*");
  GetManager ().AddRouteEntry("pc:.* = sip:<da>");

  /* Keepalive */
  PTimeInterval timeout;
  KeepAliveType type;
  GetKeepAlive (timeout, type);
  SetKeepAlive (timeout, KeepAliveByOPTION);
}
예제 #5
0
파일: sip-endpoint.cpp 프로젝트: Klom/ekiga
/* The class */
Opal::Sip::EndPoint::EndPoint (Opal::CallManager & _manager,
                               Ekiga::ServiceCore& core):
  SIPEndPoint (_manager),
  manager (_manager)
{
  boost::shared_ptr<Ekiga::ChatCore> chat_core = core.get<Ekiga::ChatCore> ("chat-core");

  protocol_name = "sip";
  uri_prefix = "sip:";
  listen_port = gm_conf_get_int (SIP_KEY "listen_port");
  listen_port = (listen_port > 0 ? listen_port : 5060);

  dialect = boost::shared_ptr<SIP::Dialect>(new SIP::Dialect (core, boost::bind (&Opal::Sip::EndPoint::send_message, this, _1, _2)));
  chat_core->add_dialect (dialect);

  /* Timeouts */
  SetAckTimeout (PTimeInterval (0, 32));
  SetPduCleanUpTimeout (PTimeInterval (0, 1));
  SetInviteTimeout (PTimeInterval (0, 60));
  SetNonInviteTimeout (PTimeInterval (0, 6));
  SetRetryTimeouts (500, 4000);
  SetMaxRetries (8);

  /* Start listener */
  set_listen_port (listen_port);

  /* Update the User Agent */
  SetUserAgent ("Ekiga/" PACKAGE_VERSION);

  /* Ready to take calls */
  manager.AddRouteEntry("sip:.* = pc:*");
  manager.AddRouteEntry("pc:.* = sip:<da>");

  /* NAT Binding */
  SetNATBindingRefreshMethod (SIPEndPoint::Options);
}
예제 #6
0
CLastFMFile::CLastFMFile() : CCurlFile()
{
  SetUserAgent("");
  SetBufferSize(8192);
}
예제 #7
0
파일: jaiku.cpp 프로젝트: SATOSHI-G/Chirrup
// timeline を取得
CString
CJaiku::GetTimeline(
            CString          &messages,
            JAIKU_STATUS     **stat,
            long             &numOfStats,
            TIMELINE_TYPE    timelineType,
            const char       *endPointURL,
            CTwitterTimeline *timeline,
            ProceedingDialog *pdlg )
{
    CChirrupApp *ap = (CChirrupApp *)AfxGetApp();

    if ( timeline->m_numOfStats > 0 ) {
        if ( !(*stat) ) {
            *stat = new JAIKU_STATUS[MAX_NUMOFSTATUS];
            numOfStats = 0;
        }

        Twitter2Jaiku( *stat, timeline->m_stat, timeline->m_numOfStats );
        numOfStats = timeline->m_numOfStats;
    }

    size_t  sz = MAX_CONTENT_SIZE * 16;
    char    *response = new char[sz];
    if ( response ) {
        CString url = endPointURL;

        if ( (timelineType != PUBLIC_TIMELINE) && m_useOAuth ) {
            // OAuth 認証
            char    *request = new char[sz];
            char    targetURL[MAX_URLLENGTH];
            char    *p = strchr( url, '?' );
            bool    userTimeline = false;
            if ( p ) {
                strncpy( targetURL, url, p - url );
                targetURL[p - url] = NUL;
                userTimeline = true;
            }
            else
                strcpy( targetURL, url );

            char    key[MAX_KEYLENGTH * 2];
            char    base[MAX_CONTENT_SIZE];
            char    param[MAX_CONTENT_SIZE];

            key[0]   = NUL;
            base[0]  = NUL;
            param[0] = NUL;
            MakeOAuthBase( targetURL, "GET", key, base, param );

            if ( userTimeline )
                sprintf( param + strlen(param),
                         "&"
                         "user=%s",
                         (const char *)m_username );
            MakeOAuthRequest( targetURL, "GET", request, key, base, param );

            SetUserAgent();
            setUpReceiveBuffer( response, sz );
            _http_getBASIC(request, NULL, NULL, response, NULL, NULL);
            delete [] request;
        }
        else {
            // 従来の認証
            SetUserAgent();
            setUpReceiveBuffer( response, sz );
            _http_get( url, response, pdlg );
        }
        if ( response[0] && !strstr( response, "<!DOCTYPE" ) ) {
            GetJaikuPresenceFromJSON( response, timelineType );
            WriteLog( timeline );

            int             i;
            TWITTER_STATUS  ts;
            messages = _T("");
            for ( i = 0; i < numOfStats; i++ ) {
                if ( ap->m_event ) {
                    DWORD   r = WaitForSingleObject( ap->m_event, 0 );
                    if ( r == WAIT_OBJECT_0 ) {
                        // 作業中断
                        ResetEvent( ap->m_event );
#ifdef  _DEBUG
                        MessageBox( NULL,
                                    "作業中断",
                                    "CJaiku::GetTimeline()",
                                    MB_OK|MB_ICONWARNING );
#endif
                        break;
                    }
                }

                ts.createdAt = (*stat)[i].createdAt;
                strcpy( ts.id,              (*stat)[i].id );
                strcpy( ts.text,            (*stat)[i].title );
                strcpy( ts.user.screenName, (*stat)[i].user.nick ); 

                MakeMessageForScreen( messages, &ts );
                if ( messages.GetLength() >= (MAX_CONTENT_SIZE / 2) )
                    break;
            }
        }

        delete [] response;
    }

    timeline->m_numOfStats = numOfStats;
    if ( timeline->m_numOfStats > 0 ) {
        int i;
        for ( i = 0; i < timeline->m_numOfStats; i++ ) {
            if ( ap->m_event ) {
                DWORD   r = WaitForSingleObject( ap->m_event, 0 );
                if ( r == WAIT_OBJECT_0 ) {
                    // 作業中断
                    ResetEvent( ap->m_event );
#ifdef  _DEBUG
                    MessageBox( NULL,
                                "作業中断",
                                "CJaiku::GetTimeline()",
                                MB_OK|MB_ICONWARNING );
#endif
                    break;
                }
            }

            Jaiku2Twitter( *(timeline->m_stat + i), *((*stat) + i) );
        }
    }

    return ( messages );
}
예제 #8
0
파일: jaiku.cpp 프로젝트: SATOSHI-G/Chirrup
// 発言を投稿
bool
CJaiku::PostPresence( CString monologue, ProceedingDialog *pdlg )
{
    bool    ret = false;
    size_t  sz  = MAX_CONTENT_SIZE;
    size_t  len = monologue.GetLength() * 18;
    char    *request  = new char[BUFSIZ + len + 1];
    char    *response = new char[sz];
    char    url[MAX_URLLENGTH];
    char    cid[MAX_KEYLENGTH];

    strcpy( url, "http://api.jaiku.com/json" );
    cid[0] = NUL;
    if ( !strncmp( monologue, ">>", 2 ) ) {
        strncpy( cid, ((const char *)monologue) + 2, MAX_KEYLENGTH - 2 );
        cid[MAX_KEYLENGTH - 2] = NUL;

        char    *p = strchr( cid, ' ' );
        if ( p ) {
            *p = NUL;
            monologue = strchr( monologue, ' ' ) + 1;
        }
    }

    char        *p = sjis2utf( monologue );

    if ( request && response ) {
        if ( m_useOAuth ) {
            // OAuth 認証
            delete [] request;
            request = new char[sz];

            char    key[MAX_KEYLENGTH * 2];
            char    base[MAX_CONTENT_SIZE];
            char    param[MAX_CONTENT_SIZE];

            key[0]   = NUL;
            base[0]  = NUL;
            param[0] = NUL;

            sprintf( request, "%s", p ? p : (const char *)monologue );
            p = GetTinyURL( request );
            sprintf( param,
                     "message=%s&"
                     "method=post&"
                     "nick=%s&",
                     encodeURLi( p ? p : monologue, FALSE ),
                     (const char *)m_username );
            MakeOAuthBase( url, "POST", key, base, param );

            sprintf( param + strlen(param),
                     "&"
                     "user=%s",
                     (const char *)m_username );
            MakeOAuthRequest( url, "POST", request, key, base, param );
        }
        else {
            // 従来の認証
            sprintf( request, "status=%s",
                     encodeURL( p ? p : (const char *)monologue ) );
            setUpReceiveBuffer( response, sz );
            sprintf( request,
                     "user=%s&"
                     "personal_key=%s&"
                     "method=%s&"
                     "message=%s&",
                     (const char *)m_username,
                     (const char *)m_apiKey,
#ifdef  JAIKU_LEGACY_API
                     "presence.send",
#else
                     "post",
#endif
                     encodeURL( p ) );
#ifdef  FEATURE_NOT_AVAILABLE
            if ( cid[0] ) {
                /*
                sprintf( url,
                         "http://api.jaiku.com/presence/%s/json",
                         cid );
                */
                sprintf( request,
                         "user=%s&"
                         "personal_key=%s&"
                         "method=%s&"
                         "presence=%s&"
                         "message=%s&",
                         m_username,
                         m_apiKey,
                         "presence.send",
                         cid,
                         encodeURL( p ) );
            }
#endif
        }
        SetUserAgent();
        setUpReceiveBuffer( response, sz );
        _http_post( url, request, response, pdlg );
        if ( *response ) {
            if ( strstr( response, "{\"status\":\"ok\"}" ) )
                ret = true;
        }
    }

    if ( response )
        delete [] response;
    if ( request )
        delete [] request;

    return ( ret );
}
예제 #9
0
파일: jaiku.cpp 프로젝트: SATOSHI-G/Chirrup
bool
CJaiku::GetAccessToken(
        const char *consumerKey,
        const char *consumerSecret,
        CString    &oauthToken,
        CString    &oauthTokenSecret
    )
{
    bool    ret = false;

    if ( !consumerKey    || !(*consumerKey)    ||
         !consumerSecret || !(*consumerSecret)    )
        return ( ret );

    // request token 取得
    CString _oauthToken       = _T("");
    CString _oauthTokenSecret = _T("");
    if ( !GetRequestToken( consumerKey, consumerSecret,
                           _oauthToken, _oauthTokenSecret ) ) {
        MessageBox( NULL,
                    "リクエストトークンの取得に失敗しました。  ",
                    "アクセス中止", MB_OK|MB_ICONERROR );
        return ( ret );
    }

    // ブラウザ起動 -- ユーザにアクセス許可を求める
    CString targetURL = _T("");
    targetURL.LoadString(IDS_URL_JAIKU_AUTHORIZE);

    char    url[MAX_URLLENGTH];
    sprintf( url,
             "%s?"
             "oauth_token=%s&"
             "perms=%s",
             targetURL,
             _oauthToken,
             "write" );
    ShellExecute( NULL, "open", url, NULL, NULL, SW_SHOWNORMAL );

    // ユーザの許可待ち
    int r = MessageBox( NULL,
            "Chirrup が Jaiku にアクセスする許可を与えてください。\r\n"
            "許可を与え終わったら、OK ボタンを押してください。\r\n"
            "許可を与えたくない場合は キャンセル ボタンを押してください。  ",
            "Jaiku へのアクセス許可", MB_OKCANCEL|MB_ICONINFORMATION );
    if ( r != IDOK ) {
        MessageBox( NULL,
                    "Jaiku へのアクセスを中止します。  ",
                    "アクセス中止", MB_OK|MB_ICONWARNING );
        return ( ret );
    }

    // access token 取得
    time_t  t  = time( NULL );
    size_t  sz = MAX_CONTENT_SIZE * 16;
    char    base[MAX_CONTENT_SIZE];
    char    param[MAX_CONTENT_SIZE];
    char    nonce[MAX_KEYLENGTH];
    char    key[MAX_KEYLENGTH * 2];

    char    *request  = new char[sz];
    char    *response = new char[sz];

    targetURL = _T("");
    targetURL.LoadString(IDS_URL_JAIKU_ACCESS_TOKEN);

    strcpy( nonce, getNonce(NULL) );

    sprintf( key,
             "%s&",
             encodeURLi( consumerSecret, FALSE ) );
    sprintf( key + strlen(key),
             "%s",
             encodeURLi( _oauthTokenSecret, FALSE ) );

    sprintf( base,
             "GET&"
             "%s&",
             encodeURLi( targetURL, FALSE ) );
    sprintf( param,
             "oauth_consumer_key=%s&"
             "oauth_nonce=%s&"
             "oauth_signature_method=HMAC-SHA1&"
             "oauth_timestamp=%ld&"
             "oauth_token=%s&"
             "oauth_version=1.0",
             consumerKey,
             nonce,
             t,
             _oauthToken );

    MakeOAuthRequest( targetURL, "GET", request, key, base, param );

    SetUserAgent();
    setUpReceiveBuffer( response, sz );
    _http_getBASIC( request, NULL, NULL, response, NULL, NULL );
    ret = GetToken( response, oauthToken, oauthTokenSecret );

    if ( ret ) {
        m_oauthToken       = oauthToken;
        m_oauthTokenSecret = oauthTokenSecret;
    }
    else
        MessageBox( NULL,
                    "アクセストークンの取得に失敗しました。  ",
                    "アクセス中止", MB_OK|MB_ICONERROR );

    delete [] response;
    delete [] request;

    return ( ret );
}