now I got segfault:
twitter.cpp
/*
Copyright 2010 Jan Koester
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include <cstring>
#include <curl/curl.h>
#include "twitter.h"
bool Twitter::getLogindata(){
try {
Session->createTables();
}catch (...) { }
Wt::Dbo::Transaction transaction(*Session);
Accounts accounts;
accounts = Session->find<Twitter>();
for (Accounts::const_iterator i = accounts.begin(); i != accounts.end();
++i){
twitterObj.getOAuth().setConsumerKey( std::string( "nACN7SW4hyD2k2iVQzVDg"
) );
twitterObj.getOAuth().setConsumerSecret( std::string(
"k8SUSQxHSn1pG7Xc76cYxelIMVKNkc0erSANBCU8c" ) );
myOAuthAccessTokenKey = (*i)->oauth_token.toUTF8();
myOAuthAccessTokenSecret = (*i)->oauth_secret.toUTF8();
qid = (*i)->id;
Tweets = "";
Followers = "";
if( myOAuthAccessTokenKey.size() && myOAuthAccessTokenSecret.size() ){
std::cerr << "Tokenkey: " << myOAuthAccessTokenKey << std::endl <<
"Tokensecret: "<< myOAuthAccessTokenSecret << std::endl;
twitterObj.getOAuth().setOAuthTokenKey( myOAuthAccessTokenKey );
twitterObj.getOAuth().setOAuthTokenSecret( myOAuthAccessTokenSecret );
Tweets += twitterObj.directMessageGet();
Followers += twitterObj.followersGet();
}else{
twitterObj.oAuthRequestToken(RequestToken);
std::cerr << "Token: " << RequestToken << std::endl;
return false;
}
}
transaction.commit();
return true;
}
void Twitter::RegisterApp(){
std::cout << "Qid: " << qid << std::endl;
twitterObj.getOAuth().setOAuthPin(AuthPin);
twitterObj.oAuthAccessToken();
twitterObj.getOAuth().getOAuthTokenKey( myOAuthAccessTokenKey );
twitterObj.getOAuth().getOAuthTokenSecret( myOAuthAccessTokenSecret );
Wt::Dbo::Transaction transaction(*Session);
Auth auth;
auth = Session->find<Twitter>().where("id = ?").bind(qid);
auth.modify()->oauth_token = myOAuthAccessTokenKey;
auth.modify()->oauth_secret = myOAuthAccessTokenSecret;
transaction.commit();
}
twitter.h
/*
Copyright 2010 Jan Koester
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef TWITTER_H_
#define TWITTER_H_
#include <cstdlib>
#include <Wt/Dbo/WtSqlTraits>
#include <Wt/Dbo/Types>
#include <Wt/Dbo/backend/Postgres>
#include <Wt/Dbo/Dbo>
#include <libtwit/twitcurl.h>
class Twitter : public Wt::Dbo::Dbo<Twitter>{
public:
Wt::Dbo::Session *Session;
typedef Wt::Dbo::collection<Wt::Dbo::ptr<Twitter >> Accounts;
typedef Wt::Dbo::ptr <Twitter> Auth;
int id;
Wt::WDate oauth_provider;
Wt::WString oauth_uid;
Wt::WString oauth_token;
Wt::WString oauth_secret;
Wt::WString username;
bool getLogindata();
template<class Action>
void persist(Action& a)
{
Wt::Dbo::field(a, id, "id");
Wt::Dbo::field(a, oauth_provider, "oauth_uid");
Wt::Dbo::field(a, oauth_uid, "oauth_uid");
Wt::Dbo::field(a, oauth_token, "oauth_token");
Wt::Dbo::field(a, oauth_secret, "oauth_secret");
Wt::Dbo::field(a, username, "username");
}
std::string getRequestToken(){
return RequestToken;
}
std::string getTweets(){
return Tweets;
}
std::string getFollowers(){
return Followers;
}
void setAuthPin(std::string pin){
AuthPin=pin;
}
void RegisterApp();
private:
int qid;
std::string Followers;
std::string Tweets;
std::string AuthPin;
std::string RequestToken;
std::string tmpStr;
std::string replyMsg;
std::string myOAuthAccessTokenKey;
std::string myOAuthAccessTokenSecret;
twitCurl twitterObj;
};
#endif
webui.cpp
/*
Copyright 2010 Jan Koester
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include <Wt/WApplication>
#include <Wt/WBreak>
#include <Wt/WStackedWidget>
#include <Wt/WContainerWidget>
#include <Wt/WLineEdit>
#include <Wt/WPushButton>
#include <Wt/WText>
#include <Wt/WWidget>
#include <Wt/WComboBox>
#include <Wt/WTextArea>
#include <Wt/WCssStyleSheet>
#include <Wt/WColor>
#include <Wt/WHBoxLayout>
#include <Wt/WLength>
#include <Wt/WJavaScript>
#include <Wt/WImage>
#include <Wt/WLogger>
#include <tuxlibs/navbar.h>
#include "twitter.h"
#include "webui.h"
TuxistApp::TuxistApp(const Wt::WEnvironment& env)
: Wt::WApplication(env)
{
Wt::Dbo::backend::Postgres db_con(getenv("TUXCMS_SQLCONFIG")); //will be
replaced agqainst multi db support
db_con.setProperty("show-queries", "true");
Session = new Wt::Dbo::Session;
Session->setConnection(db_con);
Session->mapClass<Navbar>("navbar");
Session->mapClass<Twitter>("twitter");
setTitle("Tuxist.de"); // application title
useStyleSheet("style/main.css");
Navbar navbar;
navbar.Session=Session;
navbar.getNavbar(root());
twitter.Session=Session;
if(twitter.getLogindata()==false){
root()->addWidget(new Wt::WText("Please visit this link in web browser and
authorize this application: <a href=\""+
twitter.getRequestToken()+"\">Token</a> "));
root()->addWidget(new Wt::WText("Enter the PIN provided by twitter: " ));
PinLine = new Wt::WLineEdit(root());
PinLine->enterPressed().connect(SLOT(this, TuxistApp::RegisterApp));
}
}
void TuxistApp::RegisterApp(){
twitter.setAuthPin(PinLine->text().toUTF8());
twitter.RegisterApp();
}
Wt::WApplication *createApplication(const Wt::WEnvironment& env)
{
return new TuxistApp(env);
}
int main(int argc, char **argv)
{
return WRun(argc, argv, &createApplication);
}
------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and,
should the need arise, upgrade to a full multi-node Oracle RAC database
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
witty-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/witty-interest