Merge branch 'master' into debian
This commit is contained in:
commit
89e377ba05
2032 changed files with 13024 additions and 409475 deletions
27
.gitignore
vendored
27
.gitignore
vendored
|
@ -1,3 +1,28 @@
|
|||
*.pb.cc
|
||||
*.pb.h
|
||||
plugin/python/protocol_pb2.py
|
||||
plugin/python/protocol_pb2.py
|
||||
Makefile
|
||||
*.cmake
|
||||
*.so
|
||||
*.so.*
|
||||
*.log
|
||||
libtransport_test
|
||||
CMakeFiles
|
||||
spectrum2
|
||||
transport_config.h
|
||||
Doxyfile
|
||||
moc_*
|
||||
CMakeCache.txt
|
||||
*.patch
|
||||
*.orig
|
||||
spectrum2_manager
|
||||
dfrotz
|
||||
spectrum2_frotz_backend
|
||||
spectrum2_libcommuni_backend
|
||||
spectrum2_libpurple_backend
|
||||
spectrum2_skype_backend
|
||||
spectrum2_smstools3_backend
|
||||
spectrum2_swiften_backend
|
||||
spectrum2_template_backend
|
||||
spectrum2_twitter_backend
|
||||
install_manifest.txt
|
||||
|
|
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
[submodule "msvc-deps/curl"]
|
||||
path = msvc-deps/curl
|
||||
url = https://github.com/bagder/curl.git
|
10
.travis.yml
Normal file
10
.travis.yml
Normal file
|
@ -0,0 +1,10 @@
|
|||
language: cpp
|
||||
sudo: required
|
||||
dist: trusty
|
||||
before_script:
|
||||
- curl -k https://swift.im/keys/packages.key | sudo apt-key add -
|
||||
- echo "deb http://swift.im/packages/ubuntu/trusty development main" | sudo tee -a /etc/apt/sources.list
|
||||
- sudo apt-get update -qq
|
||||
- sudo apt-get install -y --force-yes libswiften-dev libprotobuf-dev protobuf-compiler pidgin-dev liblog4cxx10-dev libpopt-dev libboost-dev libboost-signals-dev libboost-system-dev libboost-thread-dev libboost-filesystem-dev libboost-program-options-dev libboost-regex-dev libboost-date-time-dev libcppunit-dev
|
||||
script:
|
||||
- mkdir build && cd build && cmake -DCMAKE_BUILD_TYPE=Debug -DENABLE_TESTS=ON .. && make libtransport_test && ./src/libtransport_test
|
|
@ -26,7 +26,6 @@ option(ENABLE_SMSTOOLS3 "Build SMSTools3 plugin" ON)
|
|||
option(ENABLE_SKYPE "Build Skype plugin" ON)
|
||||
option(ENABLE_SWIFTEN "Build Swiften plugin" ON)
|
||||
option(ENABLE_TWITTER "Build Twitter plugin" ON)
|
||||
option(ENABLE_YAHOO2 "Build Libyahoo2 plugin" ON)
|
||||
|
||||
option(ENABLE_DOCS "Build Docs" ON)
|
||||
# option(ENABLE_LOG "Build with logging using Log4cxx" ON)
|
||||
|
@ -77,7 +76,6 @@ if(NOT SWIFTEN_FOUND)
|
|||
endif()
|
||||
|
||||
# FIND BOOST
|
||||
set(Boost_DIR "${CMAKE_SOURCE_DIR}/cmake_modules")
|
||||
if (WIN32)
|
||||
set(Boost_USE_STATIC_LIBS ON)
|
||||
set(Boost_USE_MULTITHREADED ON)
|
||||
|
@ -115,6 +113,7 @@ endif()
|
|||
# FIND SQLITE3
|
||||
if (ENABLE_SQLITE3)
|
||||
if (MSVC)
|
||||
set(SQLITE3_FOUND 1)
|
||||
ADD_SUBDIRECTORY(${CMAKE_SOURCE_DIR}/msvc-deps)
|
||||
else()
|
||||
if (WIN32)
|
||||
|
@ -219,10 +218,6 @@ set(dbus_DIR "${CMAKE_SOURCE_DIR}/cmake_modules")
|
|||
find_package(dbus)
|
||||
endif()
|
||||
|
||||
# if(ENABLE_YAHOO2)
|
||||
# set(yahoo2_DIR "${CMAKE_SOURCE_DIR}/cmake_modules")
|
||||
# find_package(yahoo2)
|
||||
# endif()
|
||||
|
||||
####### Miscallanous ######
|
||||
|
||||
|
@ -253,16 +248,6 @@ if(ENABLE_TESTS)
|
|||
endif()
|
||||
endif()
|
||||
|
||||
if (APPLE)
|
||||
FIND_LIBRARY(IOKIT_FRAMEWORK IOKit)
|
||||
FIND_LIBRARY(SECURITY_FRAMEWORK Security)
|
||||
FIND_LIBRARY(APPKIT_FRAMEWORK AppKit)
|
||||
FIND_LIBRARY(SYSTEMCONFIGURATION_FRAMEWORK SystemConfiguration)
|
||||
FIND_LIBRARY(SECURITYINTERFACE_FRAMEWORK SecurityInterface)
|
||||
MARK_AS_ADVANCED(IOKIT_FRAMEWORK APPKIT_FRAMEWORK SYSTEMCONFIGURATION_FRAMEWORK SECURITY_FRAMEWORK SECURITYINTERFACE_FRAMEWORK)
|
||||
SET (APPLE_FRAMEWORKS ${IOKIT_FRAMEWORK} ${APPKIT_FRAMEWORK} ${SYSTEMCONFIGURATION_FRAMEWORK} ${SECURITY_FRAMEWORK} ${SECURITYINTERFACE_FRAMEWORK})
|
||||
endif()
|
||||
|
||||
message(" Supported features")
|
||||
message("-----------------------")
|
||||
|
||||
|
@ -361,7 +346,7 @@ if (PROTOBUF_FOUND)
|
|||
endif()
|
||||
|
||||
if(IRC_FOUND)
|
||||
ADD_DEFINITIONS(-DCOMMUNI_SHARED)
|
||||
ADD_DEFINITIONS(-DIRC_SHARED)
|
||||
message("IRC plugin : yes")
|
||||
include_directories(${QT_QTNETWORK_INCLUDE_DIR})
|
||||
include_directories(${IRC_INCLUDE_DIR})
|
||||
|
@ -405,18 +390,6 @@ if (PROTOBUF_FOUND)
|
|||
message("Skype plugin : no (does not run on Win32)")
|
||||
endif()
|
||||
|
||||
# if(YAHOO2_FOUND)
|
||||
# message("Libyahoo2 plugin : yes")
|
||||
# include_directories(${YAHOO2_INCLUDE_DIR})
|
||||
# else()
|
||||
if(ENABLE_YAHOO2)
|
||||
set(YAHOO2_FOUND 1)
|
||||
message("Libyahoo2 plugin : yes")
|
||||
else(ENABLE_YAHOO2)
|
||||
message("Libyahoo2 plugin : no (user disabled)")
|
||||
endif()
|
||||
# endif()
|
||||
|
||||
if(ENABLE_SWIFTEN)
|
||||
message("Swiften plugin : yes")
|
||||
else()
|
||||
|
@ -453,6 +426,10 @@ if (WIN32)
|
|||
ADD_DEFINITIONS(-DBOOST_THREAD_USE_LIB)
|
||||
endif()
|
||||
|
||||
# We cannot use boost:signals2, because Swiften does not use them,
|
||||
# for now, just ignore the deprecation warning.
|
||||
ADD_DEFINITIONS(-DBOOST_SIGNALS_NO_DEPRECATION_WARNING)
|
||||
|
||||
if(CMAKE_BUILD_TYPE MATCHES Debug)
|
||||
if (CMAKE_COMPILER_IS_GNUCXX)
|
||||
ADD_DEFINITIONS(-O0)
|
||||
|
|
20
Dockerfile
Normal file
20
Dockerfile
Normal file
|
@ -0,0 +1,20 @@
|
|||
FROM fedora:23
|
||||
|
||||
EXPOSE 5222
|
||||
VOLUME ["/etc/spectrum2/transports", "/var/lib/spectrum2"]
|
||||
|
||||
RUN dnf install protobuf protobuf swiften gcc gcc-c++ make libpqxx-devel libpurple-devel protobuf-devel swiften-devel rpm-build avahi-devel boost-devel cmake cppunit-devel expat-devel libcommuni-devel libidn-devel libsqlite3x-devel log4cxx-devel mysql-devel popt-devel git libevent-devel qt-devel dbus-glib-devel libcurl-devel -y && \
|
||||
git clone git://github.com/hanzz/libtransport.git && \
|
||||
cd libtransport && \
|
||||
./packaging/fedora/build_rpm.sh && \
|
||||
rpm -U /root/rpmbuild/RPMS/x86_64/*.rpm && \
|
||||
cp ./packaging/docker/run.sh /run.sh && \
|
||||
cd .. && \
|
||||
rm -rf libtransport && \
|
||||
rm -rf ~/rpmbuild && \
|
||||
rm -rf /usr/share/locale/* && \
|
||||
rm -rf /usr/share/doc/* && \
|
||||
dnf remove protobuf-devel swiften-devel gcc gcc-c++ libpqxx-devel libevent-devel qt-devel dbus-glib-devel libpurple-devel make rpm-build avahi-devel boost-devel cmake cppunit-devel expat-devel libcommuni-devel libidn-devel libsqlite3x-devel log4cxx-devel mysql-devel popt-devel libcurl-devel spectrum2-debuginfo yum perl -y && \
|
||||
dnf clean all -y
|
||||
|
||||
CMD "/run.sh"
|
|
@ -1,3 +1,5 @@
|
|||
[](https://travis-ci.org/hanzz/libtransport)
|
||||
|
||||
Spectrum is an XMPP transport/gateway. It allows XMPP users to communicate with
|
||||
their friends who are using one of the supported networks. It supports a wide
|
||||
range of different networks such as ICQ, XMPP (Jabber, GTalk), AIM, MSN,
|
122
README.win32
122
README.win32
|
@ -1,61 +1,61 @@
|
|||
Prerequisites
|
||||
=============
|
||||
|
||||
1. Microsoft Visual C++ 2010 Express or higher edition (http://www.microsoft.com/visualstudio/en-us/products/2010-editions/visual-cpp-express)
|
||||
2. Git for Windows (http://code.google.com/p/msysgit/downloads/list)
|
||||
3. CMake 2.8 or newer (http://www.cmake.org/cmake/resources/software.html)
|
||||
4. Python 2.x for Swiften build scripts (scons) (http://www.python.org)
|
||||
|
||||
Libraries
|
||||
=========
|
||||
3. Swiften library (http://swift.im/git/swift)
|
||||
4. Boost 1.48 or newer (http://sourceforge.net/projects/boost/files/boost/1.49.0/)
|
||||
5. Google ProtoBuf library (http://code.google.com/p/protobuf/downloads/list)
|
||||
|
||||
|
||||
Environment
|
||||
===========
|
||||
|
||||
To create spectrum build environment do:
|
||||
|
||||
0. Create directory where we'll install all dependencies, e.g. C:\env-msvc-x64.
|
||||
Create C:\env-msvc-x64\bin and add it to %PATH%.
|
||||
Assuming you have git, python and cmake in %PATH%,
|
||||
launch "Visual Studio 2010 command prompt" or
|
||||
"Visual Studio 2010(x64) command prompt", depends on your target (Windows x86 or Windows x86_64).
|
||||
1. unpack and build boost libraries:
|
||||
|
||||
bootstrap.bat
|
||||
b2.exe --without-mpi --without-python
|
||||
b2.exe --without-mpi --without-python install --prefix=C:\env-msvc-x64 release
|
||||
|
||||
2. clone swift repository and build it. Don't forget to point it to our env directory:
|
||||
|
||||
git clone git://swift.im/swift
|
||||
cd swift
|
||||
echo boost_includedir="c:/env-msvc-x64/include/boost-1_49" > config.py
|
||||
echo boost_libdir="c:/env-msvc-x64/lib" >> config.py
|
||||
scons.bat debug=no SWIFTEN_INSTALLDIR=C:\env-msvc-x64 force_configure=1
|
||||
scons.bat debug=no SWIFTEN_INSTALLDIR=C:\env-msvc-x64 C:\env-msvc-x64
|
||||
|
||||
3. unpack and compile protobuf as described in its documentation.
|
||||
|
||||
Run extract_includes.bat in vsprojects/ directory and move resulting vsprojects/include/google/ directory to our C:\env-msvc-x64\include
|
||||
|
||||
Move protoc.exe to C:\env-msvc-x64\bin\ and libprotobuf.lib to C:\env-msvc-x64\lib
|
||||
|
||||
4. Install gtkmm
|
||||
|
||||
Download installer from https://live.gnome.org/gtkmm/MSWindows and install gtkmm into C:\env-msvc-x64\
|
||||
|
||||
5. Install libpurple headers
|
||||
|
||||
Download http://www.pidgin.im/download/source/ , extract it and copy libpurple directory in C:\env-msvc-x64\include
|
||||
|
||||
6. You're ready! :) Clone libtransport into C:\env-msvc-x64\libtransport (You *must* clone it into this directory, because libtransport will try to find the dependencies in ../lib and ../include)
|
||||
|
||||
Compile it as:
|
||||
|
||||
set CMAKE_INCLUDE_PATH=C:\env-msvc-x64\include
|
||||
cmake . -G "NMake Makefiles" -DBOOST_INCLUDEDIR=../include/boost-1_49 -DBOOST_LIBRARYDIR=../lib -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX=C:\env-msvc-x64 -DGIT_EXECUTABLE="c:\Program Files (x86)\git\bin\git.exe"
|
||||
nmake
|
||||
Prerequisites
|
||||
=============
|
||||
|
||||
1. Microsoft Visual C++ 2010 Express or higher edition (http://www.microsoft.com/visualstudio/en-us/products/2010-editions/visual-cpp-express)
|
||||
2. Git for Windows (http://code.google.com/p/msysgit/downloads/list)
|
||||
3. CMake 2.8 or newer (http://www.cmake.org/cmake/resources/software.html)
|
||||
4. Python 2.x for Swiften build scripts (scons) (http://www.python.org)
|
||||
|
||||
Libraries
|
||||
=========
|
||||
3. Swiften library (http://swift.im/git/swift)
|
||||
4. Boost 1.48 or newer (http://sourceforge.net/projects/boost/files/boost/1.49.0/)
|
||||
5. Google ProtoBuf library (http://code.google.com/p/protobuf/downloads/list)
|
||||
|
||||
|
||||
Environment
|
||||
===========
|
||||
|
||||
To create spectrum build environment do:
|
||||
|
||||
0. Create directory where we'll install all dependencies, e.g. C:\env-msvc-x64.
|
||||
Create C:\env-msvc-x64\bin and add it to %PATH%.
|
||||
Assuming you have git, python and cmake in %PATH%,
|
||||
launch "Visual Studio 2010 command prompt" or
|
||||
"Visual Studio 2010(x64) command prompt", depends on your target (Windows x86 or Windows x86_64).
|
||||
1. unpack and build boost libraries:
|
||||
|
||||
bootstrap.bat
|
||||
b2.exe --without-mpi --without-python
|
||||
b2.exe --without-mpi --without-python install --prefix=C:\env-msvc-x64 release
|
||||
|
||||
2. clone swift repository and build it. Don't forget to point it to our env directory:
|
||||
|
||||
git clone git://swift.im/swift
|
||||
cd swift
|
||||
echo boost_includedir="c:/env-msvc-x64/include/boost-1_49" > config.py
|
||||
echo boost_libdir="c:/env-msvc-x64/lib" >> config.py
|
||||
scons.bat debug=no SWIFTEN_INSTALLDIR=C:\env-msvc-x64 force_configure=1
|
||||
scons.bat debug=no SWIFTEN_INSTALLDIR=C:\env-msvc-x64 C:\env-msvc-x64
|
||||
|
||||
3. unpack and compile protobuf as described in its documentation.
|
||||
|
||||
Run extract_includes.bat in vsprojects/ directory and move resulting vsprojects/include/google/ directory to our C:\env-msvc-x64\include
|
||||
|
||||
Move protoc.exe to C:\env-msvc-x64\bin\ and libprotobuf.lib to C:\env-msvc-x64\lib
|
||||
|
||||
4. Install gtkmm
|
||||
|
||||
Download installer from https://live.gnome.org/gtkmm/MSWindows and install gtkmm into C:\env-msvc-x64\
|
||||
|
||||
5. Install libpurple headers
|
||||
|
||||
Download http://www.pidgin.im/download/source/ , extract it and copy libpurple directory in C:\env-msvc-x64\include
|
||||
|
||||
6. You're ready! :) Clone libtransport into C:\env-msvc-x64\libtransport (You *must* clone it into this directory, because libtransport will try to find the dependencies in ../lib and ../include)
|
||||
|
||||
Compile it as:
|
||||
|
||||
set CMAKE_INCLUDE_PATH=C:\env-msvc-x64\include
|
||||
cmake . -G "NMake Makefiles" -DBOOST_INCLUDEDIR=../include/boost-1_49 -DBOOST_LIBRARYDIR=../lib -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX=C:\env-msvc-x64 -DGIT_EXECUTABLE="c:\Program Files (x86)\git\bin\git.exe"
|
||||
nmake
|
||||
|
|
|
@ -22,9 +22,6 @@ if (PROTOBUF_FOUND)
|
|||
if(ENABLE_FROTZ)
|
||||
ADD_SUBDIRECTORY(frotz)
|
||||
endif()
|
||||
if(YAHOO2_FOUND)
|
||||
ADD_SUBDIRECTORY(libyahoo2)
|
||||
endif()
|
||||
if (${LIBDBUSGLIB_FOUND})
|
||||
ADD_SUBDIRECTORY(skype)
|
||||
endif()
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
cmake_minimum_required(VERSION 2.6)
|
||||
|
||||
ADD_SUBDIRECTORY(dfrotz)
|
||||
|
||||
FILE(GLOB SRC *.c *.cpp)
|
||||
|
||||
ADD_EXECUTABLE(spectrum2_frotz_backend ${SRC})
|
||||
|
||||
target_link_libraries(spectrum2_frotz_backend transport pthread ${Boost_LIBRARIES} ${SWIFTEN_LIBRARY} ${LOG4CXX_LIBRARIES})
|
||||
|
||||
INSTALL(TARGETS spectrum2_frotz_backend RUNTIME DESTINATION bin)
|
||||
|
||||
cmake_minimum_required(VERSION 2.6)
|
||||
|
||||
ADD_SUBDIRECTORY(dfrotz)
|
||||
|
||||
FILE(GLOB SRC *.c *.cpp)
|
||||
|
||||
ADD_EXECUTABLE(spectrum2_frotz_backend ${SRC})
|
||||
|
||||
target_link_libraries(spectrum2_frotz_backend transport pthread ${Boost_LIBRARIES} ${SWIFTEN_LIBRARY} ${LOG4CXX_LIBRARIES})
|
||||
|
||||
INSTALL(TARGETS spectrum2_frotz_backend RUNTIME DESTINATION bin)
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
cmake_minimum_required(VERSION 2.6)
|
||||
FILE(GLOB SRC common/*.c dumb/*.c)
|
||||
|
||||
ADD_EXECUTABLE(dfrotz ${SRC})
|
||||
|
||||
# target_link_libraries(dfrotz)
|
||||
|
||||
INSTALL(TARGETS dfrotz RUNTIME DESTINATION bin)
|
||||
|
||||
cmake_minimum_required(VERSION 2.6)
|
||||
FILE(GLOB SRC common/*.c dumb/*.c)
|
||||
|
||||
ADD_EXECUTABLE(dfrotz ${SRC})
|
||||
|
||||
# target_link_libraries(dfrotz)
|
||||
|
||||
INSTALL(TARGETS dfrotz RUNTIME DESTINATION bin)
|
||||
|
||||
|
|
|
@ -8,8 +8,8 @@
|
|||
* program, but you don't have to.
|
||||
*/
|
||||
|
||||
#include "transport/config.h"
|
||||
#include "transport/networkplugin.h"
|
||||
#include "transport/Config.h"
|
||||
#include "transport/NetworkPlugin.h"
|
||||
#include "Swiften/Swiften.h"
|
||||
#include <boost/filesystem.hpp>
|
||||
#include "unistd.h"
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
cmake_minimum_required(VERSION 2.6)
|
||||
FILE(GLOB SRC *.cpp)
|
||||
FILE(GLOB HEADERS *.h)
|
||||
QT4_WRAP_CPP(SRC ${HEADERS} OPTIONS -DBOOST_TT_HAS_OPERATOR_HPP_INCLUDED)
|
||||
ADD_EXECUTABLE(spectrum2_libcommuni_backend ${SRC})
|
||||
|
||||
if (NOT WIN32)
|
||||
target_link_libraries(spectrum2_libcommuni_backend ${IRC_LIBRARY} ${QT_LIBRARIES} transport pthread)
|
||||
else ()
|
||||
target_link_libraries(spectrum2_libcommuni_backend ${IRC_LIBRARY} ${QT_LIBRARIES} transport)
|
||||
endif()
|
||||
INSTALL(TARGETS spectrum2_libcommuni_backend RUNTIME DESTINATION bin)
|
||||
|
||||
cmake_minimum_required(VERSION 2.6)
|
||||
FILE(GLOB SRC *.cpp)
|
||||
FILE(GLOB HEADERS *.h)
|
||||
QT4_WRAP_CPP(SRC ${HEADERS} OPTIONS -DBOOST_TT_HAS_OPERATOR_HPP_INCLUDED)
|
||||
ADD_EXECUTABLE(spectrum2_libcommuni_backend ${SRC})
|
||||
|
||||
if (NOT WIN32)
|
||||
target_link_libraries(spectrum2_libcommuni_backend ${IRC_LIBRARY} ${QT_LIBRARIES} transport pthread)
|
||||
else ()
|
||||
target_link_libraries(spectrum2_libcommuni_backend ${IRC_LIBRARY} ${QT_LIBRARIES} transport)
|
||||
endif()
|
||||
INSTALL(TARGETS spectrum2_libcommuni_backend RUNTIME DESTINATION bin)
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
#include "ircnetworkplugin.h"
|
||||
#include <IrcCommand>
|
||||
#include <IrcMessage>
|
||||
#include "transport/logging.h"
|
||||
#include "transport/Logging.h"
|
||||
|
||||
DEFINE_LOGGER(logger, "IRCNetworkPlugin");
|
||||
|
||||
|
|
|
@ -20,8 +20,8 @@
|
|||
|
||||
#pragma once
|
||||
#ifndef Q_MOC_RUN
|
||||
#include "transport/config.h"
|
||||
#include "transport/networkplugin.h"
|
||||
#include "transport/Config.h"
|
||||
#include "transport/NetworkPlugin.h"
|
||||
#include "session.h"
|
||||
#include <QtCore>
|
||||
#include <QtNetwork>
|
||||
|
|
|
@ -18,9 +18,9 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
|
||||
*/
|
||||
|
||||
#include "transport/config.h"
|
||||
#include "transport/networkplugin.h"
|
||||
#include "transport/logging.h"
|
||||
#include "transport/Config.h"
|
||||
#include "transport/NetworkPlugin.h"
|
||||
#include "transport/Logging.h"
|
||||
#include "session.h"
|
||||
#include <QtCore>
|
||||
#include <QtNetwork>
|
||||
|
|
|
@ -23,9 +23,6 @@
|
|||
#include <iostream>
|
||||
#include <IrcCommand>
|
||||
#include <IrcMessage>
|
||||
#if COMMUNI_VERSION < 0x020000
|
||||
#include <IrcUtil>
|
||||
#endif
|
||||
#include "backports.h"
|
||||
|
||||
#include "ircnetworkplugin.h"
|
||||
|
@ -33,13 +30,13 @@
|
|||
#define FROM_UTF8(WHAT) QString::fromUtf8((WHAT).c_str(), (WHAT).size())
|
||||
#define TO_UTF8(WHAT) std::string((WHAT).toUtf8().data(), (WHAT).toUtf8().size())
|
||||
|
||||
#include "transport/logging.h"
|
||||
#include "transport/Logging.h"
|
||||
|
||||
DEFINE_LOGGER(logger, "IRCSession");
|
||||
DEFINE_LOGGER(logger, "IRCConnection");
|
||||
|
||||
static bool sentList;
|
||||
|
||||
MyIrcSession::MyIrcSession(const std::string &user, IRCNetworkPlugin *np, const std::string &suffix, QObject* parent) : IrcSession(parent)
|
||||
MyIrcSession::MyIrcSession(const std::string &user, IRCNetworkPlugin *np, const std::string &suffix, QObject* parent) : IrcConnection(parent)
|
||||
{
|
||||
this->np = np;
|
||||
this->user = user;
|
||||
|
@ -137,7 +134,7 @@ bool MyIrcSession::correctNickname(std::string &nickname) {
|
|||
|
||||
void MyIrcSession::on_joined(IrcMessage *message) {
|
||||
IrcJoinMessage *m = (IrcJoinMessage *) message;
|
||||
std::string nickname = TO_UTF8(m->sender().name());
|
||||
std::string nickname = TO_UTF8(m->nick());
|
||||
bool op = correctNickname(nickname);
|
||||
getIRCBuddy(TO_UTF8(m->channel().toLower()), nickname).setOp(op);
|
||||
np->handleParticipantChanged(user, nickname, TO_UTF8(m->channel().toLower()) + suffix, op, pbnetwork::STATUS_ONLINE);
|
||||
|
@ -147,7 +144,7 @@ void MyIrcSession::on_joined(IrcMessage *message) {
|
|||
|
||||
void MyIrcSession::on_parted(IrcMessage *message) {
|
||||
IrcPartMessage *m = (IrcPartMessage *) message;
|
||||
std::string nickname = TO_UTF8(m->sender().name());
|
||||
std::string nickname = TO_UTF8(m->nick());
|
||||
bool op = correctNickname(nickname);
|
||||
removeIRCBuddy(TO_UTF8(m->channel().toLower()), nickname);
|
||||
LOG4CXX_INFO(logger, user << ": " << nickname << " parted " << TO_UTF8(m->channel().toLower()) + suffix);
|
||||
|
@ -156,7 +153,7 @@ void MyIrcSession::on_parted(IrcMessage *message) {
|
|||
|
||||
void MyIrcSession::on_quit(IrcMessage *message) {
|
||||
IrcQuitMessage *m = (IrcQuitMessage *) message;
|
||||
std::string nickname = TO_UTF8(m->sender().name());
|
||||
std::string nickname = TO_UTF8(m->nick());
|
||||
bool op = correctNickname(nickname);
|
||||
|
||||
for(AutoJoinMap::iterator it = m_autoJoin.begin(); it != m_autoJoin.end(); it++) {
|
||||
|
@ -171,7 +168,7 @@ void MyIrcSession::on_quit(IrcMessage *message) {
|
|||
|
||||
void MyIrcSession::on_nickChanged(IrcMessage *message) {
|
||||
IrcNickMessage *m = (IrcNickMessage *) message;
|
||||
std::string nickname = TO_UTF8(m->sender().name());
|
||||
std::string nickname = TO_UTF8(m->nick());
|
||||
correctNickname(nickname);
|
||||
|
||||
for(AutoJoinMap::iterator it = m_autoJoin.begin(); it != m_autoJoin.end(); it++) {
|
||||
|
@ -214,7 +211,7 @@ void MyIrcSession::on_modeChanged(IrcMessage *message) {
|
|||
void MyIrcSession::on_topicChanged(IrcMessage *message) {
|
||||
IrcTopicMessage *m = (IrcTopicMessage *) message;
|
||||
|
||||
std::string nickname = TO_UTF8(m->sender().name());
|
||||
std::string nickname = TO_UTF8(m->nick());
|
||||
correctNickname(nickname);
|
||||
|
||||
LOG4CXX_INFO(logger, user << ": " << nickname << " topic changed to " << TO_UTF8(m->topic()));
|
||||
|
@ -224,14 +221,14 @@ void MyIrcSession::on_topicChanged(IrcMessage *message) {
|
|||
void MyIrcSession::on_messageReceived(IrcMessage *message) {
|
||||
IrcPrivateMessage *m = (IrcPrivateMessage *) message;
|
||||
if (m->isRequest()) {
|
||||
QString request = m->message().split(" ", QString::SkipEmptyParts).value(0).toUpper();
|
||||
QString request = m->content().split(" ", QString::SkipEmptyParts).value(0).toUpper();
|
||||
if (request == "PING" || request == "TIME" || request == "VERSION") {
|
||||
LOG4CXX_INFO(logger, user << ": " << TO_UTF8(request) << " received and has been answered");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
QString msg = m->message();
|
||||
QString msg = m->content();
|
||||
if (m->isAction()) {
|
||||
msg = QString("/me ") + msg;
|
||||
}
|
||||
|
@ -249,12 +246,12 @@ void MyIrcSession::on_messageReceived(IrcMessage *message) {
|
|||
std::string target = TO_UTF8(m->target().toLower());
|
||||
LOG4CXX_INFO(logger, user << ": Message from " << target);
|
||||
if (target.find("#") == 0) {
|
||||
std::string nickname = TO_UTF8(m->sender().name());
|
||||
std::string nickname = TO_UTF8(m->nick());
|
||||
correctNickname(nickname);
|
||||
np->handleMessage(user, target + suffix, TO_UTF8(msg), nickname, TO_UTF8(html));
|
||||
}
|
||||
else {
|
||||
std::string nickname = TO_UTF8(m->sender().name());
|
||||
std::string nickname = TO_UTF8(m->nick());
|
||||
correctNickname(nickname);
|
||||
if (m_pms.find(nickname) != m_pms.end()) {
|
||||
if (hasIRCBuddy(m_pms[nickname], nickname)) {
|
||||
|
@ -393,19 +390,19 @@ void MyIrcSession::awayTimeout() {
|
|||
|
||||
void MyIrcSession::on_noticeMessageReceived(IrcMessage *message) {
|
||||
IrcNoticeMessage *m = (IrcNoticeMessage *) message;
|
||||
LOG4CXX_INFO(logger, user << ": NOTICE " << TO_UTF8(m->message()));
|
||||
LOG4CXX_INFO(logger, user << ": NOTICE " << TO_UTF8(m->content()));
|
||||
|
||||
QString msg = m->message();
|
||||
QString msg = m->content();
|
||||
CommuniBackport::toPlainText(msg);
|
||||
|
||||
std::string target = TO_UTF8(m->target().toLower());
|
||||
if (target.find("#") == 0) {
|
||||
std::string nickname = TO_UTF8(m->sender().name());
|
||||
std::string nickname = TO_UTF8(m->nick());
|
||||
correctNickname(nickname);
|
||||
np->handleMessage(user, target + suffix, TO_UTF8(msg), nickname);
|
||||
}
|
||||
else {
|
||||
std::string nickname = TO_UTF8(m->sender().name());
|
||||
std::string nickname = TO_UTF8(m->nick());
|
||||
correctNickname(nickname);
|
||||
if (nickname.find(".") != std::string::npos) {
|
||||
return;
|
||||
|
|
|
@ -22,8 +22,8 @@
|
|||
#define SESSION_H
|
||||
|
||||
#ifndef Q_MOC_RUN
|
||||
#include <IrcSession>
|
||||
#include <transport/networkplugin.h>
|
||||
#include <IrcConnection>
|
||||
#include <transport/NetworkPlugin.h>
|
||||
#include "Swiften/Swiften.h"
|
||||
#include <boost/smart_ptr/make_shared.hpp>
|
||||
#include <QTimer>
|
||||
|
@ -33,7 +33,7 @@ using namespace Transport;
|
|||
|
||||
class IRCNetworkPlugin;
|
||||
|
||||
class MyIrcSession : public IrcSession
|
||||
class MyIrcSession : public IrcConnection
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
cmake_minimum_required(VERSION 2.6)
|
||||
FILE(GLOB SRC *.cpp)
|
||||
|
||||
ADD_EXECUTABLE(spectrum2_libpurple_backend ${SRC})
|
||||
|
||||
if(CMAKE_COMPILER_IS_GNUCXX)
|
||||
if (NOT WIN32)
|
||||
target_link_libraries(spectrum2_libpurple_backend ${PURPLE_LIBRARY} ${GLIB2_LIBRARIES} ${EVENT_LIBRARIES} transport-plugin pthread)
|
||||
else()
|
||||
target_link_libraries(spectrum2_libpurple_backend ${PURPLE_LIBRARY} ${GLIB2_LIBRARIES} ${EVENT_LIBRARIES} transport-plugin)
|
||||
endif()
|
||||
else()
|
||||
target_link_libraries(spectrum2_libpurple_backend sqlite3 ${PURPLE_LIBRARY} ${GLIB2_LIBRARIES} ${LIBXML2_LIBRARIES} ${EVENT_LIBRARIES} transport-plugin ${PROTOBUF_LIBRARY})
|
||||
endif()
|
||||
|
||||
INSTALL(TARGETS spectrum2_libpurple_backend RUNTIME DESTINATION bin)
|
||||
|
||||
cmake_minimum_required(VERSION 2.6)
|
||||
FILE(GLOB SRC *.cpp)
|
||||
|
||||
ADD_EXECUTABLE(spectrum2_libpurple_backend ${SRC})
|
||||
|
||||
if(CMAKE_COMPILER_IS_GNUCXX)
|
||||
if (NOT WIN32)
|
||||
target_link_libraries(spectrum2_libpurple_backend ${PURPLE_LIBRARY} ${GLIB2_LIBRARIES} ${EVENT_LIBRARIES} transport-plugin pthread)
|
||||
else()
|
||||
target_link_libraries(spectrum2_libpurple_backend ${PURPLE_LIBRARY} ${GLIB2_LIBRARIES} ${EVENT_LIBRARIES} transport-plugin)
|
||||
endif()
|
||||
else()
|
||||
target_link_libraries(spectrum2_libpurple_backend sqlite3 ${PURPLE_LIBRARY} ${GLIB2_LIBRARIES} ${LIBXML2_LIBRARIES} ${EVENT_LIBRARIES} transport-plugin ${PROTOBUF_LIBRARY})
|
||||
endif()
|
||||
|
||||
INSTALL(TARGETS spectrum2_libpurple_backend RUNTIME DESTINATION bin)
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
|
||||
#include "purple_defs.h"
|
||||
|
||||
#include "transport/logging.h"
|
||||
#include "transport/Logging.h"
|
||||
|
||||
DEFINE_LOGGER(logger, "EventLoop");
|
||||
|
||||
|
|
|
@ -10,10 +10,9 @@
|
|||
#include <algorithm>
|
||||
#include <iostream>
|
||||
|
||||
#include "transport/networkplugin.h"
|
||||
#include "transport/logging.h"
|
||||
#include "transport/config.h"
|
||||
#include "transport/logging.h"
|
||||
#include "transport/NetworkPlugin.h"
|
||||
#include "transport/Logging.h"
|
||||
#include "transport/Config.h"
|
||||
#include "geventloop.h"
|
||||
|
||||
// #include "valgrind/memcheck.h"
|
||||
|
@ -518,7 +517,11 @@ class SpectrumNetworkPlugin : public NetworkPlugin {
|
|||
}
|
||||
m_vcards[user + name] = id;
|
||||
|
||||
if (CONFIG_BOOL(config, "backend.no_vcard_fetch") && name != purple_account_get_username_wrapped(account)) {
|
||||
PurplePlugin *prpl = purple_find_prpl_wrapped(purple_account_get_protocol_id_wrapped(account));
|
||||
PurplePluginProtocolInfo *prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl);
|
||||
bool support_get_info = prpl_info && prpl_info->get_info;
|
||||
|
||||
if (!support_get_info || (CONFIG_BOOL(config, "backend.no_vcard_fetch") && name != purple_account_get_username_wrapped(account))) {
|
||||
PurpleNotifyUserInfo *user_info = purple_notify_user_info_new_wrapped();
|
||||
notify_user_info(purple_account_get_connection_wrapped(account), name.c_str(), user_info);
|
||||
purple_notify_user_info_destroy_wrapped(user_info);
|
||||
|
@ -526,7 +529,6 @@ class SpectrumNetworkPlugin : public NetworkPlugin {
|
|||
else {
|
||||
serv_get_info_wrapped(purple_account_get_connection_wrapped(account), name.c_str());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -635,6 +637,11 @@ class SpectrumNetworkPlugin : public NetworkPlugin {
|
|||
PurpleAccount *account = m_sessions[user];
|
||||
if (account) {
|
||||
serv_send_typing_wrapped(purple_account_get_connection_wrapped(account), buddyName.c_str(), PURPLE_NOT_TYPING);
|
||||
PurpleConversation *conv = purple_find_conversation_with_account_wrapped(PURPLE_CONV_TYPE_CHAT, buddyName.c_str(), account);
|
||||
if (conv) {
|
||||
purple_conversation_set_data_wrapped(conv, "unseen_count", 0);
|
||||
purple_conversation_update_wrapped(conv, PURPLE_CONV_UPDATE_UNSEEN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -224,6 +224,12 @@ extern purple_conversation_new_wrapped_fnc purple_conversation_new_wrapped;
|
|||
typedef PurpleConversationType (_cdecl * purple_conversation_get_type_wrapped_fnc)(const PurpleConversation *conv);
|
||||
extern purple_conversation_get_type_wrapped_fnc purple_conversation_get_type_wrapped;
|
||||
|
||||
typedef void (_cdecl * purple_conversation_set_data_wrapped_func)(const PurpleConversation *conv, const char *key, gpointer data);
|
||||
extern purple_conversation_set_data_wrapped_func purple_conversation_set_data_wrapped;
|
||||
|
||||
typedef void (_cdecl * purple_conversation_update_wrapped_func)(const PurpleConversation *conv, PurpleConversationUpdateType type);
|
||||
extern purple_conversation_update_wrapped_func purple_conversation_update_wrapped;
|
||||
|
||||
typedef void (_cdecl * purple_conv_im_send_wrapped_fnc)(PurpleConvIm *im, const char *message);
|
||||
extern purple_conv_im_send_wrapped_fnc purple_conv_im_send_wrapped;
|
||||
|
||||
|
@ -524,6 +530,8 @@ extern wpurple_g_io_channel_win32_new_socket_wrapped_fnc wpurple_g_io_channel_wi
|
|||
#define purple_find_conversation_with_account_wrapped purple_find_conversation_with_account
|
||||
#define purple_conversation_new_wrapped purple_conversation_new
|
||||
#define purple_conversation_get_type_wrapped purple_conversation_get_type
|
||||
#define purple_conversation_set_data_wrapped purple_conversation_set_data
|
||||
#define purple_conversation_update_wrapped purple_conversation_update
|
||||
#define purple_conv_im_send_wrapped purple_conv_im_send
|
||||
#define purple_conv_chat_send_wrapped purple_conv_chat_send
|
||||
#define purple_conversation_destroy_wrapped purple_conversation_destroy
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
cmake_minimum_required(VERSION 2.6)
|
||||
|
||||
FILE(GLOB_RECURSE SRC *.c *.cpp)
|
||||
|
||||
ADD_DEFINITIONS(-DHAVE_STDINT_H=1)
|
||||
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/yahoo)
|
||||
|
||||
ADD_EXECUTABLE(spectrum2_libyahoo2_backend ${SRC})
|
||||
|
||||
target_link_libraries(spectrum2_libyahoo2_backend transport pthread ${Boost_LIBRARIES} ${SWIFTEN_LIBRARY} ${LOG4CXX_LIBRARIES})
|
||||
|
||||
INSTALL(TARGETS spectrum2_libyahoo2_backend RUNTIME DESTINATION bin)
|
||||
|
|
@ -1,163 +0,0 @@
|
|||
|
||||
#include "httpfetch.h"
|
||||
#include "transport/logging.h"
|
||||
|
||||
#if WIN32
|
||||
#define snprintf sprintf_s
|
||||
#endif
|
||||
|
||||
DEFINE_LOGGER(logger, "HTTPFetch");
|
||||
|
||||
static int url_to_host_port_path(const char *url,
|
||||
char *host, int *port, char *path, int *ssl)
|
||||
{
|
||||
char *urlcopy = NULL;
|
||||
char *slash = NULL;
|
||||
char *colon = NULL;
|
||||
|
||||
/*
|
||||
* http://hostname
|
||||
* http://hostname/
|
||||
* http://hostname/path
|
||||
* http://hostname/path:foo
|
||||
* http://hostname:port
|
||||
* http://hostname:port/
|
||||
* http://hostname:port/path
|
||||
* http://hostname:port/path:foo
|
||||
* and https:// variants of the above
|
||||
*/
|
||||
|
||||
if (strstr(url, "http://") == url) {
|
||||
urlcopy = strdup(url + 7);
|
||||
} else if (strstr(url, "https://") == url) {
|
||||
urlcopy = strdup(url + 8);
|
||||
*ssl = 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
slash = strchr(urlcopy, '/');
|
||||
colon = strchr(urlcopy, ':');
|
||||
|
||||
if (!colon || (slash && slash < colon)) {
|
||||
if (*ssl)
|
||||
*port = 443;
|
||||
else
|
||||
*port = 80;
|
||||
} else {
|
||||
*colon = 0;
|
||||
*port = atoi(colon + 1);
|
||||
}
|
||||
|
||||
if (!slash) {
|
||||
strcpy(path, "/");
|
||||
} else {
|
||||
strcpy(path, slash);
|
||||
*slash = 0;
|
||||
}
|
||||
|
||||
strcpy(host, urlcopy);
|
||||
|
||||
free(urlcopy);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
HTTPFetch::HTTPFetch(Swift::BoostIOServiceThread *ioService, Swift::ConnectionFactory *factory) : m_ioService(ioService), m_factory(factory) {
|
||||
m_afterHeader = false;
|
||||
}
|
||||
|
||||
HTTPFetch::~HTTPFetch() {
|
||||
}
|
||||
|
||||
void HTTPFetch::_connected(boost::shared_ptr<Swift::Connection> conn, const std::string url, bool error) {
|
||||
if (error) {
|
||||
_disconnected(conn);
|
||||
}
|
||||
else {
|
||||
char host[255];
|
||||
int port = 80;
|
||||
char path[255];
|
||||
int ssl = 0;
|
||||
if (!url_to_host_port_path(url.c_str(), host, &port, path, &ssl))
|
||||
return;
|
||||
|
||||
static char buff[2048];
|
||||
snprintf(buff, sizeof(buff),
|
||||
"GET %s HTTP/1.1\r\n"
|
||||
"Host: %s\r\n"
|
||||
"User-Agent: Mozilla/4.5 [en] (1/1)\r\n"
|
||||
"Accept: */*\r\n"
|
||||
"%s" "\r\n", path, host,
|
||||
"Connection: close\r\n");
|
||||
LOG4CXX_INFO(logger, "Sending " << buff << "\n");
|
||||
conn->write(Swift::createSafeByteArray(buff));
|
||||
}
|
||||
}
|
||||
|
||||
void HTTPFetch::_disconnected(boost::shared_ptr<Swift::Connection> conn) {
|
||||
conn->onConnectFinished.disconnect_all_slots();
|
||||
conn->onDisconnected.disconnect_all_slots();
|
||||
conn->onDataRead.disconnect_all_slots();
|
||||
|
||||
if (m_buffer.size() == 0) {
|
||||
onURLFetched("");
|
||||
}
|
||||
else {
|
||||
std::string img = m_buffer.substr(m_buffer.find("\r\n\r\n") + 4);
|
||||
onURLFetched(img);
|
||||
}
|
||||
}
|
||||
|
||||
void HTTPFetch::_read(boost::shared_ptr<Swift::Connection> conn, boost::shared_ptr<Swift::SafeByteArray> data) {
|
||||
std::string d(data->begin(), data->end());
|
||||
// std::cout << d << "\n";
|
||||
std::string img = d.substr(d.find("\r\n\r\n") + 4);
|
||||
if (d.find("Location: ") == std::string::npos) {
|
||||
m_buffer += d;
|
||||
}
|
||||
else {
|
||||
d = d.substr(d.find("Location: ") + 10);
|
||||
if (d.find("\r") == std::string::npos) {
|
||||
d = d.substr(0, d.find("\n"));
|
||||
}
|
||||
else {
|
||||
d = d.substr(0, d.find("\r"));
|
||||
}
|
||||
LOG4CXX_INFO(logger, "Next url is '" << d << "'");
|
||||
fetchURL(d);
|
||||
conn->onConnectFinished.disconnect_all_slots();
|
||||
conn->onDisconnected.disconnect_all_slots();
|
||||
conn->onDataRead.disconnect_all_slots();
|
||||
}
|
||||
}
|
||||
|
||||
bool HTTPFetch::fetchURL(const std::string &url) {
|
||||
char host[255];
|
||||
int port = 80;
|
||||
char path[255];
|
||||
char buff[1024];
|
||||
int ssl = 0;
|
||||
if (!url_to_host_port_path(url.c_str(), host, &port, path, &ssl)) {
|
||||
LOG4CXX_ERROR(logger, "Invalid URL " << url);
|
||||
return false;
|
||||
}
|
||||
|
||||
LOG4CXX_INFO(logger, "Connecting to " << host << ":" << port);
|
||||
|
||||
boost::asio::ip::tcp::resolver resolver(*m_ioService->getIOService());
|
||||
boost::asio::ip::tcp::resolver::query query(host, "");
|
||||
boost::asio::ip::address address;
|
||||
for(boost::asio::ip::tcp::resolver::iterator i = resolver.resolve(query); i != boost::asio::ip::tcp::resolver::iterator(); ++i) {
|
||||
boost::asio::ip::tcp::endpoint end = *i;
|
||||
address = end.address();
|
||||
break;
|
||||
}
|
||||
|
||||
boost::shared_ptr<Swift::Connection> conn = m_factory->createConnection();
|
||||
conn->onConnectFinished.connect(boost::bind(&HTTPFetch::_connected, this, conn, url, _1));
|
||||
conn->onDisconnected.connect(boost::bind(&HTTPFetch::_disconnected, this, conn));
|
||||
conn->onDataRead.connect(boost::bind(&HTTPFetch::_read, this, conn, _1));
|
||||
conn->connect(Swift::HostAddressPort(Swift::HostAddress(address), port));
|
||||
return true;
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
// Transport includes
|
||||
#include "transport/config.h"
|
||||
#include "transport/networkplugin.h"
|
||||
#include "transport/logging.h"
|
||||
|
||||
// Swiften
|
||||
#include "Swiften/Swiften.h"
|
||||
#include "Swiften/TLS/OpenSSL/OpenSSLContextFactory.h"
|
||||
|
||||
// Boost
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
using namespace boost::filesystem;
|
||||
using namespace boost::program_options;
|
||||
using namespace Transport;
|
||||
|
||||
class HTTPFetch {
|
||||
public:
|
||||
HTTPFetch(Swift::BoostIOServiceThread *ioSerice, Swift::ConnectionFactory *factory);
|
||||
virtual ~HTTPFetch();
|
||||
|
||||
bool fetchURL(const std::string &url);
|
||||
|
||||
boost::signal<void (const std::string &data)> onURLFetched;
|
||||
|
||||
private:
|
||||
void _connected(boost::shared_ptr<Swift::Connection> conn, const std::string url, bool error);
|
||||
void _disconnected(boost::shared_ptr<Swift::Connection> conn);
|
||||
void _read(boost::shared_ptr<Swift::Connection> conn, boost::shared_ptr<Swift::SafeByteArray> data);
|
||||
|
||||
Swift::BoostIOServiceThread *m_ioService;
|
||||
Swift::ConnectionFactory *m_factory;
|
||||
std::string m_buffer;
|
||||
bool m_afterHeader;
|
||||
};
|
|
@ -1,762 +0,0 @@
|
|||
// Transport includes
|
||||
#include "transport/config.h"
|
||||
#include "transport/networkplugin.h"
|
||||
#include "transport/logging.h"
|
||||
|
||||
// Yahoo2
|
||||
#include <yahoo2.h>
|
||||
#include <yahoo2_callbacks.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "yahoohandler.h"
|
||||
#include "yahoolocalaccount.h"
|
||||
#include "httpfetch.h"
|
||||
|
||||
// Swiften
|
||||
#include "Swiften/Swiften.h"
|
||||
#include "Swiften/Network/TLSConnectionFactory.h"
|
||||
#include "Swiften/TLS/OpenSSL/OpenSSLContextFactory.h"
|
||||
|
||||
#ifndef _WIN32
|
||||
// for signal handler
|
||||
#include "unistd.h"
|
||||
#include "signal.h"
|
||||
#include "sys/wait.h"
|
||||
#include "sys/signal.h"
|
||||
#endif
|
||||
|
||||
// Boost
|
||||
#include <boost/algorithm/string.hpp>
|
||||
using namespace boost::filesystem;
|
||||
using namespace boost::program_options;
|
||||
using namespace Transport;
|
||||
|
||||
class YahooHandler;
|
||||
class YahooLocalAccount;
|
||||
|
||||
static std::string *currently_read_data;
|
||||
static YahooLocalAccount *currently_writting_account;
|
||||
|
||||
YahooHandler::YahooHandler(YahooLocalAccount *account, int conn_tag, int handler_tag, void *data, yahoo_input_condition cond) :
|
||||
handler_tag(handler_tag), conn_tag(conn_tag), data(data), cond(cond), remove_later(false), account(account) {}
|
||||
|
||||
YahooHandler::~YahooHandler() {}
|
||||
|
||||
void YahooHandler::ready(std::string *buffer) {
|
||||
if (cond == YAHOO_INPUT_WRITE) {
|
||||
YahooLocalAccount *old = currently_writting_account;
|
||||
currently_writting_account = account;
|
||||
yahoo_write_ready(account->id, (void *) conn_tag, data);
|
||||
currently_writting_account = old;
|
||||
}
|
||||
else {
|
||||
if (!buffer) {
|
||||
return;
|
||||
}
|
||||
// yahoo_read_ready calls ext_yahoo_read(...) in a loop, so we just have to choose proper buffer from which will
|
||||
// that method read. We do that by static currently_read_data pointer.
|
||||
currently_read_data = buffer;
|
||||
// libyahoo2 reads data per 1024 bytes, so if we still have some data after the first ext_yahoo_read call,
|
||||
// we have to call yahoo_read_ready again...
|
||||
do {
|
||||
yahoo_read_ready(account->id, (void *) conn_tag, data);
|
||||
} while (currently_read_data->size() != 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
typedef struct {
|
||||
std::string yahoo_id;
|
||||
std::string name;
|
||||
int status;
|
||||
int away;
|
||||
std::string msg;
|
||||
std::string group;
|
||||
} yahoo_account;
|
||||
|
||||
typedef struct {
|
||||
int id;
|
||||
char *label;
|
||||
} yahoo_idlabel;
|
||||
|
||||
typedef struct {
|
||||
int id;
|
||||
char *who;
|
||||
} yahoo_authorize_data;
|
||||
|
||||
DEFINE_LOGGER(logger, "Yahoo2");
|
||||
|
||||
// eventloop
|
||||
Swift::SimpleEventLoop *loop_;
|
||||
|
||||
// Plugin
|
||||
class YahooPlugin;
|
||||
YahooPlugin * np = NULL;
|
||||
|
||||
class YahooPlugin : public NetworkPlugin {
|
||||
public:
|
||||
Swift::BoostNetworkFactories *m_factories;
|
||||
Swift::OpenSSLContextFactory *m_sslFactory;
|
||||
Swift::TLSConnectionFactory *m_tlsFactory;
|
||||
Swift::BoostIOServiceThread m_boostIOServiceThread;
|
||||
boost::shared_ptr<Swift::Connection> m_conn;
|
||||
|
||||
YahooPlugin(Config *config, Swift::SimpleEventLoop *loop, const std::string &host, int port) : NetworkPlugin() {
|
||||
this->config = config;
|
||||
m_factories = new Swift::BoostNetworkFactories(loop);
|
||||
m_sslFactory = new Swift::OpenSSLContextFactory();
|
||||
m_tlsFactory = new Swift::TLSConnectionFactory(m_sslFactory, m_factories->getConnectionFactory());
|
||||
m_conn = m_factories->getConnectionFactory()->createConnection();
|
||||
m_conn->onDataRead.connect(boost::bind(&YahooPlugin::_handleDataRead, this, _1));
|
||||
m_conn->connect(Swift::HostAddressPort(Swift::HostAddress(host), port));
|
||||
|
||||
LOG4CXX_INFO(logger, "Starting the plugin.");
|
||||
}
|
||||
|
||||
// NetworkPlugin uses this method to send the data to networkplugin server
|
||||
void sendData(const std::string &string) {
|
||||
m_conn->write(Swift::createSafeByteArray(string));
|
||||
}
|
||||
|
||||
// This method has to call handleDataRead with all received data from network plugin server
|
||||
void _handleDataRead(boost::shared_ptr<Swift::SafeByteArray> data) {
|
||||
std::string d(data->begin(), data->end());
|
||||
handleDataRead(d);
|
||||
}
|
||||
|
||||
void handleLoginRequest(const std::string &user, const std::string &legacyName, const std::string &password) {
|
||||
YahooLocalAccount *account = new YahooLocalAccount(user, legacyName, password);
|
||||
m_users[user] = account;
|
||||
m_ids[account->id] = user;
|
||||
|
||||
LOG4CXX_INFO(logger, user << ": Logging in the user as " << legacyName << " with id=" << account->id);
|
||||
account->login();
|
||||
}
|
||||
|
||||
void handleLogoutRequest(const std::string &user, const std::string &legacyName) {
|
||||
YahooLocalAccount *account = m_users[user];
|
||||
if (account) {
|
||||
yahoo_logoff(account->id);
|
||||
m_ids.erase(account->id);
|
||||
m_users.erase(user);
|
||||
delete account;
|
||||
}
|
||||
}
|
||||
|
||||
void handleMessageSendRequest(const std::string &user, const std::string &legacyName, const std::string &message, const std::string &xhtml = "", const std::string &id = "") {
|
||||
YahooLocalAccount *account = m_users[user];
|
||||
if (account) {
|
||||
LOG4CXX_INFO(logger, "Sending message from " << user << " to " << legacyName << ": " << message << ".");
|
||||
yahoo_send_im(account->id, NULL, legacyName.c_str(), message.c_str(), 0, 0);
|
||||
_yahoo_write_ready(account);
|
||||
}
|
||||
}
|
||||
|
||||
void handleBuddyUpdatedRequest(const std::string &user, const std::string &buddyName, const std::string &alias, const std::vector<std::string> &groups) {
|
||||
LOG4CXX_INFO(logger, user << ": Added buddy " << buddyName << ".");
|
||||
handleBuddyChanged(user, buddyName, alias, groups, pbnetwork::STATUS_ONLINE);
|
||||
}
|
||||
|
||||
void _avatar_fetched(HTTPFetch *fetch, int account_id, unsigned int id, const std::string &img) {
|
||||
handleVCard(m_ids[account_id], id, "", "", "", img);
|
||||
delete fetch;
|
||||
}
|
||||
|
||||
void handleVCardRequest(const std::string &user, const std::string &legacyName, unsigned int id) {
|
||||
YahooLocalAccount *account = m_users[user];
|
||||
if (!account) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (account->urls.find(legacyName) == account->urls.end()) {
|
||||
return;
|
||||
}
|
||||
|
||||
HTTPFetch *fetch = new HTTPFetch(&m_boostIOServiceThread, m_factories->getConnectionFactory());
|
||||
fetch->onURLFetched.connect(boost::bind(&YahooPlugin::_avatar_fetched, this, fetch, account->id, id, _1));
|
||||
fetch->fetchURL(account->urls[legacyName]);
|
||||
}
|
||||
|
||||
void handleBuddyRemovedRequest(const std::string &user, const std::string &buddyName, const std::vector<std::string> &groups) {
|
||||
|
||||
}
|
||||
|
||||
YahooLocalAccount *getAccount(int id) {
|
||||
return m_users[m_ids[id]];
|
||||
}
|
||||
|
||||
void _yahoo_remove_account(YahooLocalAccount *account) {
|
||||
m_ids.erase(account->id);
|
||||
m_users.erase(account->user);
|
||||
delete account;
|
||||
}
|
||||
|
||||
void _yahoo_connect_finished(YahooLocalAccount *account, yahoo_connect_callback callback, void *data, int conn_tag, bool error) {
|
||||
currently_writting_account = account;
|
||||
if (error) {
|
||||
LOG4CXX_ERROR(logger, account->user << ": Connection error!");
|
||||
callback(NULL, 0, data);
|
||||
// np->handleDisconnected(user, 0, "Connection error.");
|
||||
}
|
||||
else {
|
||||
LOG4CXX_INFO(logger, account->user << ": Connected");
|
||||
// We will have dangling pointer here, but we can't pass boost::shared_ptr here...
|
||||
callback((void *) conn_tag, 0, data);
|
||||
}
|
||||
}
|
||||
|
||||
void _yahoo_write_ready(YahooLocalAccount *account) {
|
||||
// Find all WRITE handlers and inform that they really can write.
|
||||
for (std::map<int, YahooHandler *>::iterator it = account->handlers.begin(); it != account->handlers.end(); it++) {
|
||||
if (it->second->cond == YAHOO_INPUT_WRITE && !it->second->remove_later) {
|
||||
it->second->ready();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _yahoo_data_read(YahooLocalAccount *account, int conn_tag, boost::shared_ptr<Swift::SafeByteArray> data) {
|
||||
std::string d(data->begin(), data->end());
|
||||
|
||||
// Find the handler that handles READing for this conn_tag
|
||||
for (std::map<int, YahooHandler *>::iterator it = account->handlers_per_conn[conn_tag].begin(); it != account->handlers_per_conn[conn_tag].end(); it++) {
|
||||
if (it->second->cond == YAHOO_INPUT_READ && !it->second->remove_later) {
|
||||
std::string cpy(d);
|
||||
it->second->ready(&cpy);
|
||||
|
||||
// Look like libyahoo2 needs to be informed it can write to socket after the read
|
||||
// even we have informed it before...
|
||||
_yahoo_write_ready(account);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
account->removeOldHandlers();
|
||||
}
|
||||
|
||||
void _yahoo_data_written(YahooLocalAccount *account, int conn_tag) {
|
||||
LOG4CXX_INFO(logger, "data written");
|
||||
for (std::map<int, YahooHandler *>::iterator it = account->handlers_per_conn[conn_tag].begin(); it != account->handlers_per_conn[conn_tag].end(); it++) {
|
||||
if (it->second->cond == YAHOO_INPUT_WRITE) {
|
||||
it->second->ready();
|
||||
}
|
||||
}
|
||||
|
||||
account->removeOldHandlers();
|
||||
}
|
||||
|
||||
void _yahoo_disconnected(YahooLocalAccount *account, int conn_tag, const boost::optional<Swift::Connection::Error> &error) {
|
||||
for (std::map<int, YahooHandler *>::iterator it = account->handlers_per_conn[conn_tag].begin(); it != account->handlers_per_conn[conn_tag].end(); it++) {
|
||||
if (it->second->cond == YAHOO_INPUT_READ && !it->second->remove_later) {
|
||||
std::string cpy;
|
||||
it->second->ready(&cpy);
|
||||
_yahoo_write_ready(account);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
account->removeConn(conn_tag);
|
||||
}
|
||||
|
||||
int _yahoo_connect_async(int id, const char *host, int port, yahoo_connect_callback callback, void *data, int use_ssl) {
|
||||
YahooLocalAccount *account = getAccount(id);
|
||||
if (!account) {
|
||||
LOG4CXX_ERROR(logger, "Unknown account id=" << id);
|
||||
return -1;
|
||||
}
|
||||
|
||||
boost::asio::ip::tcp::resolver resolver(*m_boostIOServiceThread.getIOService());
|
||||
boost::asio::ip::tcp::resolver::query query(host, "");
|
||||
boost::asio::ip::address address;
|
||||
for(boost::asio::ip::tcp::resolver::iterator i = resolver.resolve(query); i != boost::asio::ip::tcp::resolver::iterator(); ++i) {
|
||||
boost::asio::ip::tcp::endpoint end = *i;
|
||||
address = end.address();
|
||||
break;
|
||||
}
|
||||
|
||||
LOG4CXX_INFO(logger, m_ids[id] << ": Connecting " << host << ":" << port);
|
||||
int tag = account->conn_tag++;
|
||||
if (use_ssl) {
|
||||
account->conns[tag] = m_tlsFactory->createConnection();
|
||||
}
|
||||
else {
|
||||
account->conns[tag] = m_factories->getConnectionFactory()->createConnection();
|
||||
}
|
||||
account->conns[tag]->onConnectFinished.connect(boost::bind(&YahooPlugin::_yahoo_connect_finished, this, account, callback, data, tag, _1));
|
||||
account->conns[tag]->onDisconnected.connect(boost::bind(&YahooPlugin::_yahoo_disconnected, this, account, tag, _1));
|
||||
account->conns[tag]->onDataRead.connect(boost::bind(&YahooPlugin::_yahoo_data_read, this, account, tag, _1));
|
||||
account->conns[tag]->onDataWritten.connect(boost::bind(&YahooPlugin::_yahoo_data_written, this, account, tag));
|
||||
account->conns[tag]->connect(Swift::HostAddressPort(Swift::HostAddress(address), port));
|
||||
return tag;
|
||||
}
|
||||
|
||||
private:
|
||||
Config *config;
|
||||
std::map<std::string, YahooLocalAccount *> m_users;
|
||||
std::map<int, std::string> m_ids;
|
||||
};
|
||||
|
||||
static void spectrum_sigchld_handler(int sig)
|
||||
{
|
||||
int status;
|
||||
pid_t pid;
|
||||
|
||||
do {
|
||||
pid = waitpid(-1, &status, WNOHANG);
|
||||
} while (pid != 0 && pid != (pid_t)-1);
|
||||
|
||||
if ((pid == (pid_t) - 1) && (errno != ECHILD)) {
|
||||
char errmsg[BUFSIZ];
|
||||
snprintf(errmsg, BUFSIZ, "Warning: waitpid() returned %d", pid);
|
||||
perror(errmsg);
|
||||
}
|
||||
}
|
||||
|
||||
static void ext_yahoo_got_conf_invite(int id, const char *me, const char *who, const char *room, const char *msg, YList *members) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_conf_userdecline(int id, const char *me, const char *who, const char *room, const char *msg) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_conf_userjoin(int id, const char *me, const char *who, const char *room) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_conf_userleave(int id, const char *me, const char *who, const char *room) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_conf_message(int id, const char *me, const char *who, const char *room, const char *msg, int utf8) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_chat_cat_xml(int id, const char *xml) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_chat_join(int id, const char *me, const char *room, const char * topic, YList *members, void *fd) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_chat_userjoin(int id, const char *me, const char *room, struct yahoo_chat_member *who) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_chat_userleave(int id, const char *me, const char *room, const char *who) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_chat_message(int id, const char *me, const char *who, const char *room, const char *msg, int msgtype, int utf8) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_status_changed(int id, const char *who, int stat, const char *msg, int away, int idle, int mobile) {
|
||||
YahooLocalAccount *account = np->getAccount(id);
|
||||
if (!account) {
|
||||
return;
|
||||
}
|
||||
|
||||
LOG4CXX_INFO(logger, account->user << ": " << who << " status changed");
|
||||
|
||||
pbnetwork::StatusType status = pbnetwork::STATUS_NONE;
|
||||
switch (stat) {
|
||||
case YAHOO_STATUS_AVAILABLE:
|
||||
status = pbnetwork::STATUS_ONLINE;
|
||||
break;
|
||||
case YAHOO_STATUS_NOTATHOME:
|
||||
case YAHOO_STATUS_NOTATDESK:
|
||||
case YAHOO_STATUS_NOTINOFFICE:
|
||||
case YAHOO_STATUS_ONPHONE:
|
||||
case YAHOO_STATUS_ONVACATION:
|
||||
case YAHOO_STATUS_OUTTOLUNCH:
|
||||
case YAHOO_STATUS_STEPPEDOUT:
|
||||
status = pbnetwork::STATUS_AWAY;
|
||||
break;
|
||||
case YAHOO_STATUS_BRB:
|
||||
status = pbnetwork::STATUS_XA;
|
||||
break;
|
||||
case YAHOO_STATUS_BUSY:
|
||||
status = pbnetwork::STATUS_DND;
|
||||
break;
|
||||
case YAHOO_STATUS_OFFLINE:
|
||||
status = pbnetwork::STATUS_NONE;
|
||||
break;
|
||||
default:
|
||||
status = pbnetwork::STATUS_ONLINE;
|
||||
break;
|
||||
}
|
||||
|
||||
yahoo_buddyicon_request(id, who);
|
||||
np->_yahoo_write_ready(account);
|
||||
|
||||
np->handleBuddyChanged(account->user, who, "", std::vector<std::string>(), status, msg ? msg : "");
|
||||
}
|
||||
|
||||
static void ext_yahoo_got_buddies(int id, YList * buds) {
|
||||
YahooLocalAccount *account = np->getAccount(id);
|
||||
if (!account) {
|
||||
return;
|
||||
}
|
||||
|
||||
LOG4CXX_INFO(logger, account->user << ": Got buddy list");
|
||||
for(; buds; buds = buds->next) {
|
||||
struct yahoo_buddy *bud = (struct yahoo_buddy *) buds->data;
|
||||
|
||||
std::vector<std::string> groups;
|
||||
groups.push_back(bud->group);
|
||||
np->handleBuddyChanged(account->user, bud->id, bud->real_name ? bud->real_name : "", groups, pbnetwork::STATUS_NONE);
|
||||
}
|
||||
|
||||
// yahoo_set_away(id, YAHOO_STATUS_AVAILABLE, "", 1);
|
||||
np->_yahoo_write_ready(account);
|
||||
np->handleConnected(account->user);
|
||||
}
|
||||
|
||||
static void ext_yahoo_got_ignore(int id, YList * igns)
|
||||
{
|
||||
}
|
||||
|
||||
static void ext_yahoo_got_buzz(int id, const char *me, const char *who, long tm) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_got_im(int id, const char *me, const char *who, const char *msg, long tm, int stat, int utf8) {
|
||||
YahooLocalAccount *account = np->getAccount(id);
|
||||
if (!account) {
|
||||
return;
|
||||
}
|
||||
|
||||
np->handleMessage(account->user, who, msg);
|
||||
}
|
||||
|
||||
static void ext_yahoo_rejected(int id, const char *who, const char *msg) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_contact_added(int id, const char *myid, const char *who, const char *msg) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_typing_notify(int id, const char* me, const char *who, int stat) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_game_notify(int id, const char *me, const char *who, int stat, const char *msg)
|
||||
{
|
||||
}
|
||||
|
||||
static void ext_yahoo_mail_notify(int id, const char *from, const char *subj, int cnt) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_got_webcam_image(int id, const char *who, const unsigned char *image, unsigned int image_size, unsigned int real_size, unsigned int timestamp) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_webcam_viewer(int id, const char *who, int connect) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_webcam_closed(int id, const char *who, int reason) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_webcam_data_request(int id, int send) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_webcam_invite(int id, const char *me, const char *from) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_webcam_invite_reply(int id, const char *me, const char *from, int accept) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_system_message(int id, const char *me, const char *who, const char *msg) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_got_cookies(int id) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_login_response(int id, int succ, const char *url) {
|
||||
YahooLocalAccount *account = np->getAccount(id);
|
||||
if (!account) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (succ == YAHOO_LOGIN_OK) {
|
||||
account->status = yahoo_current_status(id);
|
||||
// We will fire handleConnected in Got Buddy List.
|
||||
return;
|
||||
}
|
||||
else if (succ == YAHOO_LOGIN_UNAME) {
|
||||
np->handleDisconnected(account->user, 0, "Could not log into Yahoo service - username not recognised. Please verify that your username is correctly typed.");
|
||||
}
|
||||
else if (succ == YAHOO_LOGIN_PASSWD) {
|
||||
np->handleDisconnected(account->user, 0, "Could not log into Yahoo service - password incorrect. Please verify that your password is correctly typed.");
|
||||
}
|
||||
else if (succ == YAHOO_LOGIN_LOCK) {
|
||||
np->handleDisconnected(account->user, 0, std::string("Could not log into Yahoo service. Your account has been locked. Visit ") + url + " to reactivate it.");
|
||||
}
|
||||
else if (succ == YAHOO_LOGIN_DUPL) {
|
||||
np->handleDisconnected(account->user, 0, "You have been logged out of the yahoo service, possibly due to a duplicate login.");
|
||||
}
|
||||
else if (succ == YAHOO_LOGIN_SOCK) {
|
||||
np->handleDisconnected(account->user, 0, "The server closed the socket.");
|
||||
}
|
||||
else {
|
||||
np->handleDisconnected(account->user, 0, "Could not log in, unknown reason.");
|
||||
}
|
||||
|
||||
np->handleLogoutRequest(account->user, "");
|
||||
}
|
||||
|
||||
static void ext_yahoo_error(int id, const char *_err, int fatal, int num) {
|
||||
std::string err(_err);
|
||||
std::string msg("Yahoo Error: ");
|
||||
msg += err + " - ";
|
||||
switch(num) {
|
||||
case E_UNKNOWN:
|
||||
msg += "unknown error " + err;
|
||||
break;
|
||||
case E_CUSTOM:
|
||||
msg += "custom error " + err;
|
||||
break;
|
||||
case E_CONFNOTAVAIL:
|
||||
msg += err + " is not available for the conference";
|
||||
break;
|
||||
case E_IGNOREDUP:
|
||||
msg += err + " is already ignored";
|
||||
break;
|
||||
case E_IGNORENONE:
|
||||
msg += err +" is not in the ignore list";
|
||||
break;
|
||||
case E_IGNORECONF:
|
||||
msg += err + " is in buddy list - cannot ignore ";
|
||||
break;
|
||||
case E_SYSTEM:
|
||||
msg += "system error " + err;
|
||||
break;
|
||||
case E_CONNECTION:
|
||||
msg += err + "server connection error %s";
|
||||
break;
|
||||
}
|
||||
LOG4CXX_ERROR(logger, msg);
|
||||
|
||||
YahooLocalAccount *account = np->getAccount(id);
|
||||
if (!account) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(fatal) {
|
||||
np->handleDisconnected(account->user, 0, msg);
|
||||
np->handleLogoutRequest(account->user, "");
|
||||
}
|
||||
}
|
||||
|
||||
static int ext_yahoo_connect(const char *host, int port) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int ext_yahoo_add_handler(int id, void *fd, yahoo_input_condition cond, void *data) {
|
||||
YahooLocalAccount *account = np->getAccount(id);
|
||||
if (!account) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int conn_tag = (unsigned long) fd;
|
||||
YahooHandler *handler = new YahooHandler(account, conn_tag, account->handler_tag++, data, cond);
|
||||
account->addHandler(handler);
|
||||
|
||||
// We are ready to write right now, so why not...
|
||||
handler->ready();
|
||||
|
||||
return handler->handler_tag;
|
||||
}
|
||||
|
||||
static void ext_yahoo_remove_handler(int id, int tag) {
|
||||
YahooLocalAccount *account = np->getAccount(id);
|
||||
if (!account) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (account->handlers.find(tag) == account->handlers.end()) {
|
||||
return;
|
||||
}
|
||||
|
||||
YahooHandler *handler = account->handlers[tag];
|
||||
handler->remove_later = true;
|
||||
}
|
||||
|
||||
static int ext_yahoo_write(void *fd, char *buf, int len) {
|
||||
int conn_tag = (unsigned long) fd;
|
||||
YahooLocalAccount *account = currently_writting_account;
|
||||
|
||||
std::string string(buf, len);
|
||||
account->conns[conn_tag]->write(Swift::createSafeByteArray(string));
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
static int ext_yahoo_read(void *fd, char *buf, int len) {
|
||||
if (currently_read_data->size() < len) {
|
||||
len = currently_read_data->size();
|
||||
}
|
||||
memcpy(buf, currently_read_data->c_str(), len);
|
||||
currently_read_data->erase(0, len);
|
||||
return len;
|
||||
}
|
||||
|
||||
static void ext_yahoo_close(void *fd) {
|
||||
// No need to do anything here. We close it properly in _yahoo_disconnected(...);
|
||||
}
|
||||
|
||||
static int ext_yahoo_connect_async(int id, const char *host, int port, yahoo_connect_callback callback, void *data, int use_ssl) {
|
||||
return np->_yahoo_connect_async(id, host, port, callback, data, use_ssl);
|
||||
}
|
||||
|
||||
static void ext_yahoo_got_file(int id, const char *me, const char *who, const char *msg, const char *fname, unsigned long fesize, char *trid) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_file_transfer_done(int id, int response, void *data) {
|
||||
}
|
||||
|
||||
static char *ext_yahoo_get_ip_addr(const char *domain) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void ext_yahoo_got_ft_data(int id, const unsigned char *in, int count, void *data) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_got_identities(int id, YList * ids) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_chat_yahoologout(int id, const char *me) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_chat_yahooerror(int id, const char *me) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_got_ping(int id, const char *errormsg){
|
||||
}
|
||||
|
||||
static void ext_yahoo_got_search_result(int id, int found, int start, int total, YList *contacts) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_got_buddyicon_checksum(int id, const char *a, const char *b, int checksum) {
|
||||
LOG4CXX_INFO(logger, "got buddyicon_checksum");
|
||||
}
|
||||
|
||||
static void ext_yahoo_got_buddy_change_group(int id, const char *me, const char *who, const char *old_group, const char *new_group) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_got_buddyicon(int id, const char *me, const char *who, const char *url, int checksum) {
|
||||
YahooLocalAccount *account = np->getAccount(id);
|
||||
if (!account) {
|
||||
return;
|
||||
}
|
||||
|
||||
LOG4CXX_INFO(logger, account->user << ": got buddyicon of " << who);
|
||||
account->urls[who] = url;
|
||||
}
|
||||
|
||||
static void ext_yahoo_buddyicon_uploaded(int id, const char *url) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_got_buddyicon_request(int id, const char *me, const char *who) {
|
||||
LOG4CXX_INFO(logger, "got buddyicon_request");
|
||||
}
|
||||
|
||||
static int ext_yahoo_log(const char *fmt,...)
|
||||
{
|
||||
static char log[8192];
|
||||
static std::string buffered;
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
|
||||
vsnprintf(log, 8191, fmt, ap);
|
||||
buffered += log;
|
||||
if (buffered.find('\n') != std::string::npos) {
|
||||
buffered.erase(buffered.find('\n'), 1);
|
||||
LOG4CXX_INFO(logger, buffered);
|
||||
buffered.clear();
|
||||
}
|
||||
fflush(stderr);
|
||||
va_end(ap);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void register_callbacks()
|
||||
{
|
||||
static struct yahoo_callbacks yc;
|
||||
|
||||
yc.ext_yahoo_login_response = ext_yahoo_login_response;
|
||||
yc.ext_yahoo_got_buddies = ext_yahoo_got_buddies;
|
||||
yc.ext_yahoo_got_ignore = ext_yahoo_got_ignore;
|
||||
yc.ext_yahoo_got_identities = ext_yahoo_got_identities;
|
||||
yc.ext_yahoo_got_cookies = ext_yahoo_got_cookies;
|
||||
yc.ext_yahoo_status_changed = ext_yahoo_status_changed;
|
||||
yc.ext_yahoo_got_im = ext_yahoo_got_im;
|
||||
yc.ext_yahoo_got_buzz = ext_yahoo_got_buzz;
|
||||
yc.ext_yahoo_got_conf_invite = ext_yahoo_got_conf_invite;
|
||||
yc.ext_yahoo_conf_userdecline = ext_yahoo_conf_userdecline;
|
||||
yc.ext_yahoo_conf_userjoin = ext_yahoo_conf_userjoin;
|
||||
yc.ext_yahoo_conf_userleave = ext_yahoo_conf_userleave;
|
||||
yc.ext_yahoo_conf_message = ext_yahoo_conf_message;
|
||||
yc.ext_yahoo_chat_cat_xml = ext_yahoo_chat_cat_xml;
|
||||
yc.ext_yahoo_chat_join = ext_yahoo_chat_join;
|
||||
yc.ext_yahoo_chat_userjoin = ext_yahoo_chat_userjoin;
|
||||
yc.ext_yahoo_chat_userleave = ext_yahoo_chat_userleave;
|
||||
yc.ext_yahoo_chat_message = ext_yahoo_chat_message;
|
||||
yc.ext_yahoo_chat_yahoologout = ext_yahoo_chat_yahoologout;
|
||||
yc.ext_yahoo_chat_yahooerror = ext_yahoo_chat_yahooerror;
|
||||
yc.ext_yahoo_got_webcam_image = ext_yahoo_got_webcam_image;
|
||||
yc.ext_yahoo_webcam_invite = ext_yahoo_webcam_invite;
|
||||
yc.ext_yahoo_webcam_invite_reply = ext_yahoo_webcam_invite_reply;
|
||||
yc.ext_yahoo_webcam_closed = ext_yahoo_webcam_closed;
|
||||
yc.ext_yahoo_webcam_viewer = ext_yahoo_webcam_viewer;
|
||||
yc.ext_yahoo_webcam_data_request = ext_yahoo_webcam_data_request;
|
||||
yc.ext_yahoo_got_file = ext_yahoo_got_file;
|
||||
yc.ext_yahoo_got_ft_data = ext_yahoo_got_ft_data;
|
||||
yc.ext_yahoo_get_ip_addr = ext_yahoo_get_ip_addr;
|
||||
yc.ext_yahoo_file_transfer_done = ext_yahoo_file_transfer_done;
|
||||
yc.ext_yahoo_contact_added = ext_yahoo_contact_added;
|
||||
yc.ext_yahoo_rejected = ext_yahoo_rejected;
|
||||
yc.ext_yahoo_typing_notify = ext_yahoo_typing_notify;
|
||||
yc.ext_yahoo_game_notify = ext_yahoo_game_notify;
|
||||
yc.ext_yahoo_mail_notify = ext_yahoo_mail_notify;
|
||||
yc.ext_yahoo_got_search_result = ext_yahoo_got_search_result;
|
||||
yc.ext_yahoo_system_message = ext_yahoo_system_message;
|
||||
yc.ext_yahoo_error = ext_yahoo_error;
|
||||
yc.ext_yahoo_log = ext_yahoo_log;
|
||||
yc.ext_yahoo_add_handler = ext_yahoo_add_handler;
|
||||
yc.ext_yahoo_remove_handler = ext_yahoo_remove_handler;
|
||||
yc.ext_yahoo_connect = ext_yahoo_connect;
|
||||
yc.ext_yahoo_connect_async = ext_yahoo_connect_async;
|
||||
yc.ext_yahoo_read = ext_yahoo_read;
|
||||
yc.ext_yahoo_write = ext_yahoo_write;
|
||||
yc.ext_yahoo_close = ext_yahoo_close;
|
||||
yc.ext_yahoo_got_buddyicon = ext_yahoo_got_buddyicon;
|
||||
yc.ext_yahoo_got_buddyicon_checksum = ext_yahoo_got_buddyicon_checksum;
|
||||
yc.ext_yahoo_buddyicon_uploaded = ext_yahoo_buddyicon_uploaded;
|
||||
yc.ext_yahoo_got_buddyicon_request = ext_yahoo_got_buddyicon_request;
|
||||
yc.ext_yahoo_got_ping = ext_yahoo_got_ping;
|
||||
yc.ext_yahoo_got_buddy_change_group = ext_yahoo_got_buddy_change_group;
|
||||
|
||||
yahoo_register_callbacks(&yc);
|
||||
}
|
||||
|
||||
int main (int argc, char* argv[]) {
|
||||
std::string host;
|
||||
int port;
|
||||
|
||||
#ifndef _WIN32
|
||||
if (signal(SIGCHLD, spectrum_sigchld_handler) == SIG_ERR) {
|
||||
std::cout << "SIGCHLD handler can't be set\n";
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
std::string error;
|
||||
Config *cfg = Config::createFromArgs(argc, argv, error, host, port);
|
||||
if (cfg == NULL) {
|
||||
std::cerr << error;
|
||||
return 1;
|
||||
}
|
||||
|
||||
Logging::initBackendLogging(cfg);
|
||||
|
||||
register_callbacks();
|
||||
yahoo_set_log_level(YAHOO_LOG_DEBUG);
|
||||
|
||||
Swift::SimpleEventLoop eventLoop;
|
||||
loop_ = &eventLoop;
|
||||
np = new YahooPlugin(cfg, &eventLoop, host, port);
|
||||
loop_->run();
|
||||
|
||||
return 0;
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -1,212 +0,0 @@
|
|||
/* One way encryption based on MD5 sum.
|
||||
Copyright (C) 1996, 1997, 1999, 2000 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
02111-1307 USA. */
|
||||
|
||||
/* warmenhoven took this file and made it work with the md5.[ch] we
|
||||
* already had. isn't that lovely. people should just use linux or
|
||||
* freebsd, crypt works properly on those systems. i hate solaris */
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#ifdef __APPLE__
|
||||
#define HAVE_STRING_H 1
|
||||
#endif
|
||||
|
||||
#if HAVE_STRING_H
|
||||
# include <string.h>
|
||||
#elif HAVE_STRINGS_H
|
||||
# include <strings.h>
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "yahoo_util.h"
|
||||
|
||||
#include "md5.h"
|
||||
|
||||
/* Define our magic string to mark salt for MD5 "encryption"
|
||||
replacement. This is meant to be the same as for other MD5 based
|
||||
encryption implementations. */
|
||||
static const char md5_salt_prefix[] = "$1$";
|
||||
|
||||
/* Table with characters for base64 transformation. */
|
||||
static const char b64t[64] =
|
||||
"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||
|
||||
char *yahoo_crypt(char *key, char *salt)
|
||||
{
|
||||
char *buffer = NULL;
|
||||
int buflen = 0;
|
||||
int needed = 3 + strlen(salt) + 1 + 26 + 1;
|
||||
|
||||
md5_byte_t alt_result[16];
|
||||
md5_state_t ctx;
|
||||
md5_state_t alt_ctx;
|
||||
size_t salt_len;
|
||||
size_t key_len;
|
||||
size_t cnt;
|
||||
char *cp;
|
||||
|
||||
if (buflen < needed) {
|
||||
buflen = needed;
|
||||
if ((buffer = realloc(buffer, buflen)) == NULL)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Find beginning of salt string. The prefix should normally always
|
||||
be present. Just in case it is not. */
|
||||
if (strncmp(md5_salt_prefix, salt, sizeof(md5_salt_prefix) - 1) == 0)
|
||||
/* Skip salt prefix. */
|
||||
salt += sizeof(md5_salt_prefix) - 1;
|
||||
|
||||
salt_len = MIN(strcspn(salt, "$"), 8);
|
||||
key_len = strlen(key);
|
||||
|
||||
/* Prepare for the real work. */
|
||||
md5_init(&ctx);
|
||||
|
||||
/* Add the key string. */
|
||||
md5_append(&ctx, (md5_byte_t *)key, key_len);
|
||||
|
||||
/* Because the SALT argument need not always have the salt prefix we
|
||||
add it separately. */
|
||||
md5_append(&ctx, (md5_byte_t *)md5_salt_prefix,
|
||||
sizeof(md5_salt_prefix) - 1);
|
||||
|
||||
/* The last part is the salt string. This must be at most 8
|
||||
characters and it ends at the first `$' character (for
|
||||
compatibility which existing solutions). */
|
||||
md5_append(&ctx, (md5_byte_t *)salt, salt_len);
|
||||
|
||||
/* Compute alternate MD5 sum with input KEY, SALT, and KEY. The
|
||||
final result will be added to the first context. */
|
||||
md5_init(&alt_ctx);
|
||||
|
||||
/* Add key. */
|
||||
md5_append(&alt_ctx, (md5_byte_t *)key, key_len);
|
||||
|
||||
/* Add salt. */
|
||||
md5_append(&alt_ctx, (md5_byte_t *)salt, salt_len);
|
||||
|
||||
/* Add key again. */
|
||||
md5_append(&alt_ctx, (md5_byte_t *)key, key_len);
|
||||
|
||||
/* Now get result of this (16 bytes) and add it to the other
|
||||
context. */
|
||||
md5_finish(&alt_ctx, alt_result);
|
||||
|
||||
/* Add for any character in the key one byte of the alternate sum. */
|
||||
for (cnt = key_len; cnt > 16; cnt -= 16)
|
||||
md5_append(&ctx, alt_result, 16);
|
||||
md5_append(&ctx, alt_result, cnt);
|
||||
|
||||
/* For the following code we need a NUL byte. */
|
||||
alt_result[0] = '\0';
|
||||
|
||||
/* The original implementation now does something weird: for every 1
|
||||
bit in the key the first 0 is added to the buffer, for every 0
|
||||
bit the first character of the key. This does not seem to be
|
||||
what was intended but we have to follow this to be compatible. */
|
||||
for (cnt = key_len; cnt > 0; cnt >>= 1)
|
||||
md5_append(&ctx,
|
||||
(cnt & 1) != 0 ? alt_result : (md5_byte_t *)key, 1);
|
||||
|
||||
/* Create intermediate result. */
|
||||
md5_finish(&ctx, alt_result);
|
||||
|
||||
/* Now comes another weirdness. In fear of password crackers here
|
||||
comes a quite long loop which just processes the output of the
|
||||
previous round again. We cannot ignore this here. */
|
||||
for (cnt = 0; cnt < 1000; ++cnt) {
|
||||
/* New context. */
|
||||
md5_init(&ctx);
|
||||
|
||||
/* Add key or last result. */
|
||||
if ((cnt & 1) != 0)
|
||||
md5_append(&ctx, (md5_byte_t *)key, key_len);
|
||||
else
|
||||
md5_append(&ctx, alt_result, 16);
|
||||
|
||||
/* Add salt for numbers not divisible by 3. */
|
||||
if (cnt % 3 != 0)
|
||||
md5_append(&ctx, (md5_byte_t *)salt, salt_len);
|
||||
|
||||
/* Add key for numbers not divisible by 7. */
|
||||
if (cnt % 7 != 0)
|
||||
md5_append(&ctx, (md5_byte_t *)key, key_len);
|
||||
|
||||
/* Add key or last result. */
|
||||
if ((cnt & 1) != 0)
|
||||
md5_append(&ctx, alt_result, 16);
|
||||
else
|
||||
md5_append(&ctx, (md5_byte_t *)key, key_len);
|
||||
|
||||
/* Create intermediate result. */
|
||||
md5_finish(&ctx, alt_result);
|
||||
}
|
||||
|
||||
/* Now we can construct the result string. It consists of three
|
||||
parts. */
|
||||
|
||||
strncpy(buffer, md5_salt_prefix, MAX(0, buflen));
|
||||
cp = buffer + strlen(buffer);
|
||||
buflen -= sizeof(md5_salt_prefix);
|
||||
|
||||
strncpy(cp, salt, MIN((size_t) buflen, salt_len));
|
||||
cp = cp + strlen(cp);
|
||||
buflen -= MIN((size_t) buflen, salt_len);
|
||||
|
||||
if (buflen > 0) {
|
||||
*cp++ = '$';
|
||||
--buflen;
|
||||
}
|
||||
#define b64_from_24bit(B2, B1, B0, N) \
|
||||
do { \
|
||||
unsigned int w = ((B2) << 16) | ((B1) << 8) | (B0); \
|
||||
int n = (N); \
|
||||
while (n-- > 0 && buflen > 0) { \
|
||||
*cp++ = b64t[w & 0x3f]; \
|
||||
--buflen; \
|
||||
w >>= 6; \
|
||||
}\
|
||||
} while (0)
|
||||
|
||||
b64_from_24bit(alt_result[0], alt_result[6], alt_result[12], 4);
|
||||
b64_from_24bit(alt_result[1], alt_result[7], alt_result[13], 4);
|
||||
b64_from_24bit(alt_result[2], alt_result[8], alt_result[14], 4);
|
||||
b64_from_24bit(alt_result[3], alt_result[9], alt_result[15], 4);
|
||||
b64_from_24bit(alt_result[4], alt_result[10], alt_result[5], 4);
|
||||
b64_from_24bit(0, 0, alt_result[11], 2);
|
||||
if (buflen <= 0) {
|
||||
FREE(buffer);
|
||||
} else
|
||||
*cp = '\0'; /* Terminate the string. */
|
||||
|
||||
/* Clear the buffer for the intermediate result so that people
|
||||
attaching to processes or reading core dumps cannot get any
|
||||
information. We do it in this way to clear correct_words[]
|
||||
inside the MD5 implementation as well. */
|
||||
md5_init(&ctx);
|
||||
md5_finish(&ctx, alt_result);
|
||||
memset(&ctx, '\0', sizeof(ctx));
|
||||
memset(&alt_ctx, '\0', sizeof(alt_ctx));
|
||||
|
||||
return buffer;
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -1,405 +0,0 @@
|
|||
/*
|
||||
Copyright (C) 1999 Aladdin Enterprises. All rights reserved.
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
L. Peter Deutsch
|
||||
ghost@aladdin.com
|
||||
|
||||
*/
|
||||
/*
|
||||
Independent implementation of MD5 (RFC 1321).
|
||||
|
||||
This code implements the MD5 Algorithm defined in RFC 1321.
|
||||
It is derived directly from the text of the RFC and not from the
|
||||
reference implementation.
|
||||
|
||||
The original and principal author of md5.c is L. Peter Deutsch
|
||||
<ghost@aladdin.com>. Other authors are noted in the change history
|
||||
that follows (in reverse chronological order):
|
||||
|
||||
1999-11-04 lpd Edited comments slightly for automatic TOC extraction.
|
||||
1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5).
|
||||
1999-05-03 lpd Original version.
|
||||
*/
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include "md5.h"
|
||||
|
||||
#if STDC_HEADERS
|
||||
# include <string.h>
|
||||
#else
|
||||
# if !HAVE_STRCHR
|
||||
# define strchr index
|
||||
# define strrchr rindex
|
||||
# endif
|
||||
char *strchr(), *strrchr();
|
||||
# if !HAVE_MEMCPY
|
||||
# define memcpy(d, s, n) bcopy ((s), (d), (n))
|
||||
# define memmove(d, s, n) bcopy ((s), (d), (n))
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef TEST
|
||||
/*
|
||||
* Compile with -DTEST to create a self-contained executable test program.
|
||||
* The test program should print out the same values as given in section
|
||||
* A.5 of RFC 1321, reproduced below.
|
||||
*/
|
||||
main()
|
||||
{
|
||||
static const char *const test[7] = {
|
||||
"", /*d41d8cd98f00b204e9800998ecf8427e */
|
||||
"945399884.61923487334tuvga", /*0cc175b9c0f1b6a831c399e269772661 */
|
||||
"abc", /*900150983cd24fb0d6963f7d28e17f72 */
|
||||
"message digest", /*f96b697d7cb7938d525a2f31aaf161d0 */
|
||||
"abcdefghijklmnopqrstuvwxyz", /*c3fcd3d76192e4007dfb496cca67e13b */
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
|
||||
/*d174ab98d277d9f5a5611c2c9f419d9f */
|
||||
"12345678901234567890123456789012345678901234567890123456789012345678901234567890" /*57edf4a22be3c955ac49da2e2107b67a */
|
||||
};
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 7; ++i) {
|
||||
md5_state_t state;
|
||||
md5_byte_t digest[16];
|
||||
int di;
|
||||
|
||||
md5_init(&state);
|
||||
md5_append(&state, (const md5_byte_t *)test[i],
|
||||
strlen(test[i]));
|
||||
md5_finish(&state, digest);
|
||||
printf("MD5 (\"%s\") = ", test[i]);
|
||||
for (di = 0; di < 16; ++di)
|
||||
printf("%02x", digest[di]);
|
||||
printf("\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif /* TEST */
|
||||
|
||||
/*
|
||||
* For reference, here is the program that computed the T values.
|
||||
*/
|
||||
#if 0
|
||||
#include <math.h>
|
||||
main()
|
||||
{
|
||||
int i;
|
||||
for (i = 1; i <= 64; ++i) {
|
||||
unsigned long v =
|
||||
(unsigned long)(4294967296.0 * fabs(sin((double)i)));
|
||||
printf("#define T%d 0x%08lx\n", i, v);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
* End of T computation program.
|
||||
*/
|
||||
#define T1 0xd76aa478
|
||||
#define T2 0xe8c7b756
|
||||
#define T3 0x242070db
|
||||
#define T4 0xc1bdceee
|
||||
#define T5 0xf57c0faf
|
||||
#define T6 0x4787c62a
|
||||
#define T7 0xa8304613
|
||||
#define T8 0xfd469501
|
||||
#define T9 0x698098d8
|
||||
#define T10 0x8b44f7af
|
||||
#define T11 0xffff5bb1
|
||||
#define T12 0x895cd7be
|
||||
#define T13 0x6b901122
|
||||
#define T14 0xfd987193
|
||||
#define T15 0xa679438e
|
||||
#define T16 0x49b40821
|
||||
#define T17 0xf61e2562
|
||||
#define T18 0xc040b340
|
||||
#define T19 0x265e5a51
|
||||
#define T20 0xe9b6c7aa
|
||||
#define T21 0xd62f105d
|
||||
#define T22 0x02441453
|
||||
#define T23 0xd8a1e681
|
||||
#define T24 0xe7d3fbc8
|
||||
#define T25 0x21e1cde6
|
||||
#define T26 0xc33707d6
|
||||
#define T27 0xf4d50d87
|
||||
#define T28 0x455a14ed
|
||||
#define T29 0xa9e3e905
|
||||
#define T30 0xfcefa3f8
|
||||
#define T31 0x676f02d9
|
||||
#define T32 0x8d2a4c8a
|
||||
#define T33 0xfffa3942
|
||||
#define T34 0x8771f681
|
||||
#define T35 0x6d9d6122
|
||||
#define T36 0xfde5380c
|
||||
#define T37 0xa4beea44
|
||||
#define T38 0x4bdecfa9
|
||||
#define T39 0xf6bb4b60
|
||||
#define T40 0xbebfbc70
|
||||
#define T41 0x289b7ec6
|
||||
#define T42 0xeaa127fa
|
||||
#define T43 0xd4ef3085
|
||||
#define T44 0x04881d05
|
||||
#define T45 0xd9d4d039
|
||||
#define T46 0xe6db99e5
|
||||
#define T47 0x1fa27cf8
|
||||
#define T48 0xc4ac5665
|
||||
#define T49 0xf4292244
|
||||
#define T50 0x432aff97
|
||||
#define T51 0xab9423a7
|
||||
#define T52 0xfc93a039
|
||||
#define T53 0x655b59c3
|
||||
#define T54 0x8f0ccc92
|
||||
#define T55 0xffeff47d
|
||||
#define T56 0x85845dd1
|
||||
#define T57 0x6fa87e4f
|
||||
#define T58 0xfe2ce6e0
|
||||
#define T59 0xa3014314
|
||||
#define T60 0x4e0811a1
|
||||
#define T61 0xf7537e82
|
||||
#define T62 0xbd3af235
|
||||
#define T63 0x2ad7d2bb
|
||||
#define T64 0xeb86d391
|
||||
|
||||
static void md5_process(md5_state_t *pms, const md5_byte_t *data /*[64] */ )
|
||||
{
|
||||
md5_word_t
|
||||
a = pms->abcd[0], b = pms->abcd[1],
|
||||
c = pms->abcd[2], d = pms->abcd[3];
|
||||
md5_word_t t;
|
||||
|
||||
#ifndef ARCH_IS_BIG_ENDIAN
|
||||
# define ARCH_IS_BIG_ENDIAN 1 /* slower, default implementation */
|
||||
#endif
|
||||
#if ARCH_IS_BIG_ENDIAN
|
||||
|
||||
/*
|
||||
* On big-endian machines, we must arrange the bytes in the right
|
||||
* order. (This also works on machines of unknown byte order.)
|
||||
*/
|
||||
md5_word_t X[16];
|
||||
const md5_byte_t *xp = data;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 16; ++i, xp += 4)
|
||||
X[i] = xp[0] + (xp[1] << 8) + (xp[2] << 16) + (xp[3] << 24);
|
||||
|
||||
#else /* !ARCH_IS_BIG_ENDIAN */
|
||||
|
||||
/*
|
||||
* On little-endian machines, we can process properly aligned data
|
||||
* without copying it.
|
||||
*/
|
||||
md5_word_t xbuf[16];
|
||||
const md5_word_t *X;
|
||||
|
||||
if (!((data - (const md5_byte_t *)0) & 3)) {
|
||||
/* data are properly aligned */
|
||||
X = (const md5_word_t *)data;
|
||||
} else {
|
||||
/* not aligned */
|
||||
memcpy(xbuf, data, 64);
|
||||
X = xbuf;
|
||||
}
|
||||
#endif
|
||||
|
||||
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32 - (n))))
|
||||
|
||||
/* Round 1. */
|
||||
/* Let [abcd k s i] denote the operation
|
||||
a = b + ((a + F(b,c,d) + X[k] + T[i]) <<< s). */
|
||||
#define F(x, y, z) (((x) & (y)) | (~(x) & (z)))
|
||||
#define SET(a, b, c, d, k, s, Ti)\
|
||||
t = a + F(b,c,d) + X[k] + Ti;\
|
||||
a = ROTATE_LEFT(t, s) + b
|
||||
/* Do the following 16 operations. */
|
||||
SET(a, b, c, d, 0, 7, T1);
|
||||
SET(d, a, b, c, 1, 12, T2);
|
||||
SET(c, d, a, b, 2, 17, T3);
|
||||
SET(b, c, d, a, 3, 22, T4);
|
||||
SET(a, b, c, d, 4, 7, T5);
|
||||
SET(d, a, b, c, 5, 12, T6);
|
||||
SET(c, d, a, b, 6, 17, T7);
|
||||
SET(b, c, d, a, 7, 22, T8);
|
||||
SET(a, b, c, d, 8, 7, T9);
|
||||
SET(d, a, b, c, 9, 12, T10);
|
||||
SET(c, d, a, b, 10, 17, T11);
|
||||
SET(b, c, d, a, 11, 22, T12);
|
||||
SET(a, b, c, d, 12, 7, T13);
|
||||
SET(d, a, b, c, 13, 12, T14);
|
||||
SET(c, d, a, b, 14, 17, T15);
|
||||
SET(b, c, d, a, 15, 22, T16);
|
||||
#undef SET
|
||||
|
||||
/* Round 2. */
|
||||
/* Let [abcd k s i] denote the operation
|
||||
a = b + ((a + G(b,c,d) + X[k] + T[i]) <<< s). */
|
||||
#define G(x, y, z) (((x) & (z)) | ((y) & ~(z)))
|
||||
#define SET(a, b, c, d, k, s, Ti)\
|
||||
t = a + G(b,c,d) + X[k] + Ti;\
|
||||
a = ROTATE_LEFT(t, s) + b
|
||||
/* Do the following 16 operations. */
|
||||
SET(a, b, c, d, 1, 5, T17);
|
||||
SET(d, a, b, c, 6, 9, T18);
|
||||
SET(c, d, a, b, 11, 14, T19);
|
||||
SET(b, c, d, a, 0, 20, T20);
|
||||
SET(a, b, c, d, 5, 5, T21);
|
||||
SET(d, a, b, c, 10, 9, T22);
|
||||
SET(c, d, a, b, 15, 14, T23);
|
||||
SET(b, c, d, a, 4, 20, T24);
|
||||
SET(a, b, c, d, 9, 5, T25);
|
||||
SET(d, a, b, c, 14, 9, T26);
|
||||
SET(c, d, a, b, 3, 14, T27);
|
||||
SET(b, c, d, a, 8, 20, T28);
|
||||
SET(a, b, c, d, 13, 5, T29);
|
||||
SET(d, a, b, c, 2, 9, T30);
|
||||
SET(c, d, a, b, 7, 14, T31);
|
||||
SET(b, c, d, a, 12, 20, T32);
|
||||
#undef SET
|
||||
|
||||
/* Round 3. */
|
||||
/* Let [abcd k s t] denote the operation
|
||||
a = b + ((a + H(b,c,d) + X[k] + T[i]) <<< s). */
|
||||
#define H(x, y, z) ((x) ^ (y) ^ (z))
|
||||
#define SET(a, b, c, d, k, s, Ti)\
|
||||
t = a + H(b,c,d) + X[k] + Ti;\
|
||||
a = ROTATE_LEFT(t, s) + b
|
||||
/* Do the following 16 operations. */
|
||||
SET(a, b, c, d, 5, 4, T33);
|
||||
SET(d, a, b, c, 8, 11, T34);
|
||||
SET(c, d, a, b, 11, 16, T35);
|
||||
SET(b, c, d, a, 14, 23, T36);
|
||||
SET(a, b, c, d, 1, 4, T37);
|
||||
SET(d, a, b, c, 4, 11, T38);
|
||||
SET(c, d, a, b, 7, 16, T39);
|
||||
SET(b, c, d, a, 10, 23, T40);
|
||||
SET(a, b, c, d, 13, 4, T41);
|
||||
SET(d, a, b, c, 0, 11, T42);
|
||||
SET(c, d, a, b, 3, 16, T43);
|
||||
SET(b, c, d, a, 6, 23, T44);
|
||||
SET(a, b, c, d, 9, 4, T45);
|
||||
SET(d, a, b, c, 12, 11, T46);
|
||||
SET(c, d, a, b, 15, 16, T47);
|
||||
SET(b, c, d, a, 2, 23, T48);
|
||||
#undef SET
|
||||
|
||||
/* Round 4. */
|
||||
/* Let [abcd k s t] denote the operation
|
||||
a = b + ((a + I(b,c,d) + X[k] + T[i]) <<< s). */
|
||||
#define I(x, y, z) ((y) ^ ((x) | ~(z)))
|
||||
#define SET(a, b, c, d, k, s, Ti)\
|
||||
t = a + I(b,c,d) + X[k] + Ti;\
|
||||
a = ROTATE_LEFT(t, s) + b
|
||||
/* Do the following 16 operations. */
|
||||
SET(a, b, c, d, 0, 6, T49);
|
||||
SET(d, a, b, c, 7, 10, T50);
|
||||
SET(c, d, a, b, 14, 15, T51);
|
||||
SET(b, c, d, a, 5, 21, T52);
|
||||
SET(a, b, c, d, 12, 6, T53);
|
||||
SET(d, a, b, c, 3, 10, T54);
|
||||
SET(c, d, a, b, 10, 15, T55);
|
||||
SET(b, c, d, a, 1, 21, T56);
|
||||
SET(a, b, c, d, 8, 6, T57);
|
||||
SET(d, a, b, c, 15, 10, T58);
|
||||
SET(c, d, a, b, 6, 15, T59);
|
||||
SET(b, c, d, a, 13, 21, T60);
|
||||
SET(a, b, c, d, 4, 6, T61);
|
||||
SET(d, a, b, c, 11, 10, T62);
|
||||
SET(c, d, a, b, 2, 15, T63);
|
||||
SET(b, c, d, a, 9, 21, T64);
|
||||
#undef SET
|
||||
|
||||
/* Then perform the following additions. (That is increment each
|
||||
of the four registers by the value it had before this block
|
||||
was started.) */
|
||||
pms->abcd[0] += a;
|
||||
pms->abcd[1] += b;
|
||||
pms->abcd[2] += c;
|
||||
pms->abcd[3] += d;
|
||||
}
|
||||
|
||||
void md5_init(md5_state_t *pms)
|
||||
{
|
||||
pms->count[0] = pms->count[1] = 0;
|
||||
pms->abcd[0] = 0x67452301;
|
||||
pms->abcd[1] = 0xefcdab89;
|
||||
pms->abcd[2] = 0x98badcfe;
|
||||
pms->abcd[3] = 0x10325476;
|
||||
}
|
||||
|
||||
void md5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes)
|
||||
{
|
||||
const md5_byte_t *p = data;
|
||||
int left = nbytes;
|
||||
int offset = (pms->count[0] >> 3) & 63;
|
||||
md5_word_t nbits = (md5_word_t) (nbytes << 3);
|
||||
|
||||
if (nbytes <= 0)
|
||||
return;
|
||||
|
||||
/* Update the message length. */
|
||||
pms->count[1] += nbytes >> 29;
|
||||
pms->count[0] += nbits;
|
||||
if (pms->count[0] < nbits)
|
||||
pms->count[1]++;
|
||||
|
||||
/* Process an initial partial block. */
|
||||
if (offset) {
|
||||
int copy = (offset + nbytes > 64 ? 64 - offset : nbytes);
|
||||
|
||||
memcpy(pms->buf + offset, p, copy);
|
||||
if (offset + copy < 64)
|
||||
return;
|
||||
p += copy;
|
||||
left -= copy;
|
||||
md5_process(pms, pms->buf);
|
||||
}
|
||||
|
||||
/* Process full blocks. */
|
||||
for (; left >= 64; p += 64, left -= 64)
|
||||
md5_process(pms, p);
|
||||
|
||||
/* Process a final partial block. */
|
||||
if (left)
|
||||
memcpy(pms->buf, p, left);
|
||||
}
|
||||
|
||||
void md5_finish(md5_state_t *pms, md5_byte_t digest[16])
|
||||
{
|
||||
static const md5_byte_t pad[64] = {
|
||||
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
md5_byte_t data[8];
|
||||
int i;
|
||||
|
||||
/* Save the length before padding. */
|
||||
for (i = 0; i < 8; ++i)
|
||||
data[i] = (md5_byte_t) (pms->count[i >> 2] >> ((i & 3) << 3));
|
||||
/* Pad to 56 bytes mod 64. */
|
||||
md5_append(pms, pad, ((55 - (pms->count[0] >> 3)) & 63) + 1);
|
||||
/* Append the length. */
|
||||
md5_append(pms, data, 8);
|
||||
for (i = 0; i < 16; ++i)
|
||||
digest[i] = (md5_byte_t) (pms->abcd[i >> 2] >> ((i & 3) << 3));
|
||||
}
|
|
@ -1,92 +0,0 @@
|
|||
/*
|
||||
Copyright (C) 1999 Aladdin Enterprises. All rights reserved.
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
L. Peter Deutsch
|
||||
ghost@aladdin.com
|
||||
|
||||
*/
|
||||
/*
|
||||
Independent implementation of MD5 (RFC 1321).
|
||||
|
||||
This code implements the MD5 Algorithm defined in RFC 1321.
|
||||
It is derived directly from the text of the RFC and not from the
|
||||
reference implementation.
|
||||
|
||||
The original and principal author of md5.h is L. Peter Deutsch
|
||||
<ghost@aladdin.com>. Other authors are noted in the change history
|
||||
that follows (in reverse chronological order):
|
||||
|
||||
1999-11-04 lpd Edited comments slightly for automatic TOC extraction.
|
||||
1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5);
|
||||
added conditionalization for C++ compilation from Martin
|
||||
Purschke <purschke@bnl.gov>.
|
||||
1999-05-03 lpd Original version.
|
||||
*/
|
||||
|
||||
#ifndef md5_INCLUDED
|
||||
# define md5_INCLUDED
|
||||
|
||||
/*
|
||||
* This code has some adaptations for the Ghostscript environment, but it
|
||||
* will compile and run correctly in any environment with 8-bit chars and
|
||||
* 32-bit ints. Specifically, it assumes that if the following are
|
||||
* defined, they have the same meaning as in Ghostscript: P1, P2, P3,
|
||||
* ARCH_IS_BIG_ENDIAN.
|
||||
*/
|
||||
|
||||
typedef unsigned char md5_byte_t; /* 8-bit byte */
|
||||
typedef unsigned int md5_word_t; /* 32-bit word */
|
||||
|
||||
/* Define the state of the MD5 Algorithm. */
|
||||
typedef struct md5_state_s {
|
||||
md5_word_t count[2]; /* message length in bits, lsw first */
|
||||
md5_word_t abcd[4]; /* digest buffer */
|
||||
md5_byte_t buf[64]; /* accumulate block */
|
||||
} md5_state_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Initialize the algorithm. */
|
||||
#ifdef P1
|
||||
void md5_init(P1(md5_state_t *pms));
|
||||
#else
|
||||
void md5_init(md5_state_t *pms);
|
||||
#endif
|
||||
|
||||
/* Append a string to the message. */
|
||||
#ifdef P3
|
||||
void md5_append(P3(md5_state_t *pms, const md5_byte_t *data,
|
||||
int nbytes));
|
||||
#else
|
||||
void md5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes);
|
||||
#endif
|
||||
|
||||
/* Finish the message and return the digest. */
|
||||
#ifdef P2
|
||||
void md5_finish(P2(md5_state_t *pms, md5_byte_t digest[16]));
|
||||
#else
|
||||
void md5_finish(md5_state_t *pms, md5_byte_t digest[16]);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* end extern "C" */
|
||||
#endif
|
||||
#endif /* md5_INCLUDED */
|
|
@ -1,613 +0,0 @@
|
|||
/*-
|
||||
* Copyright (c) 2001-2003 Allan Saddi <allan@saddi.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ALLAN SADDI AND HIS CONTRIBUTORS ``AS IS''
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL ALLAN SADDI OR HIS CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Define WORDS_BIGENDIAN if compiling on a big-endian architecture.
|
||||
*
|
||||
* Define SHA1_TEST to test the implementation using the NIST's
|
||||
* sample messages. The output should be:
|
||||
*
|
||||
* a9993e36 4706816a ba3e2571 7850c26c 9cd0d89d
|
||||
* 84983e44 1c3bd26e baae4aa1 f95129e5 e54670f1
|
||||
* 34aa973c d4c4daa4 f61eeb2b dbad2731 6534016f
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif /* HAVE_CONFIG_H */
|
||||
|
||||
#if HAVE_INTTYPES_H
|
||||
# include <inttypes.h>
|
||||
#else
|
||||
# if HAVE_STDINT_H
|
||||
# include <stdint.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "sha1.h"
|
||||
|
||||
#define ROTL(x, n) (((x) << (n)) | ((x) >> (32 - (n))))
|
||||
#define ROTR(x, n) (((x) >> (n)) | ((x) << (32 - (n))))
|
||||
|
||||
#define F_0_19(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
|
||||
#define F_20_39(x, y, z) ((x) ^ (y) ^ (z))
|
||||
#define F_40_59(x, y, z) (((x) & ((y) | (z))) | ((y) & (z)))
|
||||
#define F_60_79(x, y, z) ((x) ^ (y) ^ (z))
|
||||
|
||||
#define DO_ROUND(F, K) { \
|
||||
temp = ROTL(a, 5) + F(b, c, d) + e + *(W++) + K; \
|
||||
e = d; \
|
||||
d = c; \
|
||||
c = ROTL(b, 30); \
|
||||
b = a; \
|
||||
a = temp; \
|
||||
}
|
||||
|
||||
#define K_0_19 0x5a827999L
|
||||
#define K_20_39 0x6ed9eba1L
|
||||
#define K_40_59 0x8f1bbcdcL
|
||||
#define K_60_79 0xca62c1d6L
|
||||
|
||||
#ifndef RUNTIME_ENDIAN
|
||||
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
|
||||
#define BYTESWAP(x) (x)
|
||||
#define BYTESWAP64(x) (x)
|
||||
|
||||
#else /* WORDS_BIGENDIAN */
|
||||
|
||||
#define BYTESWAP(x) ((ROTR((x), 8) & 0xff00ff00L) | (ROTL((x), 8) & 0x00ff00ffL))
|
||||
|
||||
static uint64_t _byteswap64(uint64_t x)
|
||||
{
|
||||
uint32_t a = x >> 32;
|
||||
uint32_t b = (uint32_t) x;
|
||||
return ((uint64_t) BYTESWAP(b) << 32) | (uint64_t) BYTESWAP(a);
|
||||
}
|
||||
|
||||
#define BYTESWAP64(x) _byteswap64(x)
|
||||
|
||||
#endif /* WORDS_BIGENDIAN */
|
||||
|
||||
#else /* !RUNTIME_ENDIAN */
|
||||
|
||||
#define BYTESWAP(x) _byteswap(sc->littleEndian, x)
|
||||
#define BYTESWAP64(x) _byteswap64(sc->littleEndian, x)
|
||||
|
||||
#define _BYTESWAP(x) ((ROTR((x), 8) & 0xff00ff00L) | \
|
||||
(ROTL((x), 8) & 0x00ff00ffL))
|
||||
#define _BYTESWAP64(x) __byteswap64(x)
|
||||
|
||||
static uint64_t __byteswap64(uint64_t x)
|
||||
{
|
||||
uint32_t a = x >> 32;
|
||||
uint32_t b = (uint32_t) x;
|
||||
return ((uint64_t) _BYTESWAP(b) << 32) | (uint64_t) _BYTESWAP(a);
|
||||
}
|
||||
|
||||
static uint32_t _byteswap(int littleEndian, uint32_t x)
|
||||
{
|
||||
if (!littleEndian)
|
||||
return x;
|
||||
else
|
||||
return _BYTESWAP(x);
|
||||
}
|
||||
|
||||
static uint64_t _byteswap64(int littleEndian, uint64_t x)
|
||||
{
|
||||
if (!littleEndian)
|
||||
return x;
|
||||
else
|
||||
return _BYTESWAP64(x);
|
||||
}
|
||||
|
||||
static void setEndian(int *littleEndianp)
|
||||
{
|
||||
union {
|
||||
uint32_t w;
|
||||
uint8_t b[4];
|
||||
} endian;
|
||||
|
||||
endian.w = 1L;
|
||||
*littleEndianp = endian.b[0] != 0;
|
||||
}
|
||||
|
||||
#endif /* !RUNTIME_ENDIAN */
|
||||
|
||||
static const uint8_t padding[64] = {
|
||||
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
void SHA1Init(SHA1Context *sc)
|
||||
{
|
||||
#ifdef RUNTIME_ENDIAN
|
||||
setEndian(&sc->littleEndian);
|
||||
#endif /* RUNTIME_ENDIAN */
|
||||
|
||||
sc->totalLength = 0LL;
|
||||
sc->hash[0] = 0x67452301L;
|
||||
sc->hash[1] = 0xefcdab89L;
|
||||
sc->hash[2] = 0x98badcfeL;
|
||||
sc->hash[3] = 0x10325476L;
|
||||
sc->hash[4] = 0xc3d2e1f0L;
|
||||
sc->bufferLength = 0L;
|
||||
}
|
||||
|
||||
static void burnStack(int size)
|
||||
{
|
||||
char buf[128];
|
||||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
size -= sizeof(buf);
|
||||
if (size > 0)
|
||||
burnStack(size);
|
||||
}
|
||||
|
||||
static void SHA1Guts(SHA1Context *sc, const uint32_t *cbuf)
|
||||
{
|
||||
uint32_t buf[80];
|
||||
uint32_t *W, *W3, *W8, *W14, *W16;
|
||||
uint32_t a, b, c, d, e, temp;
|
||||
int i;
|
||||
|
||||
W = buf;
|
||||
|
||||
for (i = 15; i >= 0; i--) {
|
||||
*(W++) = BYTESWAP(*cbuf);
|
||||
cbuf++;
|
||||
}
|
||||
|
||||
W16 = &buf[0];
|
||||
W14 = &buf[2];
|
||||
W8 = &buf[8];
|
||||
W3 = &buf[13];
|
||||
|
||||
for (i = 63; i >= 0; i--) {
|
||||
*W = *(W3++) ^ *(W8++) ^ *(W14++) ^ *(W16++);
|
||||
*W = ROTL(*W, 1);
|
||||
W++;
|
||||
}
|
||||
|
||||
a = sc->hash[0];
|
||||
b = sc->hash[1];
|
||||
c = sc->hash[2];
|
||||
d = sc->hash[3];
|
||||
e = sc->hash[4];
|
||||
|
||||
W = buf;
|
||||
|
||||
#ifndef SHA1_UNROLL
|
||||
#define SHA1_UNROLL 20
|
||||
#endif /* !SHA1_UNROLL */
|
||||
|
||||
#if SHA1_UNROLL == 1
|
||||
for (i = 19; i >= 0; i--)
|
||||
DO_ROUND(F_0_19, K_0_19);
|
||||
|
||||
for (i = 19; i >= 0; i--)
|
||||
DO_ROUND(F_20_39, K_20_39);
|
||||
|
||||
for (i = 19; i >= 0; i--)
|
||||
DO_ROUND(F_40_59, K_40_59);
|
||||
|
||||
for (i = 19; i >= 0; i--)
|
||||
DO_ROUND(F_60_79, K_60_79);
|
||||
#elif SHA1_UNROLL == 2
|
||||
for (i = 9; i >= 0; i--) {
|
||||
DO_ROUND(F_0_19, K_0_19);
|
||||
DO_ROUND(F_0_19, K_0_19);
|
||||
}
|
||||
|
||||
for (i = 9; i >= 0; i--) {
|
||||
DO_ROUND(F_20_39, K_20_39);
|
||||
DO_ROUND(F_20_39, K_20_39);
|
||||
}
|
||||
|
||||
for (i = 9; i >= 0; i--) {
|
||||
DO_ROUND(F_40_59, K_40_59);
|
||||
DO_ROUND(F_40_59, K_40_59);
|
||||
}
|
||||
|
||||
for (i = 9; i >= 0; i--) {
|
||||
DO_ROUND(F_60_79, K_60_79);
|
||||
DO_ROUND(F_60_79, K_60_79);
|
||||
}
|
||||
#elif SHA1_UNROLL == 4
|
||||
for (i = 4; i >= 0; i--) {
|
||||
DO_ROUND(F_0_19, K_0_19);
|
||||
DO_ROUND(F_0_19, K_0_19);
|
||||
DO_ROUND(F_0_19, K_0_19);
|
||||
DO_ROUND(F_0_19, K_0_19);
|
||||
}
|
||||
|
||||
for (i = 4; i >= 0; i--) {
|
||||
DO_ROUND(F_20_39, K_20_39);
|
||||
DO_ROUND(F_20_39, K_20_39);
|
||||
DO_ROUND(F_20_39, K_20_39);
|
||||
DO_ROUND(F_20_39, K_20_39);
|
||||
}
|
||||
|
||||
for (i = 4; i >= 0; i--) {
|
||||
DO_ROUND(F_40_59, K_40_59);
|
||||
DO_ROUND(F_40_59, K_40_59);
|
||||
DO_ROUND(F_40_59, K_40_59);
|
||||
DO_ROUND(F_40_59, K_40_59);
|
||||
}
|
||||
|
||||
for (i = 4; i >= 0; i--) {
|
||||
DO_ROUND(F_60_79, K_60_79);
|
||||
DO_ROUND(F_60_79, K_60_79);
|
||||
DO_ROUND(F_60_79, K_60_79);
|
||||
DO_ROUND(F_60_79, K_60_79);
|
||||
}
|
||||
#elif SHA1_UNROLL == 5
|
||||
for (i = 3; i >= 0; i--) {
|
||||
DO_ROUND(F_0_19, K_0_19);
|
||||
DO_ROUND(F_0_19, K_0_19);
|
||||
DO_ROUND(F_0_19, K_0_19);
|
||||
DO_ROUND(F_0_19, K_0_19);
|
||||
DO_ROUND(F_0_19, K_0_19);
|
||||
}
|
||||
|
||||
for (i = 3; i >= 0; i--) {
|
||||
DO_ROUND(F_20_39, K_20_39);
|
||||
DO_ROUND(F_20_39, K_20_39);
|
||||
DO_ROUND(F_20_39, K_20_39);
|
||||
DO_ROUND(F_20_39, K_20_39);
|
||||
DO_ROUND(F_20_39, K_20_39);
|
||||
}
|
||||
|
||||
for (i = 3; i >= 0; i--) {
|
||||
DO_ROUND(F_40_59, K_40_59);
|
||||
DO_ROUND(F_40_59, K_40_59);
|
||||
DO_ROUND(F_40_59, K_40_59);
|
||||
DO_ROUND(F_40_59, K_40_59);
|
||||
DO_ROUND(F_40_59, K_40_59);
|
||||
}
|
||||
|
||||
for (i = 3; i >= 0; i--) {
|
||||
DO_ROUND(F_60_79, K_60_79);
|
||||
DO_ROUND(F_60_79, K_60_79);
|
||||
DO_ROUND(F_60_79, K_60_79);
|
||||
DO_ROUND(F_60_79, K_60_79);
|
||||
DO_ROUND(F_60_79, K_60_79);
|
||||
}
|
||||
#elif SHA1_UNROLL == 10
|
||||
for (i = 1; i >= 0; i--) {
|
||||
DO_ROUND(F_0_19, K_0_19);
|
||||
DO_ROUND(F_0_19, K_0_19);
|
||||
DO_ROUND(F_0_19, K_0_19);
|
||||
DO_ROUND(F_0_19, K_0_19);
|
||||
DO_ROUND(F_0_19, K_0_19);
|
||||
DO_ROUND(F_0_19, K_0_19);
|
||||
DO_ROUND(F_0_19, K_0_19);
|
||||
DO_ROUND(F_0_19, K_0_19);
|
||||
DO_ROUND(F_0_19, K_0_19);
|
||||
DO_ROUND(F_0_19, K_0_19);
|
||||
}
|
||||
|
||||
for (i = 1; i >= 0; i--) {
|
||||
DO_ROUND(F_20_39, K_20_39);
|
||||
DO_ROUND(F_20_39, K_20_39);
|
||||
DO_ROUND(F_20_39, K_20_39);
|
||||
DO_ROUND(F_20_39, K_20_39);
|
||||
DO_ROUND(F_20_39, K_20_39);
|
||||
DO_ROUND(F_20_39, K_20_39);
|
||||
DO_ROUND(F_20_39, K_20_39);
|
||||
DO_ROUND(F_20_39, K_20_39);
|
||||
DO_ROUND(F_20_39, K_20_39);
|
||||
DO_ROUND(F_20_39, K_20_39);
|
||||
}
|
||||
|
||||
for (i = 1; i >= 0; i--) {
|
||||
DO_ROUND(F_40_59, K_40_59);
|
||||
DO_ROUND(F_40_59, K_40_59);
|
||||
DO_ROUND(F_40_59, K_40_59);
|
||||
DO_ROUND(F_40_59, K_40_59);
|
||||
DO_ROUND(F_40_59, K_40_59);
|
||||
DO_ROUND(F_40_59, K_40_59);
|
||||
DO_ROUND(F_40_59, K_40_59);
|
||||
DO_ROUND(F_40_59, K_40_59);
|
||||
DO_ROUND(F_40_59, K_40_59);
|
||||
DO_ROUND(F_40_59, K_40_59);
|
||||
}
|
||||
|
||||
for (i = 1; i >= 0; i--) {
|
||||
DO_ROUND(F_60_79, K_60_79);
|
||||
DO_ROUND(F_60_79, K_60_79);
|
||||
DO_ROUND(F_60_79, K_60_79);
|
||||
DO_ROUND(F_60_79, K_60_79);
|
||||
DO_ROUND(F_60_79, K_60_79);
|
||||
DO_ROUND(F_60_79, K_60_79);
|
||||
DO_ROUND(F_60_79, K_60_79);
|
||||
DO_ROUND(F_60_79, K_60_79);
|
||||
DO_ROUND(F_60_79, K_60_79);
|
||||
DO_ROUND(F_60_79, K_60_79);
|
||||
}
|
||||
#elif SHA1_UNROLL == 20
|
||||
DO_ROUND(F_0_19, K_0_19);
|
||||
DO_ROUND(F_0_19, K_0_19);
|
||||
DO_ROUND(F_0_19, K_0_19);
|
||||
DO_ROUND(F_0_19, K_0_19);
|
||||
DO_ROUND(F_0_19, K_0_19);
|
||||
DO_ROUND(F_0_19, K_0_19);
|
||||
DO_ROUND(F_0_19, K_0_19);
|
||||
DO_ROUND(F_0_19, K_0_19);
|
||||
DO_ROUND(F_0_19, K_0_19);
|
||||
DO_ROUND(F_0_19, K_0_19);
|
||||
DO_ROUND(F_0_19, K_0_19);
|
||||
DO_ROUND(F_0_19, K_0_19);
|
||||
DO_ROUND(F_0_19, K_0_19);
|
||||
DO_ROUND(F_0_19, K_0_19);
|
||||
DO_ROUND(F_0_19, K_0_19);
|
||||
DO_ROUND(F_0_19, K_0_19);
|
||||
DO_ROUND(F_0_19, K_0_19);
|
||||
DO_ROUND(F_0_19, K_0_19);
|
||||
DO_ROUND(F_0_19, K_0_19);
|
||||
DO_ROUND(F_0_19, K_0_19);
|
||||
|
||||
DO_ROUND(F_20_39, K_20_39);
|
||||
DO_ROUND(F_20_39, K_20_39);
|
||||
DO_ROUND(F_20_39, K_20_39);
|
||||
DO_ROUND(F_20_39, K_20_39);
|
||||
DO_ROUND(F_20_39, K_20_39);
|
||||
DO_ROUND(F_20_39, K_20_39);
|
||||
DO_ROUND(F_20_39, K_20_39);
|
||||
DO_ROUND(F_20_39, K_20_39);
|
||||
DO_ROUND(F_20_39, K_20_39);
|
||||
DO_ROUND(F_20_39, K_20_39);
|
||||
DO_ROUND(F_20_39, K_20_39);
|
||||
DO_ROUND(F_20_39, K_20_39);
|
||||
DO_ROUND(F_20_39, K_20_39);
|
||||
DO_ROUND(F_20_39, K_20_39);
|
||||
DO_ROUND(F_20_39, K_20_39);
|
||||
DO_ROUND(F_20_39, K_20_39);
|
||||
DO_ROUND(F_20_39, K_20_39);
|
||||
DO_ROUND(F_20_39, K_20_39);
|
||||
DO_ROUND(F_20_39, K_20_39);
|
||||
DO_ROUND(F_20_39, K_20_39);
|
||||
|
||||
DO_ROUND(F_40_59, K_40_59);
|
||||
DO_ROUND(F_40_59, K_40_59);
|
||||
DO_ROUND(F_40_59, K_40_59);
|
||||
DO_ROUND(F_40_59, K_40_59);
|
||||
DO_ROUND(F_40_59, K_40_59);
|
||||
DO_ROUND(F_40_59, K_40_59);
|
||||
DO_ROUND(F_40_59, K_40_59);
|
||||
DO_ROUND(F_40_59, K_40_59);
|
||||
DO_ROUND(F_40_59, K_40_59);
|
||||
DO_ROUND(F_40_59, K_40_59);
|
||||
DO_ROUND(F_40_59, K_40_59);
|
||||
DO_ROUND(F_40_59, K_40_59);
|
||||
DO_ROUND(F_40_59, K_40_59);
|
||||
DO_ROUND(F_40_59, K_40_59);
|
||||
DO_ROUND(F_40_59, K_40_59);
|
||||
DO_ROUND(F_40_59, K_40_59);
|
||||
DO_ROUND(F_40_59, K_40_59);
|
||||
DO_ROUND(F_40_59, K_40_59);
|
||||
DO_ROUND(F_40_59, K_40_59);
|
||||
DO_ROUND(F_40_59, K_40_59);
|
||||
|
||||
DO_ROUND(F_60_79, K_60_79);
|
||||
DO_ROUND(F_60_79, K_60_79);
|
||||
DO_ROUND(F_60_79, K_60_79);
|
||||
DO_ROUND(F_60_79, K_60_79);
|
||||
DO_ROUND(F_60_79, K_60_79);
|
||||
DO_ROUND(F_60_79, K_60_79);
|
||||
DO_ROUND(F_60_79, K_60_79);
|
||||
DO_ROUND(F_60_79, K_60_79);
|
||||
DO_ROUND(F_60_79, K_60_79);
|
||||
DO_ROUND(F_60_79, K_60_79);
|
||||
DO_ROUND(F_60_79, K_60_79);
|
||||
DO_ROUND(F_60_79, K_60_79);
|
||||
DO_ROUND(F_60_79, K_60_79);
|
||||
DO_ROUND(F_60_79, K_60_79);
|
||||
DO_ROUND(F_60_79, K_60_79);
|
||||
DO_ROUND(F_60_79, K_60_79);
|
||||
DO_ROUND(F_60_79, K_60_79);
|
||||
DO_ROUND(F_60_79, K_60_79);
|
||||
DO_ROUND(F_60_79, K_60_79);
|
||||
DO_ROUND(F_60_79, K_60_79);
|
||||
#else /* SHA1_UNROLL */
|
||||
#error SHA1_UNROLL must be 1, 2, 4, 5, 10 or 20!
|
||||
#endif
|
||||
|
||||
sc->hash[0] += a;
|
||||
sc->hash[1] += b;
|
||||
sc->hash[2] += c;
|
||||
sc->hash[3] += d;
|
||||
sc->hash[4] += e;
|
||||
}
|
||||
|
||||
void SHA1Update(SHA1Context *sc, const void *vdata, uint32_t len)
|
||||
{
|
||||
const uint8_t *data = vdata;
|
||||
uint32_t bufferBytesLeft;
|
||||
uint32_t bytesToCopy;
|
||||
int needBurn = 0;
|
||||
|
||||
#ifdef SHA1_FAST_COPY
|
||||
if (sc->bufferLength) {
|
||||
bufferBytesLeft = 64L - sc->bufferLength;
|
||||
|
||||
bytesToCopy = bufferBytesLeft;
|
||||
if (bytesToCopy > len)
|
||||
bytesToCopy = len;
|
||||
|
||||
memcpy(&sc->buffer.bytes[sc->bufferLength], data, bytesToCopy);
|
||||
|
||||
sc->totalLength += bytesToCopy * 8L;
|
||||
|
||||
sc->bufferLength += bytesToCopy;
|
||||
data += bytesToCopy;
|
||||
len -= bytesToCopy;
|
||||
|
||||
if (sc->bufferLength == 64L) {
|
||||
SHA1Guts(sc, sc->buffer.words);
|
||||
needBurn = 1;
|
||||
sc->bufferLength = 0L;
|
||||
}
|
||||
}
|
||||
|
||||
while (len > 63) {
|
||||
sc->totalLength += 512L;
|
||||
|
||||
SHA1Guts(sc, data);
|
||||
needBurn = 1;
|
||||
|
||||
data += 64L;
|
||||
len -= 64L;
|
||||
}
|
||||
|
||||
if (len) {
|
||||
memcpy(&sc->buffer.bytes[sc->bufferLength], data, len);
|
||||
|
||||
sc->totalLength += len * 8L;
|
||||
|
||||
sc->bufferLength += len;
|
||||
}
|
||||
#else /* SHA1_FAST_COPY */
|
||||
while (len) {
|
||||
bufferBytesLeft = 64L - sc->bufferLength;
|
||||
|
||||
bytesToCopy = bufferBytesLeft;
|
||||
if (bytesToCopy > len)
|
||||
bytesToCopy = len;
|
||||
|
||||
memcpy(&sc->buffer.bytes[sc->bufferLength], data, bytesToCopy);
|
||||
|
||||
sc->totalLength += bytesToCopy * 8L;
|
||||
|
||||
sc->bufferLength += bytesToCopy;
|
||||
data += bytesToCopy;
|
||||
len -= bytesToCopy;
|
||||
|
||||
if (sc->bufferLength == 64L) {
|
||||
SHA1Guts(sc, sc->buffer.words);
|
||||
needBurn = 1;
|
||||
sc->bufferLength = 0L;
|
||||
}
|
||||
}
|
||||
#endif /* SHA1_FAST_COPY */
|
||||
|
||||
if (needBurn)
|
||||
burnStack(sizeof(uint32_t[86]) + sizeof(uint32_t *[5]) +
|
||||
sizeof(int));
|
||||
}
|
||||
|
||||
void SHA1Final(SHA1Context *sc, uint8_t hash[SHA1_HASH_SIZE])
|
||||
{
|
||||
uint32_t bytesToPad;
|
||||
uint64_t lengthPad;
|
||||
int i;
|
||||
|
||||
bytesToPad = 120L - sc->bufferLength;
|
||||
if (bytesToPad > 64L)
|
||||
bytesToPad -= 64L;
|
||||
|
||||
lengthPad = BYTESWAP64(sc->totalLength);
|
||||
|
||||
SHA1Update(sc, padding, bytesToPad);
|
||||
SHA1Update(sc, &lengthPad, 8L);
|
||||
|
||||
if (hash) {
|
||||
for (i = 0; i < SHA1_HASH_WORDS; i++) {
|
||||
#ifdef SHA1_FAST_COPY
|
||||
*((uint32_t *)hash) = BYTESWAP(sc->hash[i]);
|
||||
#else /* SHA1_FAST_COPY */
|
||||
hash[0] = (uint8_t) (sc->hash[i] >> 24);
|
||||
hash[1] = (uint8_t) (sc->hash[i] >> 16);
|
||||
hash[2] = (uint8_t) (sc->hash[i] >> 8);
|
||||
hash[3] = (uint8_t) sc->hash[i];
|
||||
#endif /* SHA1_FAST_COPY */
|
||||
hash += 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef SHA1_TEST
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
SHA1Context foo;
|
||||
uint8_t hash[SHA1_HASH_SIZE];
|
||||
char buf[1000];
|
||||
int i;
|
||||
|
||||
SHA1Init(&foo);
|
||||
SHA1Update(&foo, "abc", 3);
|
||||
SHA1Final(&foo, hash);
|
||||
|
||||
for (i = 0; i < SHA1_HASH_SIZE;) {
|
||||
printf("%02x", hash[i++]);
|
||||
if (!(i % 4))
|
||||
printf(" ");
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
SHA1Init(&foo);
|
||||
SHA1Update(&foo,
|
||||
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 56);
|
||||
SHA1Final(&foo, hash);
|
||||
|
||||
for (i = 0; i < SHA1_HASH_SIZE;) {
|
||||
printf("%02x", hash[i++]);
|
||||
if (!(i % 4))
|
||||
printf(" ");
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
SHA1Init(&foo);
|
||||
memset(buf, 'a', sizeof(buf));
|
||||
for (i = 0; i < 1000; i++)
|
||||
SHA1Update(&foo, buf, sizeof(buf));
|
||||
SHA1Final(&foo, hash);
|
||||
|
||||
for (i = 0; i < SHA1_HASH_SIZE;) {
|
||||
printf("%02x", hash[i++]);
|
||||
if (!(i % 4))
|
||||
printf(" ");
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
#endif /* SHA1_TEST */
|
|
@ -1,69 +0,0 @@
|
|||
/*-
|
||||
* Copyright (c) 2001-2003 Allan Saddi <allan@saddi.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ALLAN SADDI AND HIS CONTRIBUTORS ``AS IS''
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL ALLAN SADDI OR HIS CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _SHA1_H
|
||||
#define _SHA1_H
|
||||
|
||||
#if HAVE_INTTYPES_H
|
||||
# include <inttypes.h>
|
||||
#else
|
||||
# if HAVE_STDINT_H
|
||||
# include <stdint.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#define SHA1_HASH_SIZE 20
|
||||
|
||||
/* Hash size in 32-bit words */
|
||||
#define SHA1_HASH_WORDS 5
|
||||
|
||||
struct _SHA1Context {
|
||||
uint64_t totalLength;
|
||||
uint32_t hash[SHA1_HASH_WORDS];
|
||||
uint32_t bufferLength;
|
||||
union {
|
||||
uint32_t words[16];
|
||||
uint8_t bytes[64];
|
||||
} buffer;
|
||||
#ifdef RUNTIME_ENDIAN
|
||||
int littleEndian;
|
||||
#endif /* RUNTIME_ENDIAN */
|
||||
};
|
||||
|
||||
typedef struct _SHA1Context SHA1Context;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void SHA1Init(SHA1Context *sc);
|
||||
void SHA1Update(SHA1Context *sc, const void *data, uint32_t len);
|
||||
void SHA1Final(SHA1Context *sc, uint8_t hash[SHA1_HASH_SIZE]);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* _SHA1_H */
|
|
@ -1,225 +0,0 @@
|
|||
/*
|
||||
* libyahoo2: yahoo2.h
|
||||
*
|
||||
* Copyright (C) 2002-2004, Philip S Tellis <philip.tellis AT gmx.net>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef YAHOO2_H
|
||||
#define YAHOO2_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "yahoo2_types.h"
|
||||
|
||||
/* returns the socket descriptor object for a given pager connection. shouldn't be needed */
|
||||
void *yahoo_get_fd(int id);
|
||||
|
||||
/* says how much logging to do */
|
||||
/* see yahoo2_types.h for the different values */
|
||||
int yahoo_set_log_level(enum yahoo_log_level level);
|
||||
enum yahoo_log_level yahoo_get_log_level(void);
|
||||
|
||||
/* these functions should be self explanatory */
|
||||
/* who always means the buddy you're acting on */
|
||||
/* id is the successful value returned by yahoo_init */
|
||||
|
||||
/* init returns a connection id used to identify the connection hereon */
|
||||
/* or 0 on failure */
|
||||
/* you must call init before calling any other function */
|
||||
/*
|
||||
* The optional parameters to init are key/value pairs that specify
|
||||
* server settings to use. This list must be NULL terminated - even
|
||||
* if the list is empty. If a parameter isn't set, a default value
|
||||
* will be used. Parameter keys are strings, parameter values are
|
||||
* either strings or ints, depending on the key. Values passed in
|
||||
* are copied, so you can use const/auto/static/pointers/whatever
|
||||
* you want. Parameters are:
|
||||
* NAME TYPE DEFAULT
|
||||
* pager_host char * scs.msg.yahoo.com
|
||||
* pager_port int 5050
|
||||
* filetransfer_host char * filetransfer.msg.yahoo.com
|
||||
* filetransfer_port int 80
|
||||
* webcam_host char * webcam.yahoo.com
|
||||
* webcam_port int 5100
|
||||
* webcam_description char * ""
|
||||
* local_host char * ""
|
||||
* conn_type int Y_WCM_DSL
|
||||
*
|
||||
* You should set at least local_host if you intend to use webcams
|
||||
*/
|
||||
int yahoo_init_with_attributes(const char *username,
|
||||
const char *password, ...);
|
||||
|
||||
/* yahoo_init does the same as yahoo_init_with_attributes, assuming defaults
|
||||
* for all attributes */
|
||||
int yahoo_init(const char *username, const char *password);
|
||||
|
||||
/* release all resources held by this session */
|
||||
/* you need to call yahoo_close for a session only if
|
||||
* yahoo_logoff is never called for it (ie, it was never logged in) */
|
||||
void yahoo_close(int id);
|
||||
/* login logs in to the server */
|
||||
/* initial is of type enum yahoo_status. see yahoo2_types.h */
|
||||
void yahoo_login(int id, int initial);
|
||||
void yahoo_logoff(int id);
|
||||
/* reloads status of all buddies */
|
||||
void yahoo_refresh(int id);
|
||||
/* activates/deactivates an identity */
|
||||
void yahoo_set_identity_status(int id, const char *identity,
|
||||
int active);
|
||||
/* regets the entire buddy list from the server */
|
||||
void yahoo_get_list(int id);
|
||||
/* download buddy contact information from your yahoo addressbook */
|
||||
void yahoo_get_yab(int id);
|
||||
/* add/modify an address book entry. if yab->dbid is set, it will */
|
||||
/* modify that entry else it creates a new entry */
|
||||
void yahoo_set_yab(int id, struct yab *yab);
|
||||
void yahoo_keepalive(int id);
|
||||
void yahoo_chat_keepalive(int id);
|
||||
|
||||
/* from is the identity you're sending from. if NULL, the default is used */
|
||||
/* utf8 is whether msg is a utf8 string or not. */
|
||||
void yahoo_send_im(int id, const char *from, const char *who,
|
||||
const char *msg, int utf8, int picture);
|
||||
void yahoo_send_buzz(int id, const char *from, const char *who);
|
||||
/* if type is true, send typing notice, else send stopped typing notice */
|
||||
void yahoo_send_typing(int id, const char *from, const char *who,
|
||||
int typ);
|
||||
|
||||
/* used to set away/back status. */
|
||||
/* away says whether the custom message is an away message or a sig */
|
||||
void yahoo_set_away(int id, enum yahoo_status state, const char *msg,
|
||||
int away);
|
||||
|
||||
void yahoo_add_buddy(int id, const char *who, const char *group,
|
||||
const char *msg);
|
||||
void yahoo_remove_buddy(int id, const char *who, const char *group);
|
||||
void yahoo_confirm_buddy(int id, const char *who, int reject,
|
||||
const char *msg);
|
||||
void yahoo_stealth_buddy(int id, const char *who, int unstealth);
|
||||
/* if unignore is true, unignore, else ignore */
|
||||
void yahoo_ignore_buddy(int id, const char *who, int unignore);
|
||||
void yahoo_change_buddy_group(int id, const char *who,
|
||||
const char *old_group, const char *new_group);
|
||||
void yahoo_group_rename(int id, const char *old_group,
|
||||
const char *new_group);
|
||||
|
||||
void yahoo_conference_invite(int id, const char *from, YList *who,
|
||||
const char *room, const char *msg);
|
||||
void yahoo_conference_addinvite(int id, const char *from,
|
||||
const char *who, const char *room, const YList *members,
|
||||
const char *msg);
|
||||
void yahoo_conference_decline(int id, const char *from, YList *who,
|
||||
const char *room, const char *msg);
|
||||
void yahoo_conference_message(int id, const char *from, YList *who,
|
||||
const char *room, const char *msg, int utf8);
|
||||
void yahoo_conference_logon(int id, const char *from, YList *who,
|
||||
const char *room);
|
||||
void yahoo_conference_logoff(int id, const char *from, YList *who,
|
||||
const char *room);
|
||||
|
||||
/* Get a list of chatrooms */
|
||||
void yahoo_get_chatrooms(int id, int chatroomid);
|
||||
/* join room with specified roomname and roomid */
|
||||
void yahoo_chat_logon(int id, const char *from, const char *room,
|
||||
const char *roomid);
|
||||
/* Send message "msg" to room with specified roomname, msgtype is 1-normal message or 2-/me mesage */
|
||||
void yahoo_chat_message(int id, const char *from, const char *room,
|
||||
const char *msg, const int msgtype, const int utf8);
|
||||
/* Log off chat */
|
||||
void yahoo_chat_logoff(int id, const char *from);
|
||||
|
||||
/* requests a webcam feed */
|
||||
/* who is the person who's webcam you would like to view */
|
||||
/* if who is null, then you're the broadcaster */
|
||||
void yahoo_webcam_get_feed(int id, const char *who);
|
||||
void yahoo_webcam_close_feed(int id, const char *who);
|
||||
|
||||
/* sends an image when uploading */
|
||||
/* image points to a JPEG-2000 image, length is the length of the image */
|
||||
/* in bytes. The timestamp is the time in milliseconds since we started the */
|
||||
/* webcam. */
|
||||
void yahoo_webcam_send_image(int id, unsigned char *image,
|
||||
unsigned int length, unsigned int timestamp);
|
||||
|
||||
/* this function should be called if we want to allow a user to watch the */
|
||||
/* webcam. Who is the user we want to accept. */
|
||||
/* Accept user (accept = 1), decline user (accept = 0) */
|
||||
void yahoo_webcam_accept_viewer(int id, const char *who, int accept);
|
||||
|
||||
/* send an invitation to a user to view your webcam */
|
||||
void yahoo_webcam_invite(int id, const char *who);
|
||||
|
||||
/* will set up a connection and initiate file transfer.
|
||||
* callback will be called with the fd that you should write
|
||||
* the file data to
|
||||
*/
|
||||
void yahoo_send_file(int id, const char *who, const char *msg,
|
||||
const char *name, unsigned long size,
|
||||
yahoo_get_fd_callback callback, void *data);
|
||||
|
||||
/*
|
||||
* Respond to a file transfer request. Be sure to provide the callback data
|
||||
* since that is your only chance to recognize future callbacks
|
||||
*/
|
||||
void yahoo_send_file_transfer_response(int client_id, int response,
|
||||
char *id, void *data);
|
||||
|
||||
|
||||
/* send a search request
|
||||
*/
|
||||
void yahoo_search(int id, enum yahoo_search_type t, const char *text,
|
||||
enum yahoo_search_gender g, enum yahoo_search_agerange ar,
|
||||
int photo, int yahoo_only);
|
||||
|
||||
/* continue last search
|
||||
* should be called if only (start+found >= total)
|
||||
*
|
||||
* where the above three are passed to ext_yahoo_got_search_result
|
||||
*/
|
||||
void yahoo_search_again(int id, int start);
|
||||
|
||||
/* these should be called when input is available on a fd */
|
||||
/* registered by ext_yahoo_add_handler */
|
||||
/* if these return negative values, errno may be set */
|
||||
int yahoo_read_ready(int id, void *fd, void *data);
|
||||
int yahoo_write_ready(int id, void *fd, void *data);
|
||||
|
||||
/* utility functions. these do not hit the server */
|
||||
enum yahoo_status yahoo_current_status(int id);
|
||||
const YList *yahoo_get_buddylist(int id);
|
||||
const YList *yahoo_get_ignorelist(int id);
|
||||
const YList *yahoo_get_identities(int id);
|
||||
/* 'which' could be y, t, c or login. This may change in later versions. */
|
||||
const char *yahoo_get_cookie(int id, const char *which);
|
||||
|
||||
/* returns the url used to get user profiles - you must append the user id */
|
||||
/* as of now this is http://profiles.yahoo.com/ */
|
||||
/* You'll have to do urlencoding yourself, but see yahoo_httplib.h first */
|
||||
const char *yahoo_get_profile_url(void);
|
||||
|
||||
void yahoo_buddyicon_request(int id, const char *who);
|
||||
|
||||
#include "yahoo_httplib.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
|
@ -1,776 +0,0 @@
|
|||
/*
|
||||
* libyahoo2: yahoo2_callbacks.h
|
||||
*
|
||||
* Copyright (C) 2002-2004, Philip S Tellis <philip.tellis AT gmx.net>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* The functions in this file *must* be defined in your client program
|
||||
* If you want to use a callback structure instead of direct functions,
|
||||
* then you must define USE_STRUCT_CALLBACKS in all files that #include
|
||||
* this one.
|
||||
*
|
||||
* Register the callback structure by calling yahoo_register_callbacks -
|
||||
* declared in this file and defined in libyahoo2.c
|
||||
*/
|
||||
|
||||
#ifndef YAHOO2_CALLBACKS_H
|
||||
#define YAHOO2_CALLBACKS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "yahoo2_types.h"
|
||||
|
||||
/*
|
||||
* yahoo2_callbacks.h
|
||||
*
|
||||
* Callback interface for libyahoo2
|
||||
*/
|
||||
|
||||
typedef enum {
|
||||
YAHOO_INPUT_READ = 1 << 0,
|
||||
YAHOO_INPUT_WRITE = 1 << 1,
|
||||
YAHOO_INPUT_EXCEPTION = 1 << 2
|
||||
} yahoo_input_condition;
|
||||
|
||||
/*
|
||||
* A callback function called when an asynchronous connect completes.
|
||||
*
|
||||
* Params:
|
||||
* fd - The file descriptor object that has been connected, or NULL on
|
||||
* error
|
||||
* error - The value of errno set by the call to connect or 0 if no error
|
||||
* Set both fd and error to 0 if the connect was cancelled by the
|
||||
* user
|
||||
* callback_data - the callback_data passed to the ext_yahoo_connect_async
|
||||
* function
|
||||
*/
|
||||
typedef void (*yahoo_connect_callback) (void *fd, int error,
|
||||
void *callback_data);
|
||||
|
||||
/*
|
||||
* The following functions need to be implemented in the client
|
||||
* interface. They will be called by the library when each
|
||||
* event occurs.
|
||||
*/
|
||||
|
||||
/*
|
||||
* should we use a callback structure or directly call functions
|
||||
* if you want the structure, you *must* define USE_STRUCT_CALLBACKS
|
||||
* both when you compile the library, and when you compile your code
|
||||
* that uses the library
|
||||
*/
|
||||
|
||||
#define YAHOO_CALLBACK_TYPE(x) (*x)
|
||||
struct yahoo_callbacks {
|
||||
|
||||
/*
|
||||
* Name: ext_yahoo_login_response
|
||||
* Called when the login process is complete
|
||||
* Params:
|
||||
* id - the id that identifies the server connection
|
||||
* succ - enum yahoo_login_status
|
||||
* url - url to reactivate account if locked
|
||||
*/
|
||||
void YAHOO_CALLBACK_TYPE(ext_yahoo_login_response) (int id, int succ,
|
||||
const char *url);
|
||||
|
||||
/*
|
||||
* Name: ext_yahoo_got_buddies
|
||||
* Called when the contact list is got from the server
|
||||
* Params:
|
||||
* id - the id that identifies the server connection
|
||||
* buds - the buddy list
|
||||
*/
|
||||
void YAHOO_CALLBACK_TYPE(ext_yahoo_got_buddies) (int id, YList *buds);
|
||||
|
||||
/*
|
||||
* Name: ext_yahoo_got_ignore
|
||||
* Called when the ignore list is got from the server
|
||||
* Params:
|
||||
* id - the id that identifies the server connection
|
||||
* igns - the ignore list
|
||||
*/
|
||||
void YAHOO_CALLBACK_TYPE(ext_yahoo_got_ignore) (int id, YList *igns);
|
||||
|
||||
/*
|
||||
* Name: ext_yahoo_got_identities
|
||||
* Called when the contact list is got from the server
|
||||
* Params:
|
||||
* id - the id that identifies the server connection
|
||||
* ids - the identity list
|
||||
*/
|
||||
void YAHOO_CALLBACK_TYPE(ext_yahoo_got_identities) (int id, YList *ids);
|
||||
|
||||
/*
|
||||
* Name: ext_yahoo_got_cookies
|
||||
* Called when the cookie list is got from the server
|
||||
* Params:
|
||||
* id - the id that identifies the server connection
|
||||
*/
|
||||
void YAHOO_CALLBACK_TYPE(ext_yahoo_got_cookies) (int id);
|
||||
|
||||
/*
|
||||
* Name: ext_yahoo_got_ping
|
||||
* Called when the ping packet is received from the server
|
||||
* Params:
|
||||
* id - the id that identifies the server connection
|
||||
* errormsg - optional error message
|
||||
*/
|
||||
void YAHOO_CALLBACK_TYPE(ext_yahoo_got_ping) (int id,
|
||||
const char *errormsg);
|
||||
|
||||
/*
|
||||
* Name: ext_yahoo_status_changed
|
||||
* Called when remote user's status changes.
|
||||
* Params:
|
||||
* id - the id that identifies the server connection
|
||||
* who - the handle of the remote user
|
||||
* stat - status code (enum yahoo_status)
|
||||
* msg - the message if stat == YAHOO_STATUS_CUSTOM
|
||||
* away - whether the contact is away or not (YAHOO_STATUS_CUSTOM)
|
||||
* idle - this is the number of seconds he is idle [if he is idle]
|
||||
* mobile - this is set for mobile users/buddies
|
||||
* TODO: add support for pager, chat, and game states
|
||||
*/
|
||||
void YAHOO_CALLBACK_TYPE(ext_yahoo_status_changed) (int id,
|
||||
const char *who, int stat, const char *msg, int away, int idle,
|
||||
int mobile);
|
||||
|
||||
/*
|
||||
* Name: ext_yahoo_got_buzz
|
||||
* Called when remote user sends you a buzz.
|
||||
* Params:
|
||||
* id - the id that identifies the server connection
|
||||
* me - the identity the message was sent to
|
||||
* who - the handle of the remote user
|
||||
* tm - timestamp of message if offline
|
||||
*/
|
||||
void YAHOO_CALLBACK_TYPE(ext_yahoo_got_buzz) (int id, const char *me,
|
||||
const char *who, long tm);
|
||||
|
||||
/*
|
||||
* Name: ext_yahoo_got_im
|
||||
* Called when remote user sends you a message.
|
||||
* Params:
|
||||
* id - the id that identifies the server connection
|
||||
* me - the identity the message was sent to
|
||||
* who - the handle of the remote user
|
||||
* msg - the message - NULL if stat == 2
|
||||
* tm - timestamp of message if offline
|
||||
* stat - message status - 0
|
||||
* 1
|
||||
* 2 == error sending message
|
||||
* 5
|
||||
* utf8 - whether the message is encoded as utf8 or not
|
||||
*/
|
||||
void YAHOO_CALLBACK_TYPE(ext_yahoo_got_im) (int id, const char *me,
|
||||
const char *who, const char *msg, long tm, int stat, int utf8);
|
||||
|
||||
/*
|
||||
* Name: ext_yahoo_got_conf_invite
|
||||
* Called when remote user sends you a conference invitation.
|
||||
* Params:
|
||||
* id - the id that identifies the server connection
|
||||
* me - the identity the invitation was sent to
|
||||
* who - the user inviting you
|
||||
* room - the room to join
|
||||
* msg - the message
|
||||
* members - the initial members of the conference (null terminated list)
|
||||
*/
|
||||
void YAHOO_CALLBACK_TYPE(ext_yahoo_got_conf_invite) (int id,
|
||||
const char *me, const char *who, const char *room,
|
||||
const char *msg, YList *members);
|
||||
|
||||
/*
|
||||
* Name: ext_yahoo_conf_userdecline
|
||||
* Called when someone declines to join the conference.
|
||||
* Params:
|
||||
* id - the id that identifies the server connection
|
||||
* me - the identity in the conference
|
||||
* who - the user who has declined
|
||||
* room - the room
|
||||
* msg - the declining message
|
||||
*/
|
||||
void YAHOO_CALLBACK_TYPE(ext_yahoo_conf_userdecline) (int id,
|
||||
const char *me, const char *who, const char *room,
|
||||
const char *msg);
|
||||
|
||||
/*
|
||||
* Name: ext_yahoo_conf_userjoin
|
||||
* Called when someone joins the conference.
|
||||
* Params:
|
||||
* id - the id that identifies the server connection
|
||||
* me - the identity in the conference
|
||||
* who - the user who has joined
|
||||
* room - the room joined
|
||||
*/
|
||||
void YAHOO_CALLBACK_TYPE(ext_yahoo_conf_userjoin) (int id,
|
||||
const char *me, const char *who, const char *room);
|
||||
|
||||
/*
|
||||
* Name: ext_yahoo_conf_userleave
|
||||
* Called when someone leaves the conference.
|
||||
* Params:
|
||||
* id - the id that identifies the server connection
|
||||
* me - the identity in the conference
|
||||
* who - the user who has left
|
||||
* room - the room left
|
||||
*/
|
||||
void YAHOO_CALLBACK_TYPE(ext_yahoo_conf_userleave) (int id,
|
||||
const char *me, const char *who, const char *room);
|
||||
|
||||
/*
|
||||
* Name: ext_yahoo_chat_cat_xml
|
||||
* Called when ?
|
||||
* Params:
|
||||
* id - the id that identifies the server connection
|
||||
* xml - ?
|
||||
*/
|
||||
void YAHOO_CALLBACK_TYPE(ext_yahoo_chat_cat_xml) (int id,
|
||||
const char *xml);
|
||||
|
||||
/*
|
||||
* Name: ext_yahoo_chat_join
|
||||
* Called when joining the chatroom.
|
||||
* Params:
|
||||
* id - the id that identifies the server connection
|
||||
* me - the identity in the chatroom
|
||||
* room - the room joined, used in all other chat calls, freed by
|
||||
* library after call
|
||||
* topic - the topic of the room, freed by library after call
|
||||
* members - the initial members of the chatroom (null terminated YList
|
||||
* of yahoo_chat_member's) Must be freed by the client
|
||||
* fd - the object where the connection is coming from (for tracking)
|
||||
*/
|
||||
void YAHOO_CALLBACK_TYPE(ext_yahoo_chat_join) (int id, const char *me,
|
||||
const char *room, const char *topic, YList *members, void *fd);
|
||||
|
||||
/*
|
||||
* Name: ext_yahoo_chat_userjoin
|
||||
* Called when someone joins the chatroom.
|
||||
* Params:
|
||||
* id - the id that identifies the server connection
|
||||
* me - the identity in the chatroom
|
||||
* room - the room joined
|
||||
* who - the user who has joined, Must be freed by the client
|
||||
*/
|
||||
void YAHOO_CALLBACK_TYPE(ext_yahoo_chat_userjoin) (int id,
|
||||
const char *me, const char *room,
|
||||
struct yahoo_chat_member *who);
|
||||
|
||||
/*
|
||||
* Name: ext_yahoo_chat_userleave
|
||||
* Called when someone leaves the chatroom.
|
||||
* Params:
|
||||
* id - the id that identifies the server connection
|
||||
* me - the identity in the chatroom
|
||||
* room - the room left
|
||||
* who - the user who has left (Just the User ID)
|
||||
*/
|
||||
void YAHOO_CALLBACK_TYPE(ext_yahoo_chat_userleave) (int id,
|
||||
const char *me, const char *room, const char *who);
|
||||
|
||||
/*
|
||||
* Name: ext_yahoo_chat_message
|
||||
* Called when someone messages in the chatroom.
|
||||
* Params:
|
||||
* id - the id that identifies the server connection
|
||||
* me - the identity in the chatroom
|
||||
* room - the room
|
||||
* who - the user who messaged (Just the user id)
|
||||
* msg - the message
|
||||
* msgtype - 1 = Normal message
|
||||
* 2 = /me type message
|
||||
* utf8 - whether the message is utf8 encoded or not
|
||||
*/
|
||||
void YAHOO_CALLBACK_TYPE(ext_yahoo_chat_message) (int id,
|
||||
const char *me, const char *who, const char *room,
|
||||
const char *msg, int msgtype, int utf8);
|
||||
|
||||
/*
|
||||
*
|
||||
* Name: ext_yahoo_chat_yahoologout
|
||||
* called when yahoo disconnects your chat session
|
||||
* Note this is called whenver a disconnect happens, client or server
|
||||
* requested. Care should be taken to make sure you know the origin
|
||||
* of the disconnect request before doing anything here (auto-join's etc)
|
||||
* Params:
|
||||
* id - the id that identifies this connection
|
||||
* me - the identity in the chatroom
|
||||
* Returns:
|
||||
* nothing.
|
||||
*/
|
||||
void YAHOO_CALLBACK_TYPE(ext_yahoo_chat_yahoologout) (int id,
|
||||
const char *me);
|
||||
|
||||
/*
|
||||
*
|
||||
* Name: ext_yahoo_chat_yahooerror
|
||||
* called when yahoo sends back an error to you
|
||||
* Note this is called whenver chat message is sent into a room
|
||||
* in error (fd not connected, room doesn't exists etc)
|
||||
* Care should be taken to make sure you know the origin
|
||||
* of the error before doing anything about it.
|
||||
* Params:
|
||||
* id - the id that identifies this connection
|
||||
* me - the identity in the chatroom
|
||||
* Returns:
|
||||
* nothing.
|
||||
*/
|
||||
void YAHOO_CALLBACK_TYPE(ext_yahoo_chat_yahooerror) (int id,
|
||||
const char *me);
|
||||
|
||||
/*
|
||||
* Name: ext_yahoo_conf_message
|
||||
* Called when someone messages in the conference.
|
||||
* Params:
|
||||
* id - the id that identifies the server connection
|
||||
* me - the identity the conf message was sent to
|
||||
* who - the user who messaged
|
||||
* room - the room
|
||||
* msg - the message
|
||||
* utf8 - whether the message is utf8 encoded or not
|
||||
*/
|
||||
void YAHOO_CALLBACK_TYPE(ext_yahoo_conf_message) (int id,
|
||||
const char *me, const char *who, const char *room,
|
||||
const char *msg, int utf8);
|
||||
|
||||
/*
|
||||
* Name: ext_yahoo_got_file
|
||||
* Called when someone sends you a file
|
||||
* Params:
|
||||
* id - the id that identifies the server connection
|
||||
* me - the identity the file was sent to
|
||||
* who - the user who sent the file
|
||||
* msg - the message
|
||||
* fname- the file name if direct transfer
|
||||
* fsize- the file size if direct transfer
|
||||
* trid - transfer id. Unique for this transfer
|
||||
*
|
||||
* NOTE: Subsequent callbacks for file transfer do not send all of this
|
||||
* information again since it is wasteful. Implementations are expected to
|
||||
* save this information and supply it as callback data when the file or
|
||||
* confirmation is sent
|
||||
*/
|
||||
void YAHOO_CALLBACK_TYPE(ext_yahoo_got_file) (int id, const char *me,
|
||||
const char *who, const char *msg, const char *fname,
|
||||
unsigned long fesize, char *trid);
|
||||
|
||||
/*
|
||||
* Name: ext_yahoo_got_ft_data
|
||||
* Called multiple times when parts of the file are received
|
||||
* Params:
|
||||
* id - the id that identifies the server connection
|
||||
* in - The data
|
||||
* len - Length of the data
|
||||
* data - callback data
|
||||
*/
|
||||
void YAHOO_CALLBACK_TYPE(ext_yahoo_got_ft_data) (int id,
|
||||
const unsigned char *in, int len, void *data);
|
||||
|
||||
/*
|
||||
* Name: ext_yahoo_file_transfer_done
|
||||
* File transfer is done
|
||||
* Params:
|
||||
* id - the id that identifies the server connection
|
||||
* result - To notify if it finished successfully or with a failure
|
||||
* data - callback data
|
||||
*/
|
||||
void YAHOO_CALLBACK_TYPE(ext_yahoo_file_transfer_done) (int id,
|
||||
int result, void *data);
|
||||
|
||||
/*
|
||||
* Name: ext_yahoo_contact_added
|
||||
* Called when a contact is added to your list
|
||||
* Params:
|
||||
* id - the id that identifies the server connection
|
||||
* myid - the identity he was added to
|
||||
* who - who was added
|
||||
* msg - any message sent
|
||||
*/
|
||||
void YAHOO_CALLBACK_TYPE(ext_yahoo_contact_added) (int id,
|
||||
const char *myid, const char *who, const char *msg);
|
||||
|
||||
/*
|
||||
* Name: ext_yahoo_rejected
|
||||
* Called when a contact rejects your add
|
||||
* Params:
|
||||
* id - the id that identifies the server connection
|
||||
* who - who rejected you
|
||||
* msg - any message sent
|
||||
*/
|
||||
void YAHOO_CALLBACK_TYPE(ext_yahoo_rejected) (int id, const char *who,
|
||||
const char *msg);
|
||||
|
||||
/*
|
||||
* Name: ext_yahoo_typing_notify
|
||||
* Called when remote user starts or stops typing.
|
||||
* Params:
|
||||
* id - the id that identifies the server connection
|
||||
* me - the handle of the identity the notification is sent to
|
||||
* who - the handle of the remote user
|
||||
* stat - 1 if typing, 0 if stopped typing
|
||||
*/
|
||||
void YAHOO_CALLBACK_TYPE(ext_yahoo_typing_notify) (int id,
|
||||
const char *me, const char *who, int stat);
|
||||
|
||||
/*
|
||||
* Name: ext_yahoo_game_notify
|
||||
* Called when remote user starts or stops a game.
|
||||
* Params:
|
||||
* id - the id that identifies the server connection
|
||||
* me - the handle of the identity the notification is sent to
|
||||
* who - the handle of the remote user
|
||||
* stat - 1 if game, 0 if stopped gaming
|
||||
* msg - game description and/or other text
|
||||
*/
|
||||
void YAHOO_CALLBACK_TYPE(ext_yahoo_game_notify) (int id, const char *me,
|
||||
const char *who, int stat, const char *msg);
|
||||
|
||||
/*
|
||||
* Name: ext_yahoo_mail_notify
|
||||
* Called when you receive mail, or with number of messages
|
||||
* Params:
|
||||
* id - the id that identifies the server connection
|
||||
* from - who the mail is from - NULL if only mail count
|
||||
* subj - the subject of the mail - NULL if only mail count
|
||||
* cnt - mail count - 0 if new mail notification
|
||||
*/
|
||||
void YAHOO_CALLBACK_TYPE(ext_yahoo_mail_notify) (int id,
|
||||
const char *from, const char *subj, int cnt);
|
||||
|
||||
/*
|
||||
* Name: ext_yahoo_system_message
|
||||
* System message
|
||||
* Params:
|
||||
* id - the id that identifies the server connection
|
||||
* me - the handle of the identity the notification is sent to
|
||||
* who - the source of the system message (there are different types)
|
||||
* msg - the message
|
||||
*/
|
||||
void YAHOO_CALLBACK_TYPE(ext_yahoo_system_message) (int id,
|
||||
const char *me, const char *who, const char *msg);
|
||||
|
||||
/*
|
||||
* Name: ext_yahoo_got_buddyicon
|
||||
* Buddy icon received
|
||||
* Params:
|
||||
* id - the id that identifies the server connection
|
||||
* me - the handle of the identity the notification is sent to
|
||||
* who - the person the buddy icon is for
|
||||
* url - the url to use to load the icon
|
||||
* checksum - the checksum of the icon content
|
||||
*/
|
||||
void YAHOO_CALLBACK_TYPE(ext_yahoo_got_buddyicon) (int id,
|
||||
const char *me, const char *who, const char *url, int checksum);
|
||||
|
||||
/*
|
||||
* Name: ext_yahoo_got_buddyicon_checksum
|
||||
* Buddy icon checksum received
|
||||
* Params:
|
||||
* id - the id that identifies the server connection
|
||||
* me - the handle of the identity the notification is sent to
|
||||
* who - the yahoo id of the buddy icon checksum is for
|
||||
* checksum - the checksum of the icon content
|
||||
*/
|
||||
void YAHOO_CALLBACK_TYPE(ext_yahoo_got_buddyicon_checksum) (int id,
|
||||
const char *me, const char *who, int checksum);
|
||||
|
||||
/*
|
||||
* Name: ext_yahoo_got_buddyicon_request
|
||||
* Buddy icon request received
|
||||
* Params:
|
||||
* id - the id that identifies the server connection
|
||||
* me - the handle of the identity the notification is sent to
|
||||
* who - the yahoo id of the buddy that requested the buddy icon
|
||||
*/
|
||||
void YAHOO_CALLBACK_TYPE(ext_yahoo_got_buddyicon_request) (int id,
|
||||
const char *me, const char *who);
|
||||
|
||||
/*
|
||||
* Name: ext_yahoo_got_buddyicon_request
|
||||
* Buddy icon request received
|
||||
* Params:
|
||||
* id - the id that identifies the server connection
|
||||
* url - remote url, the uploaded buddy icon can be fetched from
|
||||
*/
|
||||
void YAHOO_CALLBACK_TYPE(ext_yahoo_buddyicon_uploaded) (int id,
|
||||
const char *url);
|
||||
|
||||
/*
|
||||
* Name: ext_yahoo_got_webcam_image
|
||||
* Called when you get a webcam update
|
||||
* An update can either be receiving an image, a part of an image or
|
||||
* just an update with a timestamp
|
||||
* Params:
|
||||
* id - the id that identifies the server connection
|
||||
* who - the user who's webcam we're viewing
|
||||
* image - image data
|
||||
* image_size - length of the image in bytes
|
||||
* real_size - actual length of image data
|
||||
* timestamp - milliseconds since the webcam started
|
||||
*
|
||||
* If the real_size is smaller then the image_size then only part of
|
||||
* the image has been read. This function will keep being called till
|
||||
* the total amount of bytes in image_size has been read. The image
|
||||
* received is in JPEG-2000 Code Stream Syntax (ISO/IEC 15444-1).
|
||||
* The size of the image will be either 160x120 or 320x240.
|
||||
* Each webcam image contains a timestamp. This timestamp should be
|
||||
* used to keep the image in sync since some images can take longer
|
||||
* to transport then others. When image_size is 0 we can still receive
|
||||
* a timestamp to stay in sync
|
||||
*/
|
||||
void YAHOO_CALLBACK_TYPE(ext_yahoo_got_webcam_image) (int id,
|
||||
const char *who, const unsigned char *image,
|
||||
unsigned int image_size, unsigned int real_size,
|
||||
unsigned int timestamp);
|
||||
|
||||
/*
|
||||
* Name: ext_yahoo_webcam_invite
|
||||
* Called when you get a webcam invitation
|
||||
* Params:
|
||||
* id - the id that identifies the server connection
|
||||
* me - identity the invitation is to
|
||||
* from - who the invitation is from
|
||||
*/
|
||||
void YAHOO_CALLBACK_TYPE(ext_yahoo_webcam_invite) (int id,
|
||||
const char *me, const char *from);
|
||||
|
||||
/*
|
||||
* Name: ext_yahoo_webcam_invite_reply
|
||||
* Called when you get a response to a webcam invitation
|
||||
* Params:
|
||||
* id - the id that identifies the server connection
|
||||
* me - identity the invitation response is to
|
||||
* from - who the invitation response is from
|
||||
* accept - 0 (decline), 1 (accept)
|
||||
*/
|
||||
void YAHOO_CALLBACK_TYPE(ext_yahoo_webcam_invite_reply) (int id,
|
||||
const char *me, const char *from, int accept);
|
||||
|
||||
/*
|
||||
* Name: ext_yahoo_webcam_closed
|
||||
* Called when the webcam connection closed
|
||||
* Params:
|
||||
* id - the id that identifies the server connection
|
||||
* who - the user who we where connected to
|
||||
* reason - reason why the connection closed
|
||||
* 1 = user stopped broadcasting
|
||||
* 2 = user cancelled viewing permission
|
||||
* 3 = user declines permission
|
||||
* 4 = user does not have webcam online
|
||||
*/
|
||||
void YAHOO_CALLBACK_TYPE(ext_yahoo_webcam_closed) (int id,
|
||||
const char *who, int reason);
|
||||
|
||||
/*
|
||||
* Name: ext_yahoo_got_search_result
|
||||
* Called when the search result received from server
|
||||
* Params:
|
||||
* id - the id that identifies the server connection
|
||||
* found - total number of results returned in the current result set
|
||||
* start - offset from where the current result set starts
|
||||
* total - total number of results available (start + found <= total)
|
||||
* contacts - the list of results as a YList of yahoo_found_contact
|
||||
* these will be freed after this function returns, so
|
||||
* if you need to use the information, make a copy
|
||||
*/
|
||||
void YAHOO_CALLBACK_TYPE(ext_yahoo_got_search_result) (int id,
|
||||
int found, int start, int total, YList *contacts);
|
||||
|
||||
/*
|
||||
* Name: ext_yahoo_error
|
||||
* Called on error.
|
||||
* Params:
|
||||
* id - the id that identifies the server connection
|
||||
* err - the error message
|
||||
* fatal- whether this error is fatal to the connection or not
|
||||
* num - Which error is this
|
||||
*/
|
||||
void YAHOO_CALLBACK_TYPE(ext_yahoo_error) (int id, const char *err,
|
||||
int fatal, int num);
|
||||
|
||||
/*
|
||||
* Name: ext_yahoo_webcam_viewer
|
||||
* Called when a viewer disconnects/connects/requests to connect
|
||||
* Params:
|
||||
* id - the id that identifies the server connection
|
||||
* who - the viewer
|
||||
* connect - 0=disconnect 1=connect 2=request
|
||||
*/
|
||||
void YAHOO_CALLBACK_TYPE(ext_yahoo_webcam_viewer) (int id,
|
||||
const char *who, int connect);
|
||||
|
||||
/*
|
||||
* Name: ext_yahoo_webcam_data_request
|
||||
* Called when you get a request for webcam images
|
||||
* Params:
|
||||
* id - the id that identifies the server connection
|
||||
* send - whether to send images or not
|
||||
*/
|
||||
void YAHOO_CALLBACK_TYPE(ext_yahoo_webcam_data_request) (int id,
|
||||
int send);
|
||||
|
||||
/*
|
||||
* Name: ext_yahoo_log
|
||||
* Called to log a message.
|
||||
* Params:
|
||||
* fmt - the printf formatted message
|
||||
* Returns:
|
||||
* 0
|
||||
*/
|
||||
int YAHOO_CALLBACK_TYPE(ext_yahoo_log) (const char *fmt, ...);
|
||||
|
||||
/*
|
||||
* Name: ext_yahoo_add_handler
|
||||
* Add a listener for the fd. Must call yahoo_read_ready
|
||||
* when a YAHOO_INPUT_READ fd is ready and yahoo_write_ready
|
||||
* when a YAHOO_INPUT_WRITE fd is ready.
|
||||
* Params:
|
||||
* id - the id that identifies the server connection
|
||||
* fd - the fd object on which to listen
|
||||
* cond - the condition on which to call the callback
|
||||
* data - callback data to pass to yahoo_*_ready
|
||||
*
|
||||
* Returns: a tag to be used when removing the handler
|
||||
*/
|
||||
int YAHOO_CALLBACK_TYPE(ext_yahoo_add_handler) (int id, void *fd,
|
||||
yahoo_input_condition cond, void *data);
|
||||
|
||||
/*
|
||||
* Name: ext_yahoo_remove_handler
|
||||
* Remove the listener for the fd.
|
||||
* Params:
|
||||
* id - the id that identifies the connection
|
||||
* tag - the handler tag to remove
|
||||
*/
|
||||
void YAHOO_CALLBACK_TYPE(ext_yahoo_remove_handler) (int id, int tag);
|
||||
|
||||
/*
|
||||
* Name: ext_yahoo_connect
|
||||
* Connect to a host:port
|
||||
* Params:
|
||||
* host - the host to connect to
|
||||
* port - the port to connect on
|
||||
* Returns:
|
||||
* a unix file descriptor to the socket
|
||||
*/
|
||||
int YAHOO_CALLBACK_TYPE(ext_yahoo_connect) (const char *host, int port);
|
||||
|
||||
/*
|
||||
* Name: ext_yahoo_connect_async
|
||||
* Connect to a host:port asynchronously. This function should return
|
||||
* immediately returing a tag used to identify the connection handler,
|
||||
* or a pre-connect error (eg: host name lookup failure).
|
||||
* Once the connect completes (successfully or unsuccessfully), callback
|
||||
* should be called (see the signature for yahoo_connect_callback).
|
||||
* The callback may safely be called before this function returns, but
|
||||
* it should not be called twice.
|
||||
* Params:
|
||||
* id - the id that identifies this connection
|
||||
* host - the host to connect to
|
||||
* port - the port to connect on
|
||||
* callback - function to call when connect completes
|
||||
* callback_data - data to pass to the callback function
|
||||
* use_ssl - Whether we need an SSL connection
|
||||
* Returns:
|
||||
* a tag signifying the connection attempt
|
||||
*/
|
||||
int YAHOO_CALLBACK_TYPE(ext_yahoo_connect_async) (int id,
|
||||
const char *host, int port, yahoo_connect_callback callback,
|
||||
void *callback_data, int use_ssl);
|
||||
|
||||
/*
|
||||
* Name: ext_yahoo_get_ip_addr
|
||||
* get IP Address for a domain name
|
||||
* Params:
|
||||
* domain - Domain name
|
||||
* Returns:
|
||||
* Newly allocated string containing the IP Address in IPv4 notation
|
||||
*/
|
||||
char *YAHOO_CALLBACK_TYPE(ext_yahoo_get_ip_addr) (const char *domain);
|
||||
|
||||
/*
|
||||
* Name: ext_yahoo_write
|
||||
* Write data from the buffer into the socket for the specified connection
|
||||
* Params:
|
||||
* fd - the file descriptor object that identifies this connection
|
||||
* buf - Buffer to write the data from
|
||||
* len - Length of the data
|
||||
* Returns:
|
||||
* Number of bytes written or -1 for error
|
||||
*/
|
||||
int YAHOO_CALLBACK_TYPE(ext_yahoo_write) (void *fd, char *buf, int len);
|
||||
|
||||
/*
|
||||
* Name: ext_yahoo_read
|
||||
* Read data into a buffer from socket for the specified connection
|
||||
* Params:
|
||||
* fd - the file descriptor object that identifies this connection
|
||||
* buf - Buffer to read the data into
|
||||
* len - Max length to read
|
||||
* Returns:
|
||||
* Number of bytes read or -1 for error
|
||||
*/
|
||||
int YAHOO_CALLBACK_TYPE(ext_yahoo_read) (void *fd, char *buf, int len);
|
||||
|
||||
/*
|
||||
* Name: ext_yahoo_close
|
||||
* Close the file descriptor object and free its resources. Libyahoo2 will not
|
||||
* use this object again.
|
||||
* Params:
|
||||
* fd - the file descriptor object that identifies this connection
|
||||
* Returns:
|
||||
* Nothing
|
||||
*/
|
||||
void YAHOO_CALLBACK_TYPE(ext_yahoo_close) (void *fd);
|
||||
|
||||
/*
|
||||
* Name: ext_yahoo_got_buddy_change_group
|
||||
* Acknowledgement of buddy changing group
|
||||
* Params:
|
||||
* id: client id
|
||||
* me: The user
|
||||
* who: Buddy name
|
||||
* old_group: Old group name
|
||||
* new_group: New group name
|
||||
* Returns:
|
||||
* Nothing
|
||||
*/
|
||||
void YAHOO_CALLBACK_TYPE(ext_yahoo_got_buddy_change_group) (int id,
|
||||
const char *me, const char *who, const char *old_group,
|
||||
const char *new_group);
|
||||
|
||||
};
|
||||
|
||||
/*
|
||||
* if using a callback structure, call yahoo_register_callbacks
|
||||
* before doing anything else
|
||||
*/
|
||||
void yahoo_register_callbacks(struct yahoo_callbacks *tyc);
|
||||
|
||||
#undef YAHOO_CALLBACK_TYPE
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,396 +0,0 @@
|
|||
/*
|
||||
* libyahoo2: yahoo2_types.h
|
||||
*
|
||||
* Copyright (C) 2002-2004, Philip S Tellis <philip.tellis AT gmx.net>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef YAHOO2_TYPES_H
|
||||
#define YAHOO2_TYPES_H
|
||||
|
||||
#include "yahoo_list.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
enum yahoo_service { /* these are easier to see in hex */
|
||||
YAHOO_SERVICE_LOGON = 1,
|
||||
YAHOO_SERVICE_LOGOFF,
|
||||
YAHOO_SERVICE_ISAWAY,
|
||||
YAHOO_SERVICE_ISBACK,
|
||||
YAHOO_SERVICE_IDLE, /* 5 (placemarker) */
|
||||
YAHOO_SERVICE_MESSAGE,
|
||||
YAHOO_SERVICE_IDACT,
|
||||
YAHOO_SERVICE_IDDEACT,
|
||||
YAHOO_SERVICE_MAILSTAT,
|
||||
YAHOO_SERVICE_USERSTAT, /* 0xa */
|
||||
YAHOO_SERVICE_NEWMAIL,
|
||||
YAHOO_SERVICE_CHATINVITE,
|
||||
YAHOO_SERVICE_CALENDAR,
|
||||
YAHOO_SERVICE_NEWPERSONALMAIL,
|
||||
YAHOO_SERVICE_NEWCONTACT,
|
||||
YAHOO_SERVICE_ADDIDENT, /* 0x10 */
|
||||
YAHOO_SERVICE_ADDIGNORE,
|
||||
YAHOO_SERVICE_PING,
|
||||
YAHOO_SERVICE_GOTGROUPRENAME, /* < 1, 36(old), 37(new) */
|
||||
YAHOO_SERVICE_SYSMESSAGE = 0x14,
|
||||
YAHOO_SERVICE_SKINNAME = 0x15,
|
||||
YAHOO_SERVICE_PASSTHROUGH2 = 0x16,
|
||||
YAHOO_SERVICE_CONFINVITE = 0x18,
|
||||
YAHOO_SERVICE_CONFLOGON,
|
||||
YAHOO_SERVICE_CONFDECLINE,
|
||||
YAHOO_SERVICE_CONFLOGOFF,
|
||||
YAHOO_SERVICE_CONFADDINVITE,
|
||||
YAHOO_SERVICE_CONFMSG,
|
||||
YAHOO_SERVICE_CHATLOGON,
|
||||
YAHOO_SERVICE_CHATLOGOFF,
|
||||
YAHOO_SERVICE_CHATMSG = 0x20,
|
||||
YAHOO_SERVICE_GAMELOGON = 0x28,
|
||||
YAHOO_SERVICE_GAMELOGOFF,
|
||||
YAHOO_SERVICE_GAMEMSG = 0x2a,
|
||||
YAHOO_SERVICE_FILETRANSFER = 0x46,
|
||||
YAHOO_SERVICE_VOICECHAT = 0x4A,
|
||||
YAHOO_SERVICE_NOTIFY,
|
||||
YAHOO_SERVICE_VERIFY,
|
||||
YAHOO_SERVICE_P2PFILEXFER,
|
||||
YAHOO_SERVICE_PEERTOPEER = 0x4F, /* Checks if P2P possible */
|
||||
YAHOO_SERVICE_WEBCAM,
|
||||
YAHOO_SERVICE_AUTHRESP = 0x54,
|
||||
YAHOO_SERVICE_LIST,
|
||||
YAHOO_SERVICE_AUTH = 0x57,
|
||||
YAHOO_SERVICE_AUTHBUDDY = 0x6d,
|
||||
YAHOO_SERVICE_ADDBUDDY = 0x83,
|
||||
YAHOO_SERVICE_REMBUDDY,
|
||||
YAHOO_SERVICE_IGNORECONTACT, /* > 1, 7, 13 < 1, 66, 13, 0 */
|
||||
YAHOO_SERVICE_REJECTCONTACT,
|
||||
YAHOO_SERVICE_GROUPRENAME = 0x89, /* > 1, 65(new), 66(0), 67(old) */
|
||||
YAHOO_SERVICE_Y7_PING = 0x8A,
|
||||
YAHOO_SERVICE_CHATONLINE = 0x96, /* > 109(id), 1, 6(abcde) < 0,1 */
|
||||
YAHOO_SERVICE_CHATGOTO,
|
||||
YAHOO_SERVICE_CHATJOIN, /* > 1 104-room 129-1600326591 62-2 */
|
||||
YAHOO_SERVICE_CHATLEAVE,
|
||||
YAHOO_SERVICE_CHATEXIT = 0x9b,
|
||||
YAHOO_SERVICE_CHATADDINVITE = 0x9d,
|
||||
YAHOO_SERVICE_CHATLOGOUT = 0xa0,
|
||||
YAHOO_SERVICE_CHATPING,
|
||||
YAHOO_SERVICE_COMMENT = 0xa8,
|
||||
YAHOO_SERVICE_GAME_INVITE = 0xb7,
|
||||
YAHOO_SERVICE_STEALTH_PERM = 0xb9,
|
||||
YAHOO_SERVICE_STEALTH_SESSION = 0xba,
|
||||
YAHOO_SERVICE_AVATAR = 0xbc,
|
||||
YAHOO_SERVICE_PICTURE_CHECKSUM = 0xbd,
|
||||
YAHOO_SERVICE_PICTURE = 0xbe,
|
||||
YAHOO_SERVICE_PICTURE_UPDATE = 0xc1,
|
||||
YAHOO_SERVICE_PICTURE_UPLOAD = 0xc2,
|
||||
YAHOO_SERVICE_YAB_UPDATE = 0xc4,
|
||||
YAHOO_SERVICE_Y6_VISIBLE_TOGGLE = 0xc5, /* YMSG13, key 13: 2 = invisible, 1 = visible */
|
||||
YAHOO_SERVICE_Y6_STATUS_UPDATE = 0xc6, /* YMSG13 */
|
||||
YAHOO_SERVICE_PICTURE_STATUS = 0xc7, /* YMSG13, key 213: 0 = none, 1 = avatar, 2 = picture */
|
||||
YAHOO_SERVICE_VERIFY_ID_EXISTS = 0xc8,
|
||||
YAHOO_SERVICE_AUDIBLE = 0xd0,
|
||||
YAHOO_SERVICE_Y7_PHOTO_SHARING = 0xd2,
|
||||
YAHOO_SERVICE_Y7_CONTACT_DETAILS = 0xd3, /* YMSG13 */
|
||||
YAHOO_SERVICE_Y7_CHAT_SESSION = 0xd4,
|
||||
YAHOO_SERVICE_Y7_AUTHORIZATION = 0xd6, /* YMSG13 */
|
||||
YAHOO_SERVICE_Y7_FILETRANSFER = 0xdc, /* YMSG13 */
|
||||
YAHOO_SERVICE_Y7_FILETRANSFERINFO, /* YMSG13 */
|
||||
YAHOO_SERVICE_Y7_FILETRANSFERACCEPT, /* YMSG13 */
|
||||
YAHOO_SERVICE_Y7_MINGLE = 0xe1, /* YMSG13 */
|
||||
YAHOO_SERVICE_Y7_CHANGE_GROUP = 0xe7, /* YMSG13 */
|
||||
YAHOO_SERVICE_MYSTERY = 0xef, /* Don't know what this is for */
|
||||
YAHOO_SERVICE_Y8_STATUS = 0xf0, /* YMSG15 */
|
||||
YAHOO_SERVICE_Y8_LIST = 0Xf1, /* YMSG15 */
|
||||
YAHOO_SERVICE_MESSAGE_CONFIRM = 0xfb,
|
||||
YAHOO_SERVICE_WEBLOGIN = 0x0226,
|
||||
YAHOO_SERVICE_SMS_MSG = 0x02ea
|
||||
};
|
||||
|
||||
enum yahoo_status {
|
||||
YAHOO_STATUS_AVAILABLE = 0,
|
||||
YAHOO_STATUS_BRB,
|
||||
YAHOO_STATUS_BUSY,
|
||||
YAHOO_STATUS_NOTATHOME,
|
||||
YAHOO_STATUS_NOTATDESK,
|
||||
YAHOO_STATUS_NOTINOFFICE,
|
||||
YAHOO_STATUS_ONPHONE,
|
||||
YAHOO_STATUS_ONVACATION,
|
||||
YAHOO_STATUS_OUTTOLUNCH,
|
||||
YAHOO_STATUS_STEPPEDOUT,
|
||||
YAHOO_STATUS_INVISIBLE = 12,
|
||||
YAHOO_STATUS_CUSTOM = 99,
|
||||
YAHOO_STATUS_IDLE = 999,
|
||||
YAHOO_STATUS_OFFLINE = 0x5a55aa56 /* don't ask */
|
||||
};
|
||||
|
||||
enum ypacket_status {
|
||||
YPACKET_STATUS_DISCONNECTED = -1,
|
||||
YPACKET_STATUS_DEFAULT = 0,
|
||||
YPACKET_STATUS_SERVERACK = 1,
|
||||
YPACKET_STATUS_GAME = 0x2,
|
||||
YPACKET_STATUS_AWAY = 0x4,
|
||||
YPACKET_STATUS_CONTINUED = 0x5,
|
||||
YPACKET_STATUS_INVISIBLE = 12,
|
||||
YPACKET_STATUS_NOTIFY = 0x16, /* TYPING */
|
||||
YPACKET_STATUS_WEBLOGIN = 0x5a55aa55,
|
||||
YPACKET_STATUS_OFFLINE = 0x5a55aa56
|
||||
};
|
||||
|
||||
#define YAHOO_STATUS_GAME 0x2 /* Games don't fit into the regular status model */
|
||||
|
||||
enum yahoo_login_status {
|
||||
YAHOO_LOGIN_OK = 0,
|
||||
YAHOO_LOGIN_LOGOFF = 1,
|
||||
YAHOO_LOGIN_UNAME = 3,
|
||||
YAHOO_LOGIN_PASSWD = 13,
|
||||
YAHOO_LOGIN_LOCK = 14,
|
||||
YAHOO_LOGIN_DUPL = 99,
|
||||
YAHOO_LOGIN_SOCK = -1,
|
||||
YAHOO_LOGIN_UNKNOWN = 999
|
||||
};
|
||||
|
||||
enum yahoo_error {
|
||||
E_UNKNOWN = -1,
|
||||
E_CONNECTION = -2,
|
||||
E_SYSTEM = -3,
|
||||
E_CUSTOM = 0,
|
||||
|
||||
/* responses from ignore buddy */
|
||||
E_IGNOREDUP = 2,
|
||||
E_IGNORENONE = 3,
|
||||
E_IGNORECONF = 12,
|
||||
|
||||
/* conference */
|
||||
E_CONFNOTAVAIL = 20
|
||||
};
|
||||
|
||||
enum yahoo_log_level {
|
||||
YAHOO_LOG_NONE = 0,
|
||||
YAHOO_LOG_FATAL,
|
||||
YAHOO_LOG_ERR,
|
||||
YAHOO_LOG_WARNING,
|
||||
YAHOO_LOG_NOTICE,
|
||||
YAHOO_LOG_INFO,
|
||||
YAHOO_LOG_DEBUG
|
||||
};
|
||||
|
||||
enum yahoo_file_transfer {
|
||||
YAHOO_FILE_TRANSFER_INIT = 1,
|
||||
YAHOO_FILE_TRANSFER_ACCEPT = 3,
|
||||
YAHOO_FILE_TRANSFER_REJECT = 4,
|
||||
YAHOO_FILE_TRANSFER_DONE = 5,
|
||||
YAHOO_FILE_TRANSFER_RELAY,
|
||||
YAHOO_FILE_TRANSFER_FAILED,
|
||||
YAHOO_FILE_TRANSFER_UNKNOWN
|
||||
};
|
||||
|
||||
#define YAHOO_PROTO_VER 0x0010
|
||||
|
||||
/* Yahoo style/color directives */
|
||||
#define YAHOO_COLOR_BLACK "\033[30m"
|
||||
#define YAHOO_COLOR_BLUE "\033[31m"
|
||||
#define YAHOO_COLOR_LIGHTBLUE "\033[32m"
|
||||
#define YAHOO_COLOR_GRAY "\033[33m"
|
||||
#define YAHOO_COLOR_GREEN "\033[34m"
|
||||
#define YAHOO_COLOR_PINK "\033[35m"
|
||||
#define YAHOO_COLOR_PURPLE "\033[36m"
|
||||
#define YAHOO_COLOR_ORANGE "\033[37m"
|
||||
#define YAHOO_COLOR_RED "\033[38m"
|
||||
#define YAHOO_COLOR_OLIVE "\033[39m"
|
||||
#define YAHOO_COLOR_ANY "\033[#"
|
||||
#define YAHOO_STYLE_ITALICON "\033[2m"
|
||||
#define YAHOO_STYLE_ITALICOFF "\033[x2m"
|
||||
#define YAHOO_STYLE_BOLDON "\033[1m"
|
||||
#define YAHOO_STYLE_BOLDOFF "\033[x1m"
|
||||
#define YAHOO_STYLE_UNDERLINEON "\033[4m"
|
||||
#define YAHOO_STYLE_UNDERLINEOFF "\033[x4m"
|
||||
#define YAHOO_STYLE_URLON "\033[lm"
|
||||
#define YAHOO_STYLE_URLOFF "\033[xlm"
|
||||
|
||||
enum yahoo_connection_type {
|
||||
YAHOO_CONNECTION_PAGER = 0,
|
||||
YAHOO_CONNECTION_FT,
|
||||
YAHOO_CONNECTION_YAB,
|
||||
YAHOO_CONNECTION_WEBCAM_MASTER,
|
||||
YAHOO_CONNECTION_WEBCAM,
|
||||
YAHOO_CONNECTION_CHATCAT,
|
||||
YAHOO_CONNECTION_SEARCH,
|
||||
YAHOO_CONNECTION_AUTH
|
||||
};
|
||||
|
||||
enum yahoo_webcam_direction_type {
|
||||
YAHOO_WEBCAM_DOWNLOAD = 0,
|
||||
YAHOO_WEBCAM_UPLOAD
|
||||
};
|
||||
|
||||
enum yahoo_stealth_visibility_type {
|
||||
YAHOO_STEALTH_DEFAULT = 0,
|
||||
YAHOO_STEALTH_ONLINE,
|
||||
YAHOO_STEALTH_PERM_OFFLINE
|
||||
};
|
||||
|
||||
/* chat member attribs */
|
||||
#define YAHOO_CHAT_MALE 0x8000
|
||||
#define YAHOO_CHAT_FEMALE 0x10000
|
||||
#define YAHOO_CHAT_FEMALE 0x10000
|
||||
#define YAHOO_CHAT_DUNNO 0x400
|
||||
#define YAHOO_CHAT_WEBCAM 0x10
|
||||
|
||||
enum yahoo_webcam_conn_type { Y_WCM_DIALUP, Y_WCM_DSL, Y_WCM_T1 };
|
||||
|
||||
struct yahoo_webcam {
|
||||
int direction; /* Uploading or downloading */
|
||||
int conn_type; /* 0=Dialup, 1=DSL/Cable, 2=T1/Lan */
|
||||
|
||||
char *user; /* user we are viewing */
|
||||
char *server; /* webcam server to connect to */
|
||||
int port; /* webcam port to connect on */
|
||||
char *key; /* key to connect to the server with */
|
||||
char *description; /* webcam description */
|
||||
char *my_ip; /* own ip number */
|
||||
};
|
||||
|
||||
struct yahoo_webcam_data {
|
||||
unsigned int data_size;
|
||||
unsigned int to_read;
|
||||
unsigned int timestamp;
|
||||
unsigned char packet_type;
|
||||
};
|
||||
|
||||
struct yahoo_data {
|
||||
char *user;
|
||||
char *password;
|
||||
|
||||
char *cookie_y;
|
||||
char *cookie_t;
|
||||
char *cookie_c;
|
||||
char *cookie_b;
|
||||
char *login_cookie;
|
||||
char *crumb;
|
||||
char *seed;
|
||||
|
||||
YList *buddies;
|
||||
YList *ignore;
|
||||
YList *identities;
|
||||
char *login_id;
|
||||
|
||||
int current_status;
|
||||
int initial_status;
|
||||
int logged_in;
|
||||
|
||||
int session_id;
|
||||
|
||||
int client_id;
|
||||
|
||||
char *rawbuddylist;
|
||||
char *ignorelist;
|
||||
|
||||
void *server_settings;
|
||||
|
||||
struct yahoo_process_status_entry *half_user;
|
||||
};
|
||||
|
||||
struct yab {
|
||||
int yid;
|
||||
char *id;
|
||||
char *fname;
|
||||
char *lname;
|
||||
char *nname;
|
||||
char *email;
|
||||
char *hphone;
|
||||
char *wphone;
|
||||
char *mphone;
|
||||
int dbid;
|
||||
};
|
||||
|
||||
struct yahoo_buddy {
|
||||
char *group;
|
||||
char *id;
|
||||
char *real_name;
|
||||
struct yab *yab_entry;
|
||||
};
|
||||
|
||||
enum yahoo_search_type {
|
||||
YAHOO_SEARCH_KEYWORD = 0,
|
||||
YAHOO_SEARCH_YID,
|
||||
YAHOO_SEARCH_NAME
|
||||
};
|
||||
|
||||
enum yahoo_search_gender {
|
||||
YAHOO_GENDER_NONE = 0,
|
||||
YAHOO_GENDER_MALE,
|
||||
YAHOO_GENDER_FEMALE
|
||||
};
|
||||
|
||||
enum yahoo_search_agerange {
|
||||
YAHOO_AGERANGE_NONE = 0
|
||||
};
|
||||
|
||||
struct yahoo_found_contact {
|
||||
char *id;
|
||||
char *gender;
|
||||
char *location;
|
||||
int age;
|
||||
int online;
|
||||
};
|
||||
|
||||
/*
|
||||
* Function pointer to be passed to http get/post and send file
|
||||
*/
|
||||
typedef void (*yahoo_get_fd_callback) (int id, void *fd, int error,
|
||||
void *data);
|
||||
|
||||
/*
|
||||
* Function pointer to be passed to yahoo_get_url_handle
|
||||
*/
|
||||
typedef void (*yahoo_get_url_handle_callback) (int id, void *fd,
|
||||
int error, const char *filename, unsigned long size,
|
||||
void *data);
|
||||
|
||||
struct yahoo_chat_member {
|
||||
char *id;
|
||||
int age;
|
||||
int attribs;
|
||||
char *alias;
|
||||
char *location;
|
||||
};
|
||||
|
||||
struct yahoo_process_status_entry {
|
||||
char *name; /* 7 name */
|
||||
int state; /* 10 state */
|
||||
int flags; /* 13 flags, bit 0 = pager, bit 1 = chat, bit 2 = game */
|
||||
int mobile; /* 60 mobile */
|
||||
char *msg; /* 19 custom status message */
|
||||
int away; /* 47 away (or invisible) */
|
||||
int buddy_session; /* 11 state */
|
||||
int f17; /* 17 in chat? then what about flags? */
|
||||
int idle; /* 137 seconds idle */
|
||||
int f138; /* 138 state */
|
||||
char *f184; /* 184 state */
|
||||
int f192; /* 192 state */
|
||||
int f10001; /* 10001 state */
|
||||
int f10002; /* 10002 state */
|
||||
int f198; /* 198 state */
|
||||
char *f197; /* 197 state */
|
||||
char *f205; /* 205 state */
|
||||
int f213; /* 213 state */
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
|
@ -1,36 +0,0 @@
|
|||
/*
|
||||
* libyahoo2: yahoo_debug.h
|
||||
*
|
||||
* Copyright (C) 2002-2004, Philip S Tellis <philip.tellis AT gmx.net>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
extern int yahoo_log_message(char *fmt, ...);
|
||||
|
||||
#define NOTICE(x) if(yahoo_get_log_level() >= YAHOO_LOG_NOTICE) { yahoo_log_message x; yahoo_log_message("\n"); }
|
||||
|
||||
#define LOG(x) if(yahoo_get_log_level() >= YAHOO_LOG_INFO) { yahoo_log_message("%s:%d: ", __FILE__, __LINE__); \
|
||||
yahoo_log_message x; \
|
||||
yahoo_log_message("\n"); }
|
||||
|
||||
#define WARNING(x) if(yahoo_get_log_level() >= YAHOO_LOG_WARNING) { yahoo_log_message("%s:%d: warning: ", __FILE__, __LINE__); \
|
||||
yahoo_log_message x; \
|
||||
yahoo_log_message("\n"); }
|
||||
|
||||
#define DEBUG_MSG(x) if(yahoo_get_log_level() >= YAHOO_LOG_DEBUG) { yahoo_log_message("%s:%d: debug: ", __FILE__, __LINE__); \
|
||||
yahoo_log_message x; \
|
||||
yahoo_log_message("\n"); }
|
File diff suppressed because it is too large
Load diff
|
@ -1,32 +0,0 @@
|
|||
/*
|
||||
* libyahoo2 - originally from gaim patches by Amatus
|
||||
*
|
||||
* Copyright (C) 2003-2004
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#define IDENT 1 /* identify function */
|
||||
#define XOR 2 /* xor with arg1 */
|
||||
#define MULADD 3 /* multipy by arg1 then add arg2 */
|
||||
#define LOOKUP 4 /* lookup each byte in the table pointed to by arg1 */
|
||||
#define BITFLD 5 /* reorder bits according to table pointed to by arg1 */
|
||||
|
||||
struct yahoo_fn {
|
||||
int type;
|
||||
long arg1, arg2;
|
||||
};
|
||||
|
||||
int yahoo_xfrm(int table, int depth, int seed);
|
|
@ -1,404 +0,0 @@
|
|||
/*
|
||||
* libyahoo2: yahoo_httplib.c
|
||||
*
|
||||
* Copyright (C) 2002-2004, Philip S Tellis <philip.tellis AT gmx.net>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#if STDC_HEADERS
|
||||
# include <string.h>
|
||||
#else
|
||||
# if !HAVE_STRCHR
|
||||
# define strchr index
|
||||
# define strrchr rindex
|
||||
# endif
|
||||
char *strchr(), *strrchr();
|
||||
# if !HAVE_MEMCPY
|
||||
# define memcpy(d, s, n) bcopy ((s), (d), (n))
|
||||
# define memmove(d, s, n) bcopy ((s), (d), (n))
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <ctype.h>
|
||||
#include "yahoo2.h"
|
||||
#include "yahoo2_callbacks.h"
|
||||
#include "yahoo_httplib.h"
|
||||
#include "yahoo_util.h"
|
||||
|
||||
#include "yahoo_debug.h"
|
||||
#ifdef __MINGW32__
|
||||
# include <winsock2.h>
|
||||
# define snprintf _snprintf
|
||||
#endif
|
||||
|
||||
extern struct yahoo_callbacks *yc;
|
||||
#define YAHOO_CALLBACK(x) yc->x
|
||||
|
||||
extern enum yahoo_log_level log_level;
|
||||
|
||||
int yahoo_tcp_readline(char *ptr, int maxlen, void *fd)
|
||||
{
|
||||
int n, rc;
|
||||
char c;
|
||||
|
||||
for (n = 1; n < maxlen; n++) {
|
||||
|
||||
do {
|
||||
rc = YAHOO_CALLBACK(ext_yahoo_read) (fd, &c, 1);
|
||||
} while (rc == -1 && (errno == EINTR || errno == EAGAIN)); /* this is bad - it should be done asynchronously */
|
||||
|
||||
if (rc == 1) {
|
||||
if (c == '\r') /* get rid of \r */
|
||||
continue;
|
||||
*ptr = c;
|
||||
if (c == '\n')
|
||||
break;
|
||||
ptr++;
|
||||
} else if (rc == 0) {
|
||||
if (n == 1)
|
||||
return (0); /* EOF, no data */
|
||||
else
|
||||
break; /* EOF, w/ data */
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
*ptr = 0;
|
||||
return (n);
|
||||
}
|
||||
|
||||
static int url_to_host_port_path(const char *url,
|
||||
char *host, int *port, char *path, int *ssl)
|
||||
{
|
||||
char *urlcopy = NULL;
|
||||
char *slash = NULL;
|
||||
char *colon = NULL;
|
||||
|
||||
/*
|
||||
* http://hostname
|
||||
* http://hostname/
|
||||
* http://hostname/path
|
||||
* http://hostname/path:foo
|
||||
* http://hostname:port
|
||||
* http://hostname:port/
|
||||
* http://hostname:port/path
|
||||
* http://hostname:port/path:foo
|
||||
* and https:// variants of the above
|
||||
*/
|
||||
|
||||
if (strstr(url, "http://") == url) {
|
||||
urlcopy = strdup(url + 7);
|
||||
} else if (strstr(url, "https://") == url) {
|
||||
urlcopy = strdup(url + 8);
|
||||
*ssl = 1;
|
||||
} else {
|
||||
WARNING(("Weird url - unknown protocol: %s", url));
|
||||
return 0;
|
||||
}
|
||||
|
||||
slash = strchr(urlcopy, '/');
|
||||
colon = strchr(urlcopy, ':');
|
||||
|
||||
if (!colon || (slash && slash < colon)) {
|
||||
if (*ssl)
|
||||
*port = 443;
|
||||
else
|
||||
*port = 80;
|
||||
} else {
|
||||
*colon = 0;
|
||||
*port = atoi(colon + 1);
|
||||
}
|
||||
|
||||
if (!slash) {
|
||||
strcpy(path, "/");
|
||||
} else {
|
||||
strcpy(path, slash);
|
||||
*slash = 0;
|
||||
}
|
||||
|
||||
strcpy(host, urlcopy);
|
||||
|
||||
FREE(urlcopy);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int isurlchar(unsigned char c)
|
||||
{
|
||||
return (isalnum(c));
|
||||
}
|
||||
|
||||
char *yahoo_urlencode(const char *instr)
|
||||
{
|
||||
int ipos = 0, bpos = 0;
|
||||
char *str = NULL;
|
||||
int len = strlen(instr);
|
||||
|
||||
if (!(str = y_new(char, 3 *len + 1)))
|
||||
return "";
|
||||
|
||||
while (instr[ipos]) {
|
||||
while (isurlchar(instr[ipos]))
|
||||
str[bpos++] = instr[ipos++];
|
||||
if (!instr[ipos])
|
||||
break;
|
||||
|
||||
snprintf(&str[bpos], 4, "%%%02x", instr[ipos] & 0xff);
|
||||
bpos += 3;
|
||||
ipos++;
|
||||
}
|
||||
str[bpos] = '\0';
|
||||
|
||||
/* free extra alloc'ed mem. */
|
||||
len = strlen(str);
|
||||
str = y_renew(char, str, len + 1);
|
||||
|
||||
return (str);
|
||||
}
|
||||
|
||||
char *yahoo_urldecode(const char *instr)
|
||||
{
|
||||
int ipos = 0, bpos = 0;
|
||||
char *str = NULL;
|
||||
char entity[3] = { 0, 0, 0 };
|
||||
unsigned dec;
|
||||
int len = strlen(instr);
|
||||
|
||||
if (!(str = y_new(char, len + 1)))
|
||||
return "";
|
||||
|
||||
while (instr[ipos]) {
|
||||
while (instr[ipos] && instr[ipos] != '%')
|
||||
if (instr[ipos] == '+') {
|
||||
str[bpos++] = ' ';
|
||||
ipos++;
|
||||
} else
|
||||
str[bpos++] = instr[ipos++];
|
||||
if (!instr[ipos])
|
||||
break;
|
||||
|
||||
if (instr[ipos + 1] && instr[ipos + 2]) {
|
||||
ipos++;
|
||||
entity[0] = instr[ipos++];
|
||||
entity[1] = instr[ipos++];
|
||||
sscanf(entity, "%2x", &dec);
|
||||
str[bpos++] = (char)dec;
|
||||
} else {
|
||||
str[bpos++] = instr[ipos++];
|
||||
}
|
||||
}
|
||||
str[bpos] = '\0';
|
||||
|
||||
/* free extra alloc'ed mem. */
|
||||
len = strlen(str);
|
||||
str = y_renew(char, str, len + 1);
|
||||
|
||||
return (str);
|
||||
}
|
||||
|
||||
char *yahoo_xmldecode(const char *instr)
|
||||
{
|
||||
int ipos = 0, bpos = 0, epos = 0;
|
||||
char *str = NULL;
|
||||
char entity[4] = { 0, 0, 0, 0 };
|
||||
char *entitymap[5][2] = {
|
||||
{"amp;", "&"},
|
||||
{"quot;", "\""},
|
||||
{"lt;", "<"},
|
||||
{"gt;", "<"},
|
||||
{"nbsp;", " "}
|
||||
};
|
||||
unsigned dec;
|
||||
int len = strlen(instr);
|
||||
|
||||
if (!(str = y_new(char, len + 1)))
|
||||
return "";
|
||||
|
||||
while (instr[ipos]) {
|
||||
while (instr[ipos] && instr[ipos] != '&')
|
||||
if (instr[ipos] == '+') {
|
||||
str[bpos++] = ' ';
|
||||
ipos++;
|
||||
} else
|
||||
str[bpos++] = instr[ipos++];
|
||||
if (!instr[ipos] || !instr[ipos + 1])
|
||||
break;
|
||||
ipos++;
|
||||
|
||||
if (instr[ipos] == '#') {
|
||||
ipos++;
|
||||
epos = 0;
|
||||
while (instr[ipos] != ';')
|
||||
entity[epos++] = instr[ipos++];
|
||||
sscanf(entity, "%u", &dec);
|
||||
str[bpos++] = (char)dec;
|
||||
ipos++;
|
||||
} else {
|
||||
int i;
|
||||
for (i = 0; i < 5; i++)
|
||||
if (!strncmp(instr + ipos, entitymap[i][0],
|
||||
strlen(entitymap[i][0]))) {
|
||||
str[bpos++] = entitymap[i][1][0];
|
||||
ipos += strlen(entitymap[i][0]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
str[bpos] = '\0';
|
||||
|
||||
/* free extra alloc'ed mem. */
|
||||
len = strlen(str);
|
||||
str = y_renew(char, str, len + 1);
|
||||
|
||||
return (str);
|
||||
}
|
||||
|
||||
typedef void (*http_connected) (int id, void *fd, int error);
|
||||
|
||||
struct callback_data {
|
||||
int id;
|
||||
yahoo_get_fd_callback callback;
|
||||
char *request;
|
||||
void *user_data;
|
||||
};
|
||||
|
||||
static void connect_complete(void *fd, int error, void *data)
|
||||
{
|
||||
struct callback_data *ccd = data;
|
||||
if (error == 0)
|
||||
YAHOO_CALLBACK(ext_yahoo_write) (fd, ccd->request,
|
||||
strlen(ccd->request));
|
||||
free(ccd->request);
|
||||
ccd->callback(ccd->id, fd, error, ccd->user_data);
|
||||
FREE(ccd);
|
||||
}
|
||||
|
||||
static void yahoo_send_http_request(int id, char *host, int port, char *request,
|
||||
yahoo_get_fd_callback callback, void *data, int use_ssl)
|
||||
{
|
||||
struct callback_data *ccd = y_new0(struct callback_data, 1);
|
||||
ccd->callback = callback;
|
||||
ccd->id = id;
|
||||
ccd->request = strdup(request);
|
||||
ccd->user_data = data;
|
||||
|
||||
YAHOO_CALLBACK(ext_yahoo_connect_async) (id, host, port,
|
||||
connect_complete, ccd, use_ssl);
|
||||
}
|
||||
|
||||
void yahoo_http_post(int id, const char *url, const char *cookies,
|
||||
long content_length, yahoo_get_fd_callback callback, void *data)
|
||||
{
|
||||
char host[255];
|
||||
int port = 80;
|
||||
char path[255];
|
||||
char buff[1024];
|
||||
int ssl = 0;
|
||||
|
||||
if (!url_to_host_port_path(url, host, &port, path, &ssl))
|
||||
return;
|
||||
|
||||
/* thanks to kopete dumpcap */
|
||||
snprintf(buff, sizeof(buff),
|
||||
"POST %s HTTP/1.1\r\n"
|
||||
"Cookie: %s\r\n"
|
||||
"User-Agent: Mozilla/5.0\r\n"
|
||||
"Host: %s\r\n"
|
||||
"Content-Length: %ld\r\n"
|
||||
"Cache-Control: no-cache\r\n"
|
||||
"\r\n", path, cookies, host, content_length);
|
||||
|
||||
yahoo_send_http_request(id, host, port, buff, callback, data, ssl);
|
||||
}
|
||||
|
||||
void yahoo_http_get(int id, const char *url, const char *cookies, int http11,
|
||||
int keepalive, yahoo_get_fd_callback callback, void *data)
|
||||
{
|
||||
char host[255];
|
||||
int port = 80;
|
||||
char path[255];
|
||||
char buff[2048];
|
||||
char cookiebuff[1024];
|
||||
int ssl = 0;
|
||||
|
||||
if (!url_to_host_port_path(url, host, &port, path, &ssl))
|
||||
return;
|
||||
|
||||
/* Allow cases when we don't need to send a cookie */
|
||||
if (cookies)
|
||||
snprintf(cookiebuff, sizeof(cookiebuff), "Cookie: %s\r\n",
|
||||
cookies);
|
||||
else
|
||||
cookiebuff[0] = '\0';
|
||||
|
||||
snprintf(buff, sizeof(buff),
|
||||
"GET %s HTTP/1.%s\r\n"
|
||||
"%sHost: %s\r\n"
|
||||
"User-Agent: Mozilla/4.5 [en] (" "1" "/" "1" ")\r\n"
|
||||
"Accept: */*\r\n"
|
||||
"%s" "\r\n", path, http11?"1":"0", cookiebuff, host,
|
||||
keepalive? "Connection: Keep-Alive\r\n":"Connection: close\r\n");
|
||||
|
||||
yahoo_send_http_request(id, host, port, buff, callback, data, ssl);
|
||||
}
|
||||
|
||||
void yahoo_http_head(int id, const char *url, const char *cookies, int len,
|
||||
char *payload, yahoo_get_fd_callback callback, void *data)
|
||||
{
|
||||
char host[255];
|
||||
int port = 80;
|
||||
char path[255];
|
||||
char buff[2048];
|
||||
char cookiebuff[1024];
|
||||
int ssl = 0;
|
||||
|
||||
if (!url_to_host_port_path(url, host, &port, path, &ssl))
|
||||
return;
|
||||
|
||||
/* Allow cases when we don't need to send a cookie */
|
||||
if (cookies)
|
||||
snprintf(cookiebuff, sizeof(cookiebuff), "Cookie: %s\r\n",
|
||||
cookies);
|
||||
else
|
||||
cookiebuff[0] = '\0';
|
||||
|
||||
snprintf(buff, sizeof(buff),
|
||||
"HEAD %s HTTP/1.0\r\n"
|
||||
"Accept: */*\r\n"
|
||||
"Host: %s:%d\r\n"
|
||||
"User-Agent: Mozilla/4.5 [en] (" "1" "/" "1" ")\r\n"
|
||||
"%s"
|
||||
"Content-Length: %d\r\n"
|
||||
"Cache-Control: no-cache\r\n"
|
||||
"\r\n%s", path, host, port, cookiebuff, len,
|
||||
payload?payload:"");
|
||||
|
||||
yahoo_send_http_request(id, host, port, buff, callback, data, ssl);
|
||||
}
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
/*
|
||||
* libyahoo2: yahoo_httplib.h
|
||||
*
|
||||
* Copyright (C) 2002-2004, Philip S Tellis <philip.tellis AT gmx.net>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef YAHOO_HTTPLIB_H
|
||||
#define YAHOO_HTTPLIB_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "yahoo2_types.h"
|
||||
|
||||
char *yahoo_urlencode(const char *instr);
|
||||
char *yahoo_urldecode(const char *instr);
|
||||
char *yahoo_xmldecode(const char *instr);
|
||||
|
||||
int yahoo_tcp_readline(char *ptr, int maxlen, void *fd);
|
||||
void yahoo_http_post(int id, const char *url, const char *cookies,
|
||||
long size, yahoo_get_fd_callback callback, void *data);
|
||||
void yahoo_http_get(int id, const char *url, const char *cookies,
|
||||
int http11, int keepalive, yahoo_get_fd_callback callback,
|
||||
void *data);
|
||||
void yahoo_http_head(int id, const char *url, const char *cookies,
|
||||
int size, char *payload, yahoo_get_fd_callback callback,
|
||||
void *data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
|
@ -1,233 +0,0 @@
|
|||
/*
|
||||
* yahoo_list.c: linked list routines
|
||||
*
|
||||
* Some code copyright (C) 2002-2004, Philip S Tellis <philip.tellis AT gmx.net>
|
||||
* Other code copyright Meredydd Luff <meredydd AT everybuddy.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Some of this code was borrowed from elist.c in the eb-lite sources
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "yahoo_list.h"
|
||||
|
||||
YList *y_list_append(YList *list, void *data)
|
||||
{
|
||||
YList *n;
|
||||
YList *new_list = malloc(sizeof(YList));
|
||||
YList *attach_to = NULL;
|
||||
|
||||
new_list->next = NULL;
|
||||
new_list->data = data;
|
||||
|
||||
for (n = list; n != NULL; n = n->next) {
|
||||
attach_to = n;
|
||||
}
|
||||
|
||||
if (attach_to == NULL) {
|
||||
new_list->prev = NULL;
|
||||
return new_list;
|
||||
} else {
|
||||
new_list->prev = attach_to;
|
||||
attach_to->next = new_list;
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
YList *y_list_prepend(YList *list, void *data)
|
||||
{
|
||||
YList *n = malloc(sizeof(YList));
|
||||
|
||||
n->next = list;
|
||||
n->prev = NULL;
|
||||
n->data = data;
|
||||
if (list)
|
||||
list->prev = n;
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
YList *y_list_concat(YList *list, YList *add)
|
||||
{
|
||||
YList *l;
|
||||
|
||||
if (!list)
|
||||
return add;
|
||||
|
||||
if (!add)
|
||||
return list;
|
||||
|
||||
for (l = list; l->next; l = l->next) ;
|
||||
|
||||
l->next = add;
|
||||
add->prev = l;
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
YList *y_list_remove(YList *list, void *data)
|
||||
{
|
||||
YList *n;
|
||||
|
||||
for (n = list; n != NULL; n = n->next) {
|
||||
if (n->data == data) {
|
||||
list = y_list_remove_link(list, n);
|
||||
y_list_free_1(n);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/* Warning */
|
||||
/* link MUST be part of list */
|
||||
/* caller must free link using y_list_free_1 */
|
||||
YList *y_list_remove_link(YList *list, const YList *link)
|
||||
{
|
||||
if (!link)
|
||||
return list;
|
||||
|
||||
if (link->next)
|
||||
link->next->prev = link->prev;
|
||||
if (link->prev)
|
||||
link->prev->next = link->next;
|
||||
|
||||
if (link == list)
|
||||
list = link->next;
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
int y_list_length(const YList *list)
|
||||
{
|
||||
int retval = 0;
|
||||
const YList *n = list;
|
||||
|
||||
for (n = list; n != NULL; n = n->next) {
|
||||
retval++;
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/* well, you could just check for list == NULL, but that would be
|
||||
* implementation dependent
|
||||
*/
|
||||
int y_list_empty(const YList *list)
|
||||
{
|
||||
if (!list)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
int y_list_singleton(const YList *list)
|
||||
{
|
||||
if (!list || list->next)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
YList *y_list_copy(YList *list)
|
||||
{
|
||||
YList *n;
|
||||
YList *copy = NULL;
|
||||
|
||||
for (n = list; n != NULL; n = n->next) {
|
||||
copy = y_list_append(copy, n->data);
|
||||
}
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
void y_list_free_1(YList *list)
|
||||
{
|
||||
free(list);
|
||||
}
|
||||
|
||||
void y_list_free(YList *list)
|
||||
{
|
||||
YList *n = list;
|
||||
|
||||
while (n != NULL) {
|
||||
YList *next = n->next;
|
||||
free(n);
|
||||
n = next;
|
||||
}
|
||||
}
|
||||
|
||||
YList *y_list_find(YList *list, const void *data)
|
||||
{
|
||||
YList *l;
|
||||
for (l = list; l && l->data != data; l = l->next) ;
|
||||
|
||||
return l;
|
||||
}
|
||||
|
||||
void y_list_foreach(YList *list, YListFunc fn, void *user_data)
|
||||
{
|
||||
for (; list; list = list->next)
|
||||
fn(list->data, user_data);
|
||||
}
|
||||
|
||||
YList *y_list_find_custom(YList *list, const void *data, YListCompFunc comp)
|
||||
{
|
||||
YList *l;
|
||||
for (l = list; l; l = l->next)
|
||||
if (comp(l->data, data) == 0)
|
||||
return l;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
YList *y_list_nth(YList *list, int n)
|
||||
{
|
||||
int i = n;
|
||||
for (; list && i; list = list->next, i--) ;
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
YList *y_list_insert_sorted(YList *list, void *data, YListCompFunc comp)
|
||||
{
|
||||
YList *l, *n, *prev = NULL;
|
||||
if (!list)
|
||||
return y_list_append(list, data);
|
||||
|
||||
n = malloc(sizeof(YList));
|
||||
n->data = data;
|
||||
for (l = list; l && comp(l->data, n->data) <= 0; l = l->next)
|
||||
prev = l;
|
||||
|
||||
if (l) {
|
||||
n->prev = l->prev;
|
||||
l->prev = n;
|
||||
} else
|
||||
n->prev = prev;
|
||||
|
||||
n->next = l;
|
||||
|
||||
if (n->prev) {
|
||||
n->prev->next = n;
|
||||
return list;
|
||||
} else {
|
||||
return n;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,76 +0,0 @@
|
|||
/*
|
||||
* yahoo_list.h: linked list routines
|
||||
*
|
||||
* Some code copyright (C) 2002-2004, Philip S Tellis <philip.tellis AT gmx.net>
|
||||
* Other code copyright Meredydd Luff <meredydd AT everybuddy.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* This is a replacement for the GList. It only provides functions that
|
||||
* we use in Ayttm. Thanks to Meredyyd from everybuddy dev for doing
|
||||
* most of it.
|
||||
*/
|
||||
|
||||
#ifndef __YLIST_H__
|
||||
#define __YLIST_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct _YList {
|
||||
struct _YList *next;
|
||||
struct _YList *prev;
|
||||
void *data;
|
||||
} YList;
|
||||
|
||||
typedef int (*YListCompFunc) (const void *, const void *);
|
||||
typedef void (*YListFunc) (void *, void *);
|
||||
|
||||
YList *y_list_append(YList *list, void *data);
|
||||
YList *y_list_prepend(YList *list, void *data);
|
||||
YList *y_list_remove_link(YList *list, const YList *link);
|
||||
YList *y_list_remove(YList *list, void *data);
|
||||
|
||||
YList *y_list_insert_sorted(YList *list, void *data,
|
||||
YListCompFunc comp);
|
||||
|
||||
YList *y_list_copy(YList *list);
|
||||
|
||||
YList *y_list_concat(YList *list, YList *add);
|
||||
|
||||
YList *y_list_find(YList *list, const void *data);
|
||||
YList *y_list_find_custom(YList *list, const void *data,
|
||||
YListCompFunc comp);
|
||||
|
||||
YList *y_list_nth(YList *list, int n);
|
||||
|
||||
void y_list_foreach(YList *list, YListFunc fn, void *user_data);
|
||||
|
||||
void y_list_free_1(YList *list);
|
||||
void y_list_free(YList *list);
|
||||
int y_list_length(const YList *list);
|
||||
int y_list_empty(const YList *list);
|
||||
int y_list_singleton(const YList *list);
|
||||
|
||||
#define y_list_next(list) list->next
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
|
@ -1,166 +0,0 @@
|
|||
/*
|
||||
* libyahoo2: yahoo_util.c
|
||||
*
|
||||
* Copyright (C) 2002-2004, Philip S Tellis <philip.tellis AT gmx.net>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#if __APPLE__
|
||||
#define STDC_HEADERS 1
|
||||
#endif
|
||||
|
||||
#if STDC_HEADERS
|
||||
# include <string.h>
|
||||
#else
|
||||
# if !HAVE_STRCHR
|
||||
# define strchr index
|
||||
# define strrchr rindex
|
||||
# endif
|
||||
char *strchr(), *strrchr();
|
||||
# if !HAVE_MEMCPY
|
||||
# define memcpy(d, s, n) bcopy ((s), (d), (n))
|
||||
# define memmove(d, s, n) bcopy ((s), (d), (n))
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#include "yahoo_util.h"
|
||||
|
||||
char *y_string_append(char *string, char *append)
|
||||
{
|
||||
int size = strlen(string) + strlen(append) + 1;
|
||||
char *new_string = y_renew(char, string, size);
|
||||
|
||||
if (new_string == NULL) {
|
||||
new_string = y_new(char, size);
|
||||
strcpy(new_string, string);
|
||||
FREE(string);
|
||||
}
|
||||
|
||||
strcat(new_string, append);
|
||||
|
||||
return new_string;
|
||||
}
|
||||
|
||||
char *y_str_to_utf8(const char *in)
|
||||
{
|
||||
unsigned int n, i = 0;
|
||||
char *result = NULL;
|
||||
|
||||
if (in == NULL || *in == '\0')
|
||||
return strdup("");
|
||||
|
||||
result = y_new(char, strlen(in) * 2 + 1);
|
||||
|
||||
/* convert a string to UTF-8 Format */
|
||||
for (n = 0; n < strlen(in); n++) {
|
||||
unsigned char c = (unsigned char)in[n];
|
||||
|
||||
if (c < 128) {
|
||||
result[i++] = (char)c;
|
||||
} else {
|
||||
result[i++] = (char)((c >> 6) | 192);
|
||||
result[i++] = (char)((c & 63) | 128);
|
||||
}
|
||||
}
|
||||
result[i] = '\0';
|
||||
return result;
|
||||
}
|
||||
|
||||
char *y_utf8_to_str(const char *in)
|
||||
{
|
||||
int i = 0;
|
||||
unsigned int n;
|
||||
char *result = NULL;
|
||||
|
||||
if (in == NULL || *in == '\0')
|
||||
return strdup("");
|
||||
|
||||
result = y_new(char, strlen(in) + 1);
|
||||
|
||||
/* convert a string from UTF-8 Format */
|
||||
for (n = 0; n < strlen(in); n++) {
|
||||
unsigned char c = in[n];
|
||||
|
||||
if (c < 128) {
|
||||
result[i++] = (char)c;
|
||||
} else {
|
||||
result[i++] = (c << 6) | (in[++n] & 63);
|
||||
}
|
||||
}
|
||||
result[i] = '\0';
|
||||
return result;
|
||||
}
|
||||
|
||||
#if !HAVE_GLIB
|
||||
|
||||
void y_strfreev(char **vector)
|
||||
{
|
||||
char **v;
|
||||
for (v = vector; *v; v++) {
|
||||
FREE(*v);
|
||||
}
|
||||
FREE(vector);
|
||||
}
|
||||
|
||||
char **y_strsplit(char *str, char *sep, int nelem)
|
||||
{
|
||||
char **vector;
|
||||
char *s, *p;
|
||||
int i = 0;
|
||||
int l = strlen(sep);
|
||||
if (nelem <= 0) {
|
||||
char *s;
|
||||
nelem = 0;
|
||||
if (*str) {
|
||||
for (s = strstr(str, sep); s;
|
||||
s = strstr(s + l, sep), nelem++) ;
|
||||
if (strcmp(str + strlen(str) - l, sep))
|
||||
nelem++;
|
||||
}
|
||||
}
|
||||
|
||||
vector = y_new(char *, nelem + 1);
|
||||
|
||||
for (p = str, s = strstr(p, sep); i < nelem && s;
|
||||
p = s + l, s = strstr(p, sep), i++) {
|
||||
int len = s - p;
|
||||
vector[i] = y_new(char, len + 1);
|
||||
strncpy(vector[i], p, len);
|
||||
vector[i][len] = '\0';
|
||||
}
|
||||
|
||||
if (i < nelem && *str) /* str didn't end with sep, and str isn't empty */
|
||||
vector[i++] = strdup(p);
|
||||
|
||||
vector[i] = NULL;
|
||||
|
||||
return vector;
|
||||
}
|
||||
|
||||
void *y_memdup(const void *addr, int n)
|
||||
{
|
||||
void *new_chunk = malloc(n);
|
||||
if (new_chunk)
|
||||
memcpy(new_chunk, addr, n);
|
||||
return new_chunk;
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,103 +0,0 @@
|
|||
/*
|
||||
* libyahoo2: yahoo_util.h
|
||||
*
|
||||
* Copyright (C) 2002-2004, Philip S Tellis <philip.tellis AT gmx.net>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __YAHOO_UTIL_H__
|
||||
#define __YAHOO_UTIL_H__
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_GLIB
|
||||
# include <glib.h>
|
||||
|
||||
# define FREE(x) if(x) {g_free(x); x=NULL;}
|
||||
|
||||
# define y_new g_new
|
||||
# define y_new0 g_new0
|
||||
# define y_renew g_renew
|
||||
|
||||
# define y_memdup g_memdup
|
||||
# define y_strsplit g_strsplit
|
||||
# define y_strfreev g_strfreev
|
||||
# ifndef strdup
|
||||
# define strdup g_strdup
|
||||
# endif
|
||||
# ifndef strncasecmp
|
||||
# define strncasecmp g_strncasecmp
|
||||
# define strcasecmp g_strcasecmp
|
||||
# endif
|
||||
|
||||
# define snprintf g_snprintf
|
||||
# define vsnprintf g_vsnprintf
|
||||
|
||||
#else
|
||||
|
||||
# include <stdlib.h>
|
||||
# include <stdarg.h>
|
||||
|
||||
# define FREE(x) if(x) {free(x); x=NULL;}
|
||||
|
||||
# define y_new(type, n) (type *)malloc(sizeof(type) * (n))
|
||||
# define y_new0(type, n) (type *)calloc((n), sizeof(type))
|
||||
# define y_renew(type, mem, n) (type *)realloc(mem, n)
|
||||
|
||||
void *y_memdup(const void *addr, int n);
|
||||
char **y_strsplit(char *str, char *sep, int nelem);
|
||||
void y_strfreev(char **vector);
|
||||
|
||||
#if !defined(_WIN32) && !defined(__APPLE__)
|
||||
int strncasecmp(const char *s1, const char *s2, size_t n);
|
||||
int strcasecmp(const char *s1, const char *s2);
|
||||
|
||||
char *strdup(const char *s);
|
||||
|
||||
int snprintf(char *str, size_t size, const char *format, ...);
|
||||
int vsnprintf(char *str, size_t size, const char *format, va_list ap);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef TRUE
|
||||
#define TRUE 1
|
||||
#endif
|
||||
|
||||
#ifndef FALSE
|
||||
#define FALSE 0
|
||||
#endif
|
||||
|
||||
#ifndef MIN
|
||||
#define MIN(x,y) ((x)<(y)?(x):(y))
|
||||
#endif
|
||||
|
||||
#ifndef MAX
|
||||
#define MAX(x,y) ((x)>(y)?(x):(y))
|
||||
#endif
|
||||
|
||||
/*
|
||||
* The following three functions return newly allocated memory.
|
||||
* You must free it yourself
|
||||
*/
|
||||
char *y_string_append(char *str, char *append);
|
||||
char *y_str_to_utf8(const char *in);
|
||||
char *y_utf8_to_str(const char *in);
|
||||
|
||||
#endif
|
|
@ -1,42 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
// Transport includes
|
||||
#include "transport/config.h"
|
||||
#include "transport/networkplugin.h"
|
||||
#include "transport/logging.h"
|
||||
|
||||
// Yahoo2
|
||||
#include <yahoo2.h>
|
||||
#include <yahoo2_callbacks.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
// Swiften
|
||||
#include "Swiften/Swiften.h"
|
||||
#include "Swiften/TLS/OpenSSL/OpenSSLContextFactory.h"
|
||||
|
||||
// Boost
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
using namespace boost::filesystem;
|
||||
using namespace boost::program_options;
|
||||
using namespace Transport;
|
||||
|
||||
class YahooLocalAccount;
|
||||
|
||||
class YahooHandler {
|
||||
public:
|
||||
YahooHandler(YahooLocalAccount *account, int conn_tag, int handler_tag, void *data, yahoo_input_condition cond);
|
||||
virtual ~YahooHandler();
|
||||
|
||||
void ready(std::string *buffer = NULL);
|
||||
|
||||
int handler_tag;
|
||||
int conn_tag;
|
||||
void *data;
|
||||
yahoo_input_condition cond;
|
||||
bool remove_later;
|
||||
YahooLocalAccount *account;
|
||||
};
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
|
||||
#include "yahoolocalaccount.h"
|
||||
#include "yahoohandler.h"
|
||||
|
||||
YahooLocalAccount::YahooLocalAccount(const std::string &user, const std::string &legacyName, const std::string &password) : user(user), id(0), conn_tag(1), handler_tag(1), status(YAHOO_STATUS_OFFLINE), msg(""), buffer("") {
|
||||
id = yahoo_init_with_attributes(legacyName.c_str(), password.c_str(),
|
||||
"local_host", "",
|
||||
"pager_port", 5050,
|
||||
NULL);
|
||||
}
|
||||
|
||||
YahooLocalAccount::~YahooLocalAccount() {
|
||||
// remove handlers
|
||||
for (std::map<int, YahooHandler *>::iterator it = handlers.begin(); it != handlers.end(); it++) {
|
||||
delete it->second;
|
||||
}
|
||||
|
||||
// remove conns
|
||||
for (std::map<int, boost::shared_ptr<Swift::Connection> >::iterator it = conns.begin(); it != conns.end(); it++) {
|
||||
it->second->onConnectFinished.disconnect_all_slots();
|
||||
it->second->onDisconnected.disconnect_all_slots();
|
||||
it->second->onDataRead.disconnect_all_slots();
|
||||
it->second->onDataWritten.disconnect_all_slots();
|
||||
}
|
||||
}
|
||||
|
||||
void YahooLocalAccount::login() {
|
||||
yahoo_login(id, YAHOO_STATUS_AVAILABLE);
|
||||
}
|
||||
|
||||
void YahooLocalAccount::addHandler(YahooHandler *handler) {
|
||||
handlers[handler->handler_tag] = handler;
|
||||
handlers_per_conn[handler->conn_tag][handler->handler_tag] = handler;
|
||||
}
|
||||
|
||||
void YahooLocalAccount::removeOldHandlers() {
|
||||
std::vector<int> handlers_to_remove;
|
||||
for (std::map<int, YahooHandler *>::iterator it = handlers.begin(); it != handlers.end(); it++) {
|
||||
if (it->second->remove_later) {
|
||||
handlers_to_remove.push_back(it->first);
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_FOREACH(int tag, handlers_to_remove) {
|
||||
YahooHandler *handler = handlers[tag];
|
||||
handlers.erase(tag);
|
||||
handlers_per_conn[handler->conn_tag].erase(tag);
|
||||
delete handler;
|
||||
}
|
||||
}
|
||||
|
||||
void YahooLocalAccount::removeConn(int conn_tag) {
|
||||
for (std::map<int, YahooHandler *>::iterator it = handlers_per_conn[conn_tag].begin(); it != handlers_per_conn[conn_tag].end(); it++) {
|
||||
it->second->remove_later = true;
|
||||
}
|
||||
|
||||
removeOldHandlers();
|
||||
|
||||
conns.erase(conn_tag);
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
// Transport includes
|
||||
#include "transport/config.h"
|
||||
#include "transport/networkplugin.h"
|
||||
#include "transport/logging.h"
|
||||
|
||||
// Yahoo2
|
||||
#include <yahoo2.h>
|
||||
#include <yahoo2_callbacks.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
// Swiften
|
||||
#include "Swiften/Swiften.h"
|
||||
#include "Swiften/TLS/OpenSSL/OpenSSLContextFactory.h"
|
||||
|
||||
// Boost
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
using namespace boost::filesystem;
|
||||
using namespace boost::program_options;
|
||||
using namespace Transport;
|
||||
|
||||
class YahooHandler;
|
||||
|
||||
class YahooLocalAccount {
|
||||
public:
|
||||
YahooLocalAccount(const std::string &user, const std::string &legacyName, const std::string &password);
|
||||
virtual ~YahooLocalAccount();
|
||||
|
||||
void login();
|
||||
|
||||
void addHandler(YahooHandler *handler);
|
||||
void removeOldHandlers();
|
||||
void removeConn(int conn_tag);
|
||||
|
||||
std::string user;
|
||||
int id;
|
||||
std::map<int, boost::shared_ptr<Swift::Connection> > conns;
|
||||
int conn_tag;
|
||||
std::map<int, YahooHandler *> handlers;
|
||||
std::map<int, std::map<int, YahooHandler *> > handlers_per_conn;
|
||||
std::map<std::string, std::string> urls;
|
||||
int handler_tag;
|
||||
int status;
|
||||
std::string msg;
|
||||
std::string buffer;
|
||||
};
|
|
@ -1,9 +1,9 @@
|
|||
cmake_minimum_required(VERSION 2.6)
|
||||
FILE(GLOB SRC *.cpp)
|
||||
|
||||
ADD_EXECUTABLE(spectrum2_skype_backend ${SRC})
|
||||
|
||||
target_link_libraries(spectrum2_skype_backend ${GLIB2_LIBRARIES} ${EVENT_LIBRARIES} transport pthread ${LIBDBUSGLIB_LIBRARIES})
|
||||
|
||||
INSTALL(TARGETS spectrum2_skype_backend RUNTIME DESTINATION bin)
|
||||
|
||||
cmake_minimum_required(VERSION 2.6)
|
||||
FILE(GLOB SRC *.cpp)
|
||||
|
||||
ADD_EXECUTABLE(spectrum2_skype_backend ${SRC})
|
||||
|
||||
target_link_libraries(spectrum2_skype_backend ${GLIB2_LIBRARIES} ${EVENT_LIBRARIES} transport pthread ${LIBDBUSGLIB_LIBRARIES})
|
||||
|
||||
INSTALL(TARGETS spectrum2_skype_backend RUNTIME DESTINATION bin)
|
||||
|
||||
|
|
|
@ -3,18 +3,18 @@
|
|||
#include "sqlite3.h"
|
||||
#include <iostream>
|
||||
|
||||
#include "transport/config.h"
|
||||
#include "transport/logging.h"
|
||||
#include "transport/transport.h"
|
||||
#include "transport/usermanager.h"
|
||||
#include "transport/memoryusage.h"
|
||||
#include "transport/sqlite3backend.h"
|
||||
#include "transport/userregistration.h"
|
||||
#include "transport/user.h"
|
||||
#include "transport/storagebackend.h"
|
||||
#include "transport/rostermanager.h"
|
||||
#include "transport/conversation.h"
|
||||
#include "transport/networkplugin.h"
|
||||
#include "transport/Config.h"
|
||||
#include "transport/Logging.h"
|
||||
#include "transport/Transport.h"
|
||||
#include "transport/UserManager.h"
|
||||
#include "transport/MemoryUsage.h"
|
||||
#include "transport/SQLite3Backend.h"
|
||||
#include "transport/UserRegistration.h"
|
||||
#include "transport/User.h"
|
||||
#include "transport/StorageBackend.h"
|
||||
#include "transport/RosterManager.h"
|
||||
#include "transport/Conversation.h"
|
||||
#include "transport/NetworkPlugin.h"
|
||||
#include <boost/filesystem.hpp>
|
||||
#include "sys/wait.h"
|
||||
#include "sys/signal.h"
|
||||
|
|
|
@ -22,18 +22,17 @@
|
|||
#include "skypeplugin.h"
|
||||
#include "skypedb.h"
|
||||
|
||||
#include "transport/config.h"
|
||||
#include "transport/logging.h"
|
||||
#include "transport/transport.h"
|
||||
#include "transport/usermanager.h"
|
||||
#include "transport/memoryusage.h"
|
||||
#include "transport/sqlite3backend.h"
|
||||
#include "transport/userregistration.h"
|
||||
#include "transport/user.h"
|
||||
#include "transport/storagebackend.h"
|
||||
#include "transport/rostermanager.h"
|
||||
#include "transport/conversation.h"
|
||||
#include "transport/networkplugin.h"
|
||||
#include "transport/Logging.h"
|
||||
#include "transport/Transport.h"
|
||||
#include "transport/UserManager.h"
|
||||
#include "transport/MemoryUsage.h"
|
||||
#include "transport/SQLite3Backend.h"
|
||||
#include "transport/UserRegistration.h"
|
||||
#include "transport/User.h"
|
||||
#include "transport/StorageBackend.h"
|
||||
#include "transport/RosterManager.h"
|
||||
#include "transport/Conversation.h"
|
||||
#include "transport/NetworkPlugin.h"
|
||||
#include <boost/filesystem.hpp>
|
||||
#include "sys/wait.h"
|
||||
#include "sys/signal.h"
|
||||
|
|
|
@ -20,18 +20,17 @@
|
|||
|
||||
#include "skypedb.h"
|
||||
|
||||
#include "transport/config.h"
|
||||
#include "transport/logging.h"
|
||||
#include "transport/transport.h"
|
||||
#include "transport/usermanager.h"
|
||||
#include "transport/memoryusage.h"
|
||||
#include "transport/sqlite3backend.h"
|
||||
#include "transport/userregistration.h"
|
||||
#include "transport/user.h"
|
||||
#include "transport/storagebackend.h"
|
||||
#include "transport/rostermanager.h"
|
||||
#include "transport/conversation.h"
|
||||
#include "transport/networkplugin.h"
|
||||
#include "transport/Logging.h"
|
||||
#include "transport/Transport.h"
|
||||
#include "transport/UserManager.h"
|
||||
#include "transport/MemoryUsage.h"
|
||||
#include "transport/SQLite3Backend.h"
|
||||
#include "transport/UserRegistration.h"
|
||||
#include "transport/User.h"
|
||||
#include "transport/StorageBackend.h"
|
||||
#include "transport/RosterManager.h"
|
||||
#include "transport/Conversation.h"
|
||||
#include "transport/NetworkPlugin.h"
|
||||
#include <boost/filesystem.hpp>
|
||||
#include "sys/wait.h"
|
||||
#include "sys/signal.h"
|
||||
|
|
|
@ -22,18 +22,17 @@
|
|||
#include "skype.h"
|
||||
#include "skypedb.h"
|
||||
|
||||
#include "transport/config.h"
|
||||
#include "transport/logging.h"
|
||||
#include "transport/transport.h"
|
||||
#include "transport/usermanager.h"
|
||||
#include "transport/memoryusage.h"
|
||||
#include "transport/sqlite3backend.h"
|
||||
#include "transport/userregistration.h"
|
||||
#include "transport/user.h"
|
||||
#include "transport/storagebackend.h"
|
||||
#include "transport/rostermanager.h"
|
||||
#include "transport/conversation.h"
|
||||
#include "transport/networkplugin.h"
|
||||
#include "transport/Logging.h"
|
||||
#include "transport/Transport.h"
|
||||
#include "transport/UserManager.h"
|
||||
#include "transport/MemoryUsage.h"
|
||||
#include "transport/SQLite3Backend.h"
|
||||
#include "transport/UserRegistration.h"
|
||||
#include "transport/User.h"
|
||||
#include "transport/StorageBackend.h"
|
||||
#include "transport/RosterManager.h"
|
||||
#include "transport/Conversation.h"
|
||||
#include "transport/NetworkPlugin.h"
|
||||
#include <boost/filesystem.hpp>
|
||||
#include "sys/wait.h"
|
||||
#include "sys/signal.h"
|
||||
|
|
|
@ -25,8 +25,8 @@
|
|||
#include "sqlite3.h"
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include "transport/networkplugin.h"
|
||||
#include "transport/config.h"
|
||||
#include "transport/NetworkPlugin.h"
|
||||
#include "transport/Config.h"
|
||||
|
||||
class Skype;
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
cmake_minimum_required(VERSION 2.6)
|
||||
|
||||
FILE(GLOB SRC *.c *.cpp)
|
||||
|
||||
ADD_EXECUTABLE(spectrum2_smstools3_backend ${SRC})
|
||||
|
||||
target_link_libraries(spectrum2_smstools3_backend transport pthread ${Boost_LIBRARIES} ${SWIFTEN_LIBRARY} ${LOG4CXX_LIBRARIES})
|
||||
|
||||
INSTALL(TARGETS spectrum2_smstools3_backend RUNTIME DESTINATION bin)
|
||||
|
||||
cmake_minimum_required(VERSION 2.6)
|
||||
|
||||
FILE(GLOB SRC *.c *.cpp)
|
||||
|
||||
ADD_EXECUTABLE(spectrum2_smstools3_backend ${SRC})
|
||||
|
||||
target_link_libraries(spectrum2_smstools3_backend transport pthread ${Boost_LIBRARIES} ${SWIFTEN_LIBRARY} ${LOG4CXX_LIBRARIES})
|
||||
|
||||
INSTALL(TARGETS spectrum2_smstools3_backend RUNTIME DESTINATION bin)
|
||||
|
||||
|
|
|
@ -8,13 +8,13 @@
|
|||
* program, but you don't have to.
|
||||
*/
|
||||
|
||||
#include "transport/config.h"
|
||||
#include "transport/logging.h"
|
||||
#include "transport/networkplugin.h"
|
||||
#include "transport/sqlite3backend.h"
|
||||
#include "transport/mysqlbackend.h"
|
||||
#include "transport/pqxxbackend.h"
|
||||
#include "transport/storagebackend.h"
|
||||
#include "transport/Config.h"
|
||||
#include "transport/Logging.h"
|
||||
#include "transport/NetworkPlugin.h"
|
||||
#include "transport/SQLite3Backend.h"
|
||||
#include "transport/MySQLBackend.h"
|
||||
#include "transport/PQXXBackend.h"
|
||||
#include "transport/StorageBackend.h"
|
||||
#include "Swiften/Swiften.h"
|
||||
#include <boost/filesystem.hpp>
|
||||
#include "unistd.h"
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
cmake_minimum_required(VERSION 2.6)
|
||||
|
||||
FILE(GLOB SRC *.cpp)
|
||||
|
||||
ADD_EXECUTABLE(spectrum2_swiften_backend ${SRC})
|
||||
|
||||
IF (NOT WIN32)
|
||||
target_link_libraries(spectrum2_swiften_backend transport pthread ${Boost_LIBRARIES} ${SWIFTEN_LIBRARY} ${LOG4CXX_LIBRARIES})
|
||||
else()
|
||||
target_link_libraries(spectrum2_swiften_backend transport ${Boost_LIBRARIES} ${SWIFTEN_LIBRARY} ${LOG4CXX_LIBRARIES})
|
||||
endif()
|
||||
|
||||
INSTALL(TARGETS spectrum2_swiften_backend RUNTIME DESTINATION bin)
|
||||
|
||||
cmake_minimum_required(VERSION 2.6)
|
||||
|
||||
FILE(GLOB SRC *.cpp)
|
||||
|
||||
ADD_EXECUTABLE(spectrum2_swiften_backend ${SRC})
|
||||
|
||||
IF (NOT WIN32)
|
||||
target_link_libraries(spectrum2_swiften_backend transport pthread ${Boost_LIBRARIES} ${SWIFTEN_LIBRARY} ${LOG4CXX_LIBRARIES})
|
||||
else()
|
||||
target_link_libraries(spectrum2_swiften_backend transport ${Boost_LIBRARIES} ${SWIFTEN_LIBRARY} ${LOG4CXX_LIBRARIES})
|
||||
endif()
|
||||
|
||||
INSTALL(TARGETS spectrum2_swiften_backend RUNTIME DESTINATION bin)
|
||||
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
// Transport includes
|
||||
#include "transport/config.h"
|
||||
#include "transport/networkplugin.h"
|
||||
#include "transport/logging.h"
|
||||
#include "transport/Config.h"
|
||||
#include "transport/NetworkPlugin.h"
|
||||
#include "transport/Logging.h"
|
||||
|
||||
#include "boost/date_time/posix_time/posix_time.hpp"
|
||||
|
||||
// Swiften
|
||||
#include "Swiften/Swiften.h"
|
||||
#include <Swiften/Version.h>
|
||||
#define HAVE_SWIFTEN_3 (SWIFTEN_VERSION >= 0x030000)
|
||||
|
||||
#ifndef WIN32
|
||||
// for signal handler
|
||||
|
@ -87,8 +89,11 @@ class SwiftenPlugin : public NetworkPlugin, Swift::XMPPParserClient {
|
|||
m_conn = m_factories->getConnectionFactory()->createConnection();
|
||||
m_conn->onDataRead.connect(boost::bind(&SwiftenPlugin::_handleDataRead, this, _1));
|
||||
m_conn->connect(Swift::HostAddressPort(Swift::HostAddress(host), port));
|
||||
|
||||
#if HAVE_SWIFTEN_3
|
||||
serializer = new Swift::XMPPSerializer(&collection, Swift::ClientStreamType, false);
|
||||
#else
|
||||
serializer = new Swift::XMPPSerializer(&collection, Swift::ClientStreamType);
|
||||
#endif
|
||||
m_xmppParser = new Swift::XMPPParser(this, &m_collection2, m_factories->getXMLParserFactory());
|
||||
m_xmppParser->parse("<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' to='localhost' version='1.0'>");
|
||||
|
||||
|
@ -113,8 +118,11 @@ class SwiftenPlugin : public NetworkPlugin, Swift::XMPPParserClient {
|
|||
}
|
||||
|
||||
void handleStreamStart(const Swift::ProtocolHeader&) {}
|
||||
|
||||
#if HAVE_SWIFTEN_3
|
||||
void handleElement(boost::shared_ptr<Swift::ToplevelElement> element) {
|
||||
#else
|
||||
void handleElement(boost::shared_ptr<Swift::Element> element) {
|
||||
#endif
|
||||
boost::shared_ptr<Swift::Stanza> stanza = boost::dynamic_pointer_cast<Swift::Stanza>(element);
|
||||
if (!stanza) {
|
||||
return;
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
cmake_minimum_required(VERSION 2.6)
|
||||
|
||||
FILE(GLOB SRC *.c *.cpp)
|
||||
|
||||
ADD_EXECUTABLE(spectrum2_template_backend ${SRC})
|
||||
|
||||
if (CMAKE_COMPILER_IS_GNUCXX)
|
||||
if (NOT WIN32)
|
||||
target_link_libraries(spectrum2_template_backend transport pthread ${Boost_LIBRARIES} ${SWIFTEN_LIBRARY} ${LOG4CXX_LIBRARIES})
|
||||
else()
|
||||
target_link_libraries(spectrum2_template_backend transport ${Boost_LIBRARIES} ${SWIFTEN_LIBRARY} ${LOG4CXX_LIBRARIES})
|
||||
endif()
|
||||
else()
|
||||
target_link_libraries(spectrum2_template_backend transport ${PROTOBUF_LIBRARY} ${Boost_LIBRARIES} ${SWIFTEN_LIBRARY} ${LOG4CXX_LIBRARIES})
|
||||
endif()
|
||||
|
||||
#INSTALL(TARGETS spectrum2_template_backend RUNTIME DESTINATION bin)
|
||||
|
||||
cmake_minimum_required(VERSION 2.6)
|
||||
|
||||
FILE(GLOB SRC *.c *.cpp)
|
||||
|
||||
ADD_EXECUTABLE(spectrum2_template_backend ${SRC})
|
||||
|
||||
if (CMAKE_COMPILER_IS_GNUCXX)
|
||||
if (NOT WIN32)
|
||||
target_link_libraries(spectrum2_template_backend transport pthread ${Boost_LIBRARIES} ${SWIFTEN_LIBRARY} ${LOG4CXX_LIBRARIES})
|
||||
else()
|
||||
target_link_libraries(spectrum2_template_backend transport ${Boost_LIBRARIES} ${SWIFTEN_LIBRARY} ${LOG4CXX_LIBRARIES})
|
||||
endif()
|
||||
else()
|
||||
target_link_libraries(spectrum2_template_backend transport ${PROTOBUF_LIBRARY} ${Boost_LIBRARIES} ${SWIFTEN_LIBRARY} ${LOG4CXX_LIBRARIES})
|
||||
endif()
|
||||
|
||||
#INSTALL(TARGETS spectrum2_template_backend RUNTIME DESTINATION bin)
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
#include "plugin.h"
|
||||
|
||||
// Transport includes
|
||||
#include "transport/config.h"
|
||||
#include "transport/networkplugin.h"
|
||||
#include "transport/logging.h"
|
||||
#include "transport/Config.h"
|
||||
#include "transport/NetworkPlugin.h"
|
||||
#include "transport/Logging.h"
|
||||
|
||||
// Swiften
|
||||
#include "Swiften/Swiften.h"
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#include "plugin.h"
|
||||
// Transport includes
|
||||
#include "transport/config.h"
|
||||
#include "transport/networkplugin.h"
|
||||
#include "transport/logging.h"
|
||||
#include "transport/Config.h"
|
||||
#include "transport/NetworkPlugin.h"
|
||||
#include "transport/Logging.h"
|
||||
|
||||
// Swiften
|
||||
#include "Swiften/Swiften.h"
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
#include "Swiften/Swiften.h"
|
||||
|
||||
#include "transport/config.h"
|
||||
#include "transport/networkplugin.h"
|
||||
#include "transport/Config.h"
|
||||
#include "transport/NetworkPlugin.h"
|
||||
|
||||
class Plugin : public Transport::NetworkPlugin {
|
||||
public:
|
||||
|
|
|
@ -2,11 +2,14 @@ include_directories (${libtransport_SOURCE_DIR}/backends/twitter/libtwitcurl)
|
|||
FILE(GLOB SRC *.cpp libtwitcurl/*.cpp Requests/*.cpp)
|
||||
add_executable(spectrum2_twitter_backend ${SRC})
|
||||
|
||||
if (NOT WIN32)
|
||||
target_link_libraries(spectrum2_twitter_backend curl transport pthread ${Boost_LIBRARIES} ${SWIFTEN_LIBRARY} ${LOG4CXX_LIBRARIES})
|
||||
else ()
|
||||
include_directories("${CMAKE_SOURCE_DIR}/msvc-deps/curl/include")
|
||||
target_link_libraries(spectrum2_twitter_backend libcurl transport ${Boost_LIBRARIES} ${SWIFTEN_LIBRARY} ${LOG4CXX_LIBRARIES})
|
||||
find_package(CURL)
|
||||
|
||||
if(CURL_FOUND)
|
||||
message(STATUS "Using curl ${CURL_VERSION_STRING}: ${CURL_INCLUDE_DIRS} ${CURL_LIBRARIES}")
|
||||
include_directories (${CURL_INCLUDE_DIRS})
|
||||
target_link_libraries(spectrum2_twitter_backend transport ${CURL_LIBRARIES} ${Boost_LIBRARIES} ${SWIFTEN_LIBRARY} ${LOG4CXX_LIBRARIES})
|
||||
else()
|
||||
message(FATAL_ERROR "curl not found")
|
||||
endif()
|
||||
|
||||
INSTALL(TARGETS spectrum2_twitter_backend RUNTIME DESTINATION bin)
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#define HTTPREQ_H
|
||||
|
||||
#include "curl/curl.h"
|
||||
#include "transport/logging.h"
|
||||
#include "transport/Logging.h"
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string.h>
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
#ifndef CREATE_FRIEND
|
||||
#define CREATE_FRIEND
|
||||
|
||||
#include "transport/threadpool.h"
|
||||
#include "transport/ThreadPool.h"
|
||||
#include "../TwitterResponseParser.h"
|
||||
#include "../libtwitcurl/twitcurl.h"
|
||||
#include "transport/logging.h"
|
||||
#include "transport/Logging.h"
|
||||
#include <string>
|
||||
#include <boost/function.hpp>
|
||||
#include <iostream>
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
#ifndef DESTROY_FRIEND
|
||||
#define DESTROY_FRIEND
|
||||
|
||||
#include "transport/threadpool.h"
|
||||
#include "transport/ThreadPool.h"
|
||||
#include "../TwitterResponseParser.h"
|
||||
#include "../libtwitcurl/twitcurl.h"
|
||||
#include "transport/logging.h"
|
||||
#include "transport/Logging.h"
|
||||
#include <string>
|
||||
#include <boost/function.hpp>
|
||||
#include <iostream>
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
#ifndef DIRECT_MESSAGE
|
||||
#define DIRECT_MESSAGE
|
||||
|
||||
#include "transport/threadpool.h"
|
||||
#include "transport/ThreadPool.h"
|
||||
#include "../TwitterResponseParser.h"
|
||||
#include "../libtwitcurl/twitcurl.h"
|
||||
#include "transport/logging.h"
|
||||
#include "transport/Logging.h"
|
||||
#include <string>
|
||||
#include <boost/function.hpp>
|
||||
#include <iostream>
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
#ifndef FRIENDS_H
|
||||
#define FRIENDS_H
|
||||
|
||||
#include "transport/threadpool.h"
|
||||
#include "transport/ThreadPool.h"
|
||||
#include "../libtwitcurl/twitcurl.h"
|
||||
#include "../TwitterResponseParser.h"
|
||||
#include "transport/logging.h"
|
||||
#include "transport/Logging.h"
|
||||
#include <string>
|
||||
#include <boost/signals.hpp>
|
||||
#include <boost/function.hpp>
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
#ifndef HELPMESSAGE_H
|
||||
#define HELPMESSAGE_H
|
||||
|
||||
#include "transport/threadpool.h"
|
||||
#include "transport/ThreadPool.h"
|
||||
#include "../libtwitcurl/twitcurl.h"
|
||||
#include "transport/networkplugin.h"
|
||||
#include "transport/logging.h"
|
||||
#include "transport/Logging.h"
|
||||
#include <string>
|
||||
#include <boost/function.hpp>
|
||||
#include <iostream>
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
#ifndef OAUTH_FLOW
|
||||
#define OAUTH_FLOW
|
||||
|
||||
#include "transport/threadpool.h"
|
||||
#include "transport/ThreadPool.h"
|
||||
#include "../libtwitcurl/twitcurl.h"
|
||||
#include "../TwitterPlugin.h"
|
||||
#include "transport/logging.h"
|
||||
#include "transport/Logging.h"
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
#ifndef PIN_EXCHANGE
|
||||
#define PIN_EXCHANGE
|
||||
|
||||
#include "transport/threadpool.h"
|
||||
#include "transport/ThreadPool.h"
|
||||
#include "../libtwitcurl/twitcurl.h"
|
||||
#include "../TwitterPlugin.h"
|
||||
#include "transport/networkplugin.h"
|
||||
#include "transport/logging.h"
|
||||
#include "transport/Logging.h"
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
#ifndef PROFILEIMAGE_H
|
||||
#define PROFILEIMAGE_H
|
||||
|
||||
#include "transport/threadpool.h"
|
||||
#include "../TwitterResponseParser.h"
|
||||
#include "transport/logging.h"
|
||||
#include "transport/config.h"
|
||||
#include "transport/ThreadPool.h"
|
||||
#include "transport/Logging.h"
|
||||
#include "transport/Config.h"
|
||||
#include <string>
|
||||
#include <boost/signals.hpp>
|
||||
#include <boost/function.hpp>
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
#ifndef RETWEET_H
|
||||
#define RETWEET_H
|
||||
|
||||
#include "transport/threadpool.h"
|
||||
#include "transport/ThreadPool.h"
|
||||
#include "../TwitterResponseParser.h"
|
||||
#include "../libtwitcurl/twitcurl.h"
|
||||
#include "transport/networkplugin.h"
|
||||
#include "transport/logging.h"
|
||||
#include "transport/Logging.h"
|
||||
#include <boost/function.hpp>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
#ifndef STATUS_UPDATE
|
||||
#define STATUS_UPDATE
|
||||
|
||||
#include "transport/threadpool.h"
|
||||
#include "transport/ThreadPool.h"
|
||||
#include "../libtwitcurl/twitcurl.h"
|
||||
#include "../TwitterResponseParser.h"
|
||||
#include "transport/networkplugin.h"
|
||||
#include "transport/logging.h"
|
||||
#include "transport/Logging.h"
|
||||
#include <boost/function.hpp>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
#ifndef TIMELINE_H
|
||||
#define TIMELINE_H
|
||||
|
||||
#include "transport/threadpool.h"
|
||||
#include "transport/ThreadPool.h"
|
||||
#include "../libtwitcurl/twitcurl.h"
|
||||
#include "../TwitterResponseParser.h"
|
||||
#include "transport/logging.h"
|
||||
#include "transport/Logging.h"
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <boost/function.hpp>
|
||||
|
|
|
@ -649,7 +649,11 @@ void TwitterPlugin::populateRoster(std::string &user, std::vector<User> &friends
|
|||
std::string lastTweet = friends[i].getLastStatus().getTweet();
|
||||
//LOG4CXX_INFO(logger, user << " - " << SHA(friendAvatars[i]))
|
||||
handleBuddyChanged(user, friends[i].getScreenName(), friends[i].getUserName(), std::vector<std::string>(),
|
||||
#if HAVE_SWIFTEN_3
|
||||
pbnetwork::STATUS_ONLINE, lastTweet, Swift::byteArrayToString(cryptoProvider->getSHA1Hash(Swift::createByteArray(friendAvatars[i]))));
|
||||
#else
|
||||
pbnetwork::STATUS_ONLINE, lastTweet, SHA(friendAvatars[i]));
|
||||
#endif
|
||||
}
|
||||
else if(userdb[user].twitterMode == CHATROOM)
|
||||
handleParticipantChanged(user, friends[i].getScreenName(), adminChatRoom, 0, pbnetwork::STATUS_ONLINE);
|
||||
|
@ -821,7 +825,11 @@ void TwitterPlugin::createFriendResponse(std::string &user, User &frnd, std::str
|
|||
|
||||
LOG4CXX_INFO(logger, user << " - " << frnd.getScreenName() << ", " << frnd.getProfileImgURL())
|
||||
if(userdb[user].twitterMode == MULTIPLECONTACT) {
|
||||
#if HAVE_SWIFTEN_3
|
||||
handleBuddyChanged(user, frnd.getScreenName(), frnd.getUserName(), std::vector<std::string>(), pbnetwork::STATUS_ONLINE, "", Swift::byteArrayToString(cryptoProvider->getSHA1Hash(Swift::createByteArray(img))));
|
||||
#else
|
||||
handleBuddyChanged(user, frnd.getScreenName(), frnd.getUserName(), std::vector<std::string>(), pbnetwork::STATUS_ONLINE, "", SHA(img));
|
||||
#endif
|
||||
} else if(userdb[user].twitterMode == CHATROOM) {
|
||||
handleParticipantChanged(user, frnd.getScreenName(), adminChatRoom, 0, pbnetwork::STATUS_ONLINE);
|
||||
}
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
#ifndef TWITTER_PLUGIN
|
||||
#define TWITTER_PLUGIN
|
||||
|
||||
#include "transport/config.h"
|
||||
#include "transport/networkplugin.h"
|
||||
#include "transport/logging.h"
|
||||
#include "transport/sqlite3backend.h"
|
||||
#include "transport/mysqlbackend.h"
|
||||
#include "transport/pqxxbackend.h"
|
||||
#include "transport/storagebackend.h"
|
||||
#include "transport/threadpool.h"
|
||||
#include "transport/Config.h"
|
||||
#include "transport/NetworkPlugin.h"
|
||||
#include "transport/Logging.h"
|
||||
#include "transport/SQLite3Backend.h"
|
||||
#include "transport/MySQLBackend.h"
|
||||
#include "transport/PQXXBackend.h"
|
||||
#include "transport/StorageBackend.h"
|
||||
#include "transport/ThreadPool.h"
|
||||
|
||||
#include "Swiften/Swiften.h"
|
||||
#ifndef _WIN32
|
||||
|
@ -32,9 +32,14 @@
|
|||
#include <queue>
|
||||
#include <set>
|
||||
#include <cstdio>
|
||||
|
||||
#include <Swiften/Version.h>
|
||||
#define HAVE_SWIFTEN_3 (SWIFTEN_VERSION >= 0x030000)
|
||||
#if HAVE_SWIFTEN_3
|
||||
#include <Swiften/Crypto/CryptoProvider.h>
|
||||
#include <Swiften/Crypto/PlatformCryptoProvider.h>
|
||||
#else
|
||||
#include "Swiften/StringCodecs/SHA1.h"
|
||||
|
||||
#endif
|
||||
using namespace boost::filesystem;
|
||||
using namespace boost::program_options;
|
||||
using namespace Transport;
|
||||
|
@ -51,6 +56,9 @@ class TwitterPlugin : public NetworkPlugin {
|
|||
Swift::BoostNetworkFactories *m_factories;
|
||||
Swift::BoostIOServiceThread m_boostIOServiceThread;
|
||||
boost::shared_ptr<Swift::Connection> m_conn;
|
||||
#if HAVE_SWIFTEN_3
|
||||
boost::shared_ptr<Swift::CryptoProvider> cryptoProvider;
|
||||
#endif
|
||||
Swift::Timer::ref tweet_timer;
|
||||
Swift::Timer::ref message_timer;
|
||||
StorageBackend *storagebackend;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include "TwitterResponseParser.h"
|
||||
#include "transport/logging.h"
|
||||
#include "transport/Logging.h"
|
||||
#include "boost/algorithm/string.hpp"
|
||||
#include <cctype>
|
||||
#include "boost/date_time/local_time/local_time.hpp"
|
||||
|
|
|
@ -1,64 +1,64 @@
|
|||
//******************************************************************************
|
||||
//* HMAC_SHA1.cpp : Implementation of HMAC SHA1 algorithm
|
||||
//* Comfort to RFC 2104
|
||||
//*
|
||||
//******************************************************************************
|
||||
#include "HMAC_SHA1.h"
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
|
||||
|
||||
void CHMAC_SHA1::HMAC_SHA1(BYTE *text, int text_len, BYTE *key, int key_len, BYTE *digest)
|
||||
{
|
||||
memset(SHA1_Key, 0, SHA1_BLOCK_SIZE);
|
||||
|
||||
/* repeated 64 times for values in ipad and opad */
|
||||
memset(m_ipad, 0x36, sizeof(m_ipad));
|
||||
memset(m_opad, 0x5c, sizeof(m_opad));
|
||||
|
||||
/* STEP 1 */
|
||||
if (key_len > SHA1_BLOCK_SIZE)
|
||||
{
|
||||
CSHA1::Reset();
|
||||
CSHA1::Update((UINT_8 *)key, key_len);
|
||||
CSHA1::Final();
|
||||
|
||||
CSHA1::GetHash((UINT_8 *)SHA1_Key);
|
||||
}
|
||||
else
|
||||
memcpy(SHA1_Key, key, key_len);
|
||||
|
||||
/* STEP 2 */
|
||||
for (size_t i=0; i<sizeof(m_ipad); i++)
|
||||
{
|
||||
m_ipad[i] ^= SHA1_Key[i];
|
||||
}
|
||||
|
||||
/* STEP 3 */
|
||||
memcpy(AppendBuf1, m_ipad, sizeof(m_ipad));
|
||||
memcpy(AppendBuf1 + sizeof(m_ipad), text, text_len);
|
||||
|
||||
/* STEP 4 */
|
||||
CSHA1::Reset();
|
||||
CSHA1::Update((UINT_8 *)AppendBuf1, sizeof(m_ipad) + text_len);
|
||||
CSHA1::Final();
|
||||
|
||||
CSHA1::GetHash((UINT_8 *)szReport);
|
||||
|
||||
/* STEP 5 */
|
||||
for (size_t j=0; j<sizeof(m_opad); j++)
|
||||
{
|
||||
m_opad[j] ^= SHA1_Key[j];
|
||||
}
|
||||
|
||||
/* STEP 6 */
|
||||
memcpy(AppendBuf2, m_opad, sizeof(m_opad));
|
||||
memcpy(AppendBuf2 + sizeof(m_opad), szReport, SHA1_DIGEST_LENGTH);
|
||||
|
||||
/*STEP 7 */
|
||||
CSHA1::Reset();
|
||||
CSHA1::Update((UINT_8 *)AppendBuf2, sizeof(m_opad) + SHA1_DIGEST_LENGTH);
|
||||
CSHA1::Final();
|
||||
|
||||
CSHA1::GetHash((UINT_8 *)digest);
|
||||
}
|
||||
//******************************************************************************
|
||||
//* HMAC_SHA1.cpp : Implementation of HMAC SHA1 algorithm
|
||||
//* Comfort to RFC 2104
|
||||
//*
|
||||
//******************************************************************************
|
||||
#include "HMAC_SHA1.h"
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
|
||||
|
||||
void CHMAC_SHA1::HMAC_SHA1(BYTE *text, int text_len, BYTE *key, int key_len, BYTE *digest)
|
||||
{
|
||||
memset(SHA1_Key, 0, SHA1_BLOCK_SIZE);
|
||||
|
||||
/* repeated 64 times for values in ipad and opad */
|
||||
memset(m_ipad, 0x36, sizeof(m_ipad));
|
||||
memset(m_opad, 0x5c, sizeof(m_opad));
|
||||
|
||||
/* STEP 1 */
|
||||
if (key_len > SHA1_BLOCK_SIZE)
|
||||
{
|
||||
CSHA1::Reset();
|
||||
CSHA1::Update((UINT_8 *)key, key_len);
|
||||
CSHA1::Final();
|
||||
|
||||
CSHA1::GetHash((UINT_8 *)SHA1_Key);
|
||||
}
|
||||
else
|
||||
memcpy(SHA1_Key, key, key_len);
|
||||
|
||||
/* STEP 2 */
|
||||
for (size_t i=0; i<sizeof(m_ipad); i++)
|
||||
{
|
||||
m_ipad[i] ^= SHA1_Key[i];
|
||||
}
|
||||
|
||||
/* STEP 3 */
|
||||
memcpy(AppendBuf1, m_ipad, sizeof(m_ipad));
|
||||
memcpy(AppendBuf1 + sizeof(m_ipad), text, text_len);
|
||||
|
||||
/* STEP 4 */
|
||||
CSHA1::Reset();
|
||||
CSHA1::Update((UINT_8 *)AppendBuf1, sizeof(m_ipad) + text_len);
|
||||
CSHA1::Final();
|
||||
|
||||
CSHA1::GetHash((UINT_8 *)szReport);
|
||||
|
||||
/* STEP 5 */
|
||||
for (size_t j=0; j<sizeof(m_opad); j++)
|
||||
{
|
||||
m_opad[j] ^= SHA1_Key[j];
|
||||
}
|
||||
|
||||
/* STEP 6 */
|
||||
memcpy(AppendBuf2, m_opad, sizeof(m_opad));
|
||||
memcpy(AppendBuf2 + sizeof(m_opad), szReport, SHA1_DIGEST_LENGTH);
|
||||
|
||||
/*STEP 7 */
|
||||
CSHA1::Reset();
|
||||
CSHA1::Update((UINT_8 *)AppendBuf2, sizeof(m_opad) + SHA1_DIGEST_LENGTH);
|
||||
CSHA1::Final();
|
||||
|
||||
CSHA1::GetHash((UINT_8 *)digest);
|
||||
}
|
||||
|
|
|
@ -1,53 +1,53 @@
|
|||
/*
|
||||
100% free public domain implementation of the HMAC-SHA1 algorithm
|
||||
by Chien-Chung, Chung (Jim Chung) <jimchung1221@gmail.com>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __HMAC_SHA1_H__
|
||||
#define __HMAC_SHA1_H__
|
||||
|
||||
#include "SHA1.h"
|
||||
|
||||
typedef unsigned char BYTE ;
|
||||
|
||||
class CHMAC_SHA1 : public CSHA1
|
||||
{
|
||||
private:
|
||||
BYTE m_ipad[64];
|
||||
BYTE m_opad[64];
|
||||
|
||||
char * szReport ;
|
||||
char * SHA1_Key ;
|
||||
char * AppendBuf1 ;
|
||||
char * AppendBuf2 ;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
enum {
|
||||
SHA1_DIGEST_LENGTH = 20,
|
||||
SHA1_BLOCK_SIZE = 64,
|
||||
HMAC_BUF_LEN = 4096
|
||||
} ;
|
||||
|
||||
CHMAC_SHA1()
|
||||
:szReport(new char[HMAC_BUF_LEN]),
|
||||
SHA1_Key(new char[HMAC_BUF_LEN]),
|
||||
AppendBuf1(new char[HMAC_BUF_LEN]),
|
||||
AppendBuf2(new char[HMAC_BUF_LEN])
|
||||
{}
|
||||
|
||||
~CHMAC_SHA1()
|
||||
{
|
||||
delete[] szReport ;
|
||||
delete[] AppendBuf1 ;
|
||||
delete[] AppendBuf2 ;
|
||||
delete[] SHA1_Key ;
|
||||
}
|
||||
|
||||
void HMAC_SHA1(BYTE *text, int text_len, BYTE *key, int key_len, BYTE *digest);
|
||||
};
|
||||
|
||||
|
||||
#endif /* __HMAC_SHA1_H__ */
|
||||
/*
|
||||
100% free public domain implementation of the HMAC-SHA1 algorithm
|
||||
by Chien-Chung, Chung (Jim Chung) <jimchung1221@gmail.com>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __HMAC_SHA1_H__
|
||||
#define __HMAC_SHA1_H__
|
||||
|
||||
#include "SHA1.h"
|
||||
|
||||
typedef unsigned char BYTE ;
|
||||
|
||||
class CHMAC_SHA1 : public CSHA1
|
||||
{
|
||||
private:
|
||||
BYTE m_ipad[64];
|
||||
BYTE m_opad[64];
|
||||
|
||||
char * szReport ;
|
||||
char * SHA1_Key ;
|
||||
char * AppendBuf1 ;
|
||||
char * AppendBuf2 ;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
enum {
|
||||
SHA1_DIGEST_LENGTH = 20,
|
||||
SHA1_BLOCK_SIZE = 64,
|
||||
HMAC_BUF_LEN = 4096
|
||||
} ;
|
||||
|
||||
CHMAC_SHA1()
|
||||
:szReport(new char[HMAC_BUF_LEN]),
|
||||
SHA1_Key(new char[HMAC_BUF_LEN]),
|
||||
AppendBuf1(new char[HMAC_BUF_LEN]),
|
||||
AppendBuf2(new char[HMAC_BUF_LEN])
|
||||
{}
|
||||
|
||||
~CHMAC_SHA1()
|
||||
{
|
||||
delete[] szReport ;
|
||||
delete[] AppendBuf1 ;
|
||||
delete[] AppendBuf2 ;
|
||||
delete[] SHA1_Key ;
|
||||
}
|
||||
|
||||
void HMAC_SHA1(BYTE *text, int text_len, BYTE *key, int key_len, BYTE *digest);
|
||||
};
|
||||
|
||||
|
||||
#endif /* __HMAC_SHA1_H__ */
|
||||
|
|
|
@ -1,274 +1,274 @@
|
|||
/*
|
||||
100% free public domain implementation of the SHA-1 algorithm
|
||||
by Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Web: http://www.dominik-reichl.de/
|
||||
|
||||
Version 1.6 - 2005-02-07 (thanks to Howard Kapustein for patches)
|
||||
- You can set the endianness in your files, no need to modify the
|
||||
header file of the CSHA1 class any more
|
||||
- Aligned data support
|
||||
- Made support/compilation of the utility functions (ReportHash
|
||||
and HashFile) optional (useful, if bytes count, for example in
|
||||
embedded environments)
|
||||
|
||||
Version 1.5 - 2005-01-01
|
||||
- 64-bit compiler compatibility added
|
||||
- Made variable wiping optional (define SHA1_WIPE_VARIABLES)
|
||||
- Removed unnecessary variable initializations
|
||||
- ROL32 improvement for the Microsoft compiler (using _rotl)
|
||||
|
||||
======== Test Vectors (from FIPS PUB 180-1) ========
|
||||
|
||||
SHA1("abc") =
|
||||
A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D
|
||||
|
||||
SHA1("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq") =
|
||||
84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1
|
||||
|
||||
SHA1(A million repetitions of "a") =
|
||||
34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F
|
||||
*/
|
||||
|
||||
#include "SHA1.h"
|
||||
|
||||
#ifdef SHA1_UTILITY_FUNCTIONS
|
||||
#define SHA1_MAX_FILE_BUFFER 8000
|
||||
#endif
|
||||
|
||||
// Rotate x bits to the left
|
||||
#ifndef ROL32
|
||||
#ifdef _MSC_VER
|
||||
#define ROL32(_val32, _nBits) _rotl(_val32, _nBits)
|
||||
#else
|
||||
#define ROL32(_val32, _nBits) (((_val32)<<(_nBits))|((_val32)>>(32-(_nBits))))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef SHA1_LITTLE_ENDIAN
|
||||
#define SHABLK0(i) (m_block->l[i] = \
|
||||
(ROL32(m_block->l[i],24) & 0xFF00FF00) | (ROL32(m_block->l[i],8) & 0x00FF00FF))
|
||||
#else
|
||||
#define SHABLK0(i) (m_block->l[i])
|
||||
#endif
|
||||
|
||||
#define SHABLK(i) (m_block->l[i&15] = ROL32(m_block->l[(i+13)&15] ^ m_block->l[(i+8)&15] \
|
||||
^ m_block->l[(i+2)&15] ^ m_block->l[i&15],1))
|
||||
|
||||
// SHA-1 rounds
|
||||
#define _R0(v,w,x,y,z,i) { z+=((w&(x^y))^y)+SHABLK0(i)+0x5A827999+ROL32(v,5); w=ROL32(w,30); }
|
||||
#define _R1(v,w,x,y,z,i) { z+=((w&(x^y))^y)+SHABLK(i)+0x5A827999+ROL32(v,5); w=ROL32(w,30); }
|
||||
#define _R2(v,w,x,y,z,i) { z+=(w^x^y)+SHABLK(i)+0x6ED9EBA1+ROL32(v,5); w=ROL32(w,30); }
|
||||
#define _R3(v,w,x,y,z,i) { z+=(((w|x)&y)|(w&x))+SHABLK(i)+0x8F1BBCDC+ROL32(v,5); w=ROL32(w,30); }
|
||||
#define _R4(v,w,x,y,z,i) { z+=(w^x^y)+SHABLK(i)+0xCA62C1D6+ROL32(v,5); w=ROL32(w,30); }
|
||||
|
||||
CSHA1::CSHA1()
|
||||
{
|
||||
m_block = (SHA1_WORKSPACE_BLOCK *)m_workspace;
|
||||
|
||||
Reset();
|
||||
}
|
||||
|
||||
CSHA1::~CSHA1()
|
||||
{
|
||||
Reset();
|
||||
}
|
||||
|
||||
void CSHA1::Reset()
|
||||
{
|
||||
// SHA1 initialization constants
|
||||
m_state[0] = 0x67452301;
|
||||
m_state[1] = 0xEFCDAB89;
|
||||
m_state[2] = 0x98BADCFE;
|
||||
m_state[3] = 0x10325476;
|
||||
m_state[4] = 0xC3D2E1F0;
|
||||
|
||||
m_count[0] = 0;
|
||||
m_count[1] = 0;
|
||||
}
|
||||
|
||||
void CSHA1::Transform(UINT_32 *state, UINT_8 *buffer)
|
||||
{
|
||||
// Copy state[] to working vars
|
||||
UINT_32 a = state[0], b = state[1], c = state[2], d = state[3], e = state[4];
|
||||
|
||||
memcpy(m_block, buffer, 64);
|
||||
|
||||
// 4 rounds of 20 operations each. Loop unrolled.
|
||||
_R0(a,b,c,d,e, 0); _R0(e,a,b,c,d, 1); _R0(d,e,a,b,c, 2); _R0(c,d,e,a,b, 3);
|
||||
_R0(b,c,d,e,a, 4); _R0(a,b,c,d,e, 5); _R0(e,a,b,c,d, 6); _R0(d,e,a,b,c, 7);
|
||||
_R0(c,d,e,a,b, 8); _R0(b,c,d,e,a, 9); _R0(a,b,c,d,e,10); _R0(e,a,b,c,d,11);
|
||||
_R0(d,e,a,b,c,12); _R0(c,d,e,a,b,13); _R0(b,c,d,e,a,14); _R0(a,b,c,d,e,15);
|
||||
_R1(e,a,b,c,d,16); _R1(d,e,a,b,c,17); _R1(c,d,e,a,b,18); _R1(b,c,d,e,a,19);
|
||||
_R2(a,b,c,d,e,20); _R2(e,a,b,c,d,21); _R2(d,e,a,b,c,22); _R2(c,d,e,a,b,23);
|
||||
_R2(b,c,d,e,a,24); _R2(a,b,c,d,e,25); _R2(e,a,b,c,d,26); _R2(d,e,a,b,c,27);
|
||||
_R2(c,d,e,a,b,28); _R2(b,c,d,e,a,29); _R2(a,b,c,d,e,30); _R2(e,a,b,c,d,31);
|
||||
_R2(d,e,a,b,c,32); _R2(c,d,e,a,b,33); _R2(b,c,d,e,a,34); _R2(a,b,c,d,e,35);
|
||||
_R2(e,a,b,c,d,36); _R2(d,e,a,b,c,37); _R2(c,d,e,a,b,38); _R2(b,c,d,e,a,39);
|
||||
_R3(a,b,c,d,e,40); _R3(e,a,b,c,d,41); _R3(d,e,a,b,c,42); _R3(c,d,e,a,b,43);
|
||||
_R3(b,c,d,e,a,44); _R3(a,b,c,d,e,45); _R3(e,a,b,c,d,46); _R3(d,e,a,b,c,47);
|
||||
_R3(c,d,e,a,b,48); _R3(b,c,d,e,a,49); _R3(a,b,c,d,e,50); _R3(e,a,b,c,d,51);
|
||||
_R3(d,e,a,b,c,52); _R3(c,d,e,a,b,53); _R3(b,c,d,e,a,54); _R3(a,b,c,d,e,55);
|
||||
_R3(e,a,b,c,d,56); _R3(d,e,a,b,c,57); _R3(c,d,e,a,b,58); _R3(b,c,d,e,a,59);
|
||||
_R4(a,b,c,d,e,60); _R4(e,a,b,c,d,61); _R4(d,e,a,b,c,62); _R4(c,d,e,a,b,63);
|
||||
_R4(b,c,d,e,a,64); _R4(a,b,c,d,e,65); _R4(e,a,b,c,d,66); _R4(d,e,a,b,c,67);
|
||||
_R4(c,d,e,a,b,68); _R4(b,c,d,e,a,69); _R4(a,b,c,d,e,70); _R4(e,a,b,c,d,71);
|
||||
_R4(d,e,a,b,c,72); _R4(c,d,e,a,b,73); _R4(b,c,d,e,a,74); _R4(a,b,c,d,e,75);
|
||||
_R4(e,a,b,c,d,76); _R4(d,e,a,b,c,77); _R4(c,d,e,a,b,78); _R4(b,c,d,e,a,79);
|
||||
|
||||
// Add the working vars back into state
|
||||
state[0] += a;
|
||||
state[1] += b;
|
||||
state[2] += c;
|
||||
state[3] += d;
|
||||
state[4] += e;
|
||||
|
||||
// Wipe variables
|
||||
#ifdef SHA1_WIPE_VARIABLES
|
||||
a = b = c = d = e = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
// Use this function to hash in binary data and strings
|
||||
void CSHA1::Update(UINT_8 *data, UINT_32 len)
|
||||
{
|
||||
UINT_32 i, j;
|
||||
|
||||
j = (m_count[0] >> 3) & 63;
|
||||
|
||||
if((m_count[0] += len << 3) < (len << 3)) m_count[1]++;
|
||||
|
||||
m_count[1] += (len >> 29);
|
||||
|
||||
if((j + len) > 63)
|
||||
{
|
||||
i = 64 - j;
|
||||
memcpy(&m_buffer[j], data, i);
|
||||
Transform(m_state, m_buffer);
|
||||
|
||||
for(; i + 63 < len; i += 64) Transform(m_state, &data[i]);
|
||||
|
||||
j = 0;
|
||||
}
|
||||
else i = 0;
|
||||
|
||||
memcpy(&m_buffer[j], &data[i], len - i);
|
||||
}
|
||||
|
||||
#ifdef SHA1_UTILITY_FUNCTIONS
|
||||
// Hash in file contents
|
||||
bool CSHA1::HashFile(char *szFileName)
|
||||
{
|
||||
unsigned long ulFileSize, ulRest, ulBlocks;
|
||||
unsigned long i;
|
||||
UINT_8 uData[SHA1_MAX_FILE_BUFFER];
|
||||
FILE *fIn;
|
||||
|
||||
if(szFileName == NULL) return false;
|
||||
|
||||
fIn = fopen(szFileName, "rb");
|
||||
if(fIn == NULL) return false;
|
||||
|
||||
fseek(fIn, 0, SEEK_END);
|
||||
ulFileSize = (unsigned long)ftell(fIn);
|
||||
fseek(fIn, 0, SEEK_SET);
|
||||
|
||||
if(ulFileSize != 0)
|
||||
{
|
||||
ulBlocks = ulFileSize / SHA1_MAX_FILE_BUFFER;
|
||||
ulRest = ulFileSize % SHA1_MAX_FILE_BUFFER;
|
||||
}
|
||||
else
|
||||
{
|
||||
ulBlocks = 0;
|
||||
ulRest = 0;
|
||||
}
|
||||
|
||||
for(i = 0; i < ulBlocks; i++)
|
||||
{
|
||||
fread(uData, 1, SHA1_MAX_FILE_BUFFER, fIn);
|
||||
Update((UINT_8 *)uData, SHA1_MAX_FILE_BUFFER);
|
||||
}
|
||||
|
||||
if(ulRest != 0)
|
||||
{
|
||||
fread(uData, 1, ulRest, fIn);
|
||||
Update((UINT_8 *)uData, ulRest);
|
||||
}
|
||||
|
||||
fclose(fIn); fIn = NULL;
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
void CSHA1::Final()
|
||||
{
|
||||
UINT_32 i;
|
||||
UINT_8 finalcount[8];
|
||||
|
||||
for(i = 0; i < 8; i++)
|
||||
finalcount[i] = (UINT_8)((m_count[((i >= 4) ? 0 : 1)]
|
||||
>> ((3 - (i & 3)) * 8) ) & 255); // Endian independent
|
||||
|
||||
Update((UINT_8 *)"\200", 1);
|
||||
|
||||
while ((m_count[0] & 504) != 448)
|
||||
Update((UINT_8 *)"\0", 1);
|
||||
|
||||
Update(finalcount, 8); // Cause a SHA1Transform()
|
||||
|
||||
for(i = 0; i < 20; i++)
|
||||
{
|
||||
m_digest[i] = (UINT_8)((m_state[i >> 2] >> ((3 - (i & 3)) * 8) ) & 255);
|
||||
}
|
||||
|
||||
// Wipe variables for security reasons
|
||||
#ifdef SHA1_WIPE_VARIABLES
|
||||
i = 0;
|
||||
memset(m_buffer, 0, 64);
|
||||
memset(m_state, 0, 20);
|
||||
memset(m_count, 0, 8);
|
||||
memset(finalcount, 0, 8);
|
||||
Transform(m_state, m_buffer);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef SHA1_UTILITY_FUNCTIONS
|
||||
// Get the final hash as a pre-formatted string
|
||||
void CSHA1::ReportHash(char *szReport, unsigned char uReportType)
|
||||
{
|
||||
unsigned char i;
|
||||
char szTemp[16];
|
||||
|
||||
if(szReport == NULL) return;
|
||||
|
||||
if(uReportType == REPORT_HEX)
|
||||
{
|
||||
sprintf(szTemp, "%02X", m_digest[0]);
|
||||
strcat(szReport, szTemp);
|
||||
|
||||
for(i = 1; i < 20; i++)
|
||||
{
|
||||
sprintf(szTemp, " %02X", m_digest[i]);
|
||||
strcat(szReport, szTemp);
|
||||
}
|
||||
}
|
||||
else if(uReportType == REPORT_DIGIT)
|
||||
{
|
||||
sprintf(szTemp, "%u", m_digest[0]);
|
||||
strcat(szReport, szTemp);
|
||||
|
||||
for(i = 1; i < 20; i++)
|
||||
{
|
||||
sprintf(szTemp, " %u", m_digest[i]);
|
||||
strcat(szReport, szTemp);
|
||||
}
|
||||
}
|
||||
else strcpy(szReport, "Error: Unknown report type!");
|
||||
}
|
||||
#endif
|
||||
|
||||
// Get the raw message digest
|
||||
void CSHA1::GetHash(UINT_8 *puDest)
|
||||
{
|
||||
memcpy(puDest, m_digest, 20);
|
||||
}
|
||||
/*
|
||||
100% free public domain implementation of the SHA-1 algorithm
|
||||
by Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Web: http://www.dominik-reichl.de/
|
||||
|
||||
Version 1.6 - 2005-02-07 (thanks to Howard Kapustein for patches)
|
||||
- You can set the endianness in your files, no need to modify the
|
||||
header file of the CSHA1 class any more
|
||||
- Aligned data support
|
||||
- Made support/compilation of the utility functions (ReportHash
|
||||
and HashFile) optional (useful, if bytes count, for example in
|
||||
embedded environments)
|
||||
|
||||
Version 1.5 - 2005-01-01
|
||||
- 64-bit compiler compatibility added
|
||||
- Made variable wiping optional (define SHA1_WIPE_VARIABLES)
|
||||
- Removed unnecessary variable initializations
|
||||
- ROL32 improvement for the Microsoft compiler (using _rotl)
|
||||
|
||||
======== Test Vectors (from FIPS PUB 180-1) ========
|
||||
|
||||
SHA1("abc") =
|
||||
A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D
|
||||
|
||||
SHA1("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq") =
|
||||
84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1
|
||||
|
||||
SHA1(A million repetitions of "a") =
|
||||
34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F
|
||||
*/
|
||||
|
||||
#include "SHA1.h"
|
||||
|
||||
#ifdef SHA1_UTILITY_FUNCTIONS
|
||||
#define SHA1_MAX_FILE_BUFFER 8000
|
||||
#endif
|
||||
|
||||
// Rotate x bits to the left
|
||||
#ifndef ROL32
|
||||
#ifdef _MSC_VER
|
||||
#define ROL32(_val32, _nBits) _rotl(_val32, _nBits)
|
||||
#else
|
||||
#define ROL32(_val32, _nBits) (((_val32)<<(_nBits))|((_val32)>>(32-(_nBits))))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef SHA1_LITTLE_ENDIAN
|
||||
#define SHABLK0(i) (m_block->l[i] = \
|
||||
(ROL32(m_block->l[i],24) & 0xFF00FF00) | (ROL32(m_block->l[i],8) & 0x00FF00FF))
|
||||
#else
|
||||
#define SHABLK0(i) (m_block->l[i])
|
||||
#endif
|
||||
|
||||
#define SHABLK(i) (m_block->l[i&15] = ROL32(m_block->l[(i+13)&15] ^ m_block->l[(i+8)&15] \
|
||||
^ m_block->l[(i+2)&15] ^ m_block->l[i&15],1))
|
||||
|
||||
// SHA-1 rounds
|
||||
#define _R0(v,w,x,y,z,i) { z+=((w&(x^y))^y)+SHABLK0(i)+0x5A827999+ROL32(v,5); w=ROL32(w,30); }
|
||||
#define _R1(v,w,x,y,z,i) { z+=((w&(x^y))^y)+SHABLK(i)+0x5A827999+ROL32(v,5); w=ROL32(w,30); }
|
||||
#define _R2(v,w,x,y,z,i) { z+=(w^x^y)+SHABLK(i)+0x6ED9EBA1+ROL32(v,5); w=ROL32(w,30); }
|
||||
#define _R3(v,w,x,y,z,i) { z+=(((w|x)&y)|(w&x))+SHABLK(i)+0x8F1BBCDC+ROL32(v,5); w=ROL32(w,30); }
|
||||
#define _R4(v,w,x,y,z,i) { z+=(w^x^y)+SHABLK(i)+0xCA62C1D6+ROL32(v,5); w=ROL32(w,30); }
|
||||
|
||||
CSHA1::CSHA1()
|
||||
{
|
||||
m_block = (SHA1_WORKSPACE_BLOCK *)m_workspace;
|
||||
|
||||
Reset();
|
||||
}
|
||||
|
||||
CSHA1::~CSHA1()
|
||||
{
|
||||
Reset();
|
||||
}
|
||||
|
||||
void CSHA1::Reset()
|
||||
{
|
||||
// SHA1 initialization constants
|
||||
m_state[0] = 0x67452301;
|
||||
m_state[1] = 0xEFCDAB89;
|
||||
m_state[2] = 0x98BADCFE;
|
||||
m_state[3] = 0x10325476;
|
||||
m_state[4] = 0xC3D2E1F0;
|
||||
|
||||
m_count[0] = 0;
|
||||
m_count[1] = 0;
|
||||
}
|
||||
|
||||
void CSHA1::Transform(UINT_32 *state, UINT_8 *buffer)
|
||||
{
|
||||
// Copy state[] to working vars
|
||||
UINT_32 a = state[0], b = state[1], c = state[2], d = state[3], e = state[4];
|
||||
|
||||
memcpy(m_block, buffer, 64);
|
||||
|
||||
// 4 rounds of 20 operations each. Loop unrolled.
|
||||
_R0(a,b,c,d,e, 0); _R0(e,a,b,c,d, 1); _R0(d,e,a,b,c, 2); _R0(c,d,e,a,b, 3);
|
||||
_R0(b,c,d,e,a, 4); _R0(a,b,c,d,e, 5); _R0(e,a,b,c,d, 6); _R0(d,e,a,b,c, 7);
|
||||
_R0(c,d,e,a,b, 8); _R0(b,c,d,e,a, 9); _R0(a,b,c,d,e,10); _R0(e,a,b,c,d,11);
|
||||
_R0(d,e,a,b,c,12); _R0(c,d,e,a,b,13); _R0(b,c,d,e,a,14); _R0(a,b,c,d,e,15);
|
||||
_R1(e,a,b,c,d,16); _R1(d,e,a,b,c,17); _R1(c,d,e,a,b,18); _R1(b,c,d,e,a,19);
|
||||
_R2(a,b,c,d,e,20); _R2(e,a,b,c,d,21); _R2(d,e,a,b,c,22); _R2(c,d,e,a,b,23);
|
||||
_R2(b,c,d,e,a,24); _R2(a,b,c,d,e,25); _R2(e,a,b,c,d,26); _R2(d,e,a,b,c,27);
|
||||
_R2(c,d,e,a,b,28); _R2(b,c,d,e,a,29); _R2(a,b,c,d,e,30); _R2(e,a,b,c,d,31);
|
||||
_R2(d,e,a,b,c,32); _R2(c,d,e,a,b,33); _R2(b,c,d,e,a,34); _R2(a,b,c,d,e,35);
|
||||
_R2(e,a,b,c,d,36); _R2(d,e,a,b,c,37); _R2(c,d,e,a,b,38); _R2(b,c,d,e,a,39);
|
||||
_R3(a,b,c,d,e,40); _R3(e,a,b,c,d,41); _R3(d,e,a,b,c,42); _R3(c,d,e,a,b,43);
|
||||
_R3(b,c,d,e,a,44); _R3(a,b,c,d,e,45); _R3(e,a,b,c,d,46); _R3(d,e,a,b,c,47);
|
||||
_R3(c,d,e,a,b,48); _R3(b,c,d,e,a,49); _R3(a,b,c,d,e,50); _R3(e,a,b,c,d,51);
|
||||
_R3(d,e,a,b,c,52); _R3(c,d,e,a,b,53); _R3(b,c,d,e,a,54); _R3(a,b,c,d,e,55);
|
||||
_R3(e,a,b,c,d,56); _R3(d,e,a,b,c,57); _R3(c,d,e,a,b,58); _R3(b,c,d,e,a,59);
|
||||
_R4(a,b,c,d,e,60); _R4(e,a,b,c,d,61); _R4(d,e,a,b,c,62); _R4(c,d,e,a,b,63);
|
||||
_R4(b,c,d,e,a,64); _R4(a,b,c,d,e,65); _R4(e,a,b,c,d,66); _R4(d,e,a,b,c,67);
|
||||
_R4(c,d,e,a,b,68); _R4(b,c,d,e,a,69); _R4(a,b,c,d,e,70); _R4(e,a,b,c,d,71);
|
||||
_R4(d,e,a,b,c,72); _R4(c,d,e,a,b,73); _R4(b,c,d,e,a,74); _R4(a,b,c,d,e,75);
|
||||
_R4(e,a,b,c,d,76); _R4(d,e,a,b,c,77); _R4(c,d,e,a,b,78); _R4(b,c,d,e,a,79);
|
||||
|
||||
// Add the working vars back into state
|
||||
state[0] += a;
|
||||
state[1] += b;
|
||||
state[2] += c;
|
||||
state[3] += d;
|
||||
state[4] += e;
|
||||
|
||||
// Wipe variables
|
||||
#ifdef SHA1_WIPE_VARIABLES
|
||||
a = b = c = d = e = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
// Use this function to hash in binary data and strings
|
||||
void CSHA1::Update(UINT_8 *data, UINT_32 len)
|
||||
{
|
||||
UINT_32 i, j;
|
||||
|
||||
j = (m_count[0] >> 3) & 63;
|
||||
|
||||
if((m_count[0] += len << 3) < (len << 3)) m_count[1]++;
|
||||
|
||||
m_count[1] += (len >> 29);
|
||||
|
||||
if((j + len) > 63)
|
||||
{
|
||||
i = 64 - j;
|
||||
memcpy(&m_buffer[j], data, i);
|
||||
Transform(m_state, m_buffer);
|
||||
|
||||
for(; i + 63 < len; i += 64) Transform(m_state, &data[i]);
|
||||
|
||||
j = 0;
|
||||
}
|
||||
else i = 0;
|
||||
|
||||
memcpy(&m_buffer[j], &data[i], len - i);
|
||||
}
|
||||
|
||||
#ifdef SHA1_UTILITY_FUNCTIONS
|
||||
// Hash in file contents
|
||||
bool CSHA1::HashFile(char *szFileName)
|
||||
{
|
||||
unsigned long ulFileSize, ulRest, ulBlocks;
|
||||
unsigned long i;
|
||||
UINT_8 uData[SHA1_MAX_FILE_BUFFER];
|
||||
FILE *fIn;
|
||||
|
||||
if(szFileName == NULL) return false;
|
||||
|
||||
fIn = fopen(szFileName, "rb");
|
||||
if(fIn == NULL) return false;
|
||||
|
||||
fseek(fIn, 0, SEEK_END);
|
||||
ulFileSize = (unsigned long)ftell(fIn);
|
||||
fseek(fIn, 0, SEEK_SET);
|
||||
|
||||
if(ulFileSize != 0)
|
||||
{
|
||||
ulBlocks = ulFileSize / SHA1_MAX_FILE_BUFFER;
|
||||
ulRest = ulFileSize % SHA1_MAX_FILE_BUFFER;
|
||||
}
|
||||
else
|
||||
{
|
||||
ulBlocks = 0;
|
||||
ulRest = 0;
|
||||
}
|
||||
|
||||
for(i = 0; i < ulBlocks; i++)
|
||||
{
|
||||
fread(uData, 1, SHA1_MAX_FILE_BUFFER, fIn);
|
||||
Update((UINT_8 *)uData, SHA1_MAX_FILE_BUFFER);
|
||||
}
|
||||
|
||||
if(ulRest != 0)
|
||||
{
|
||||
fread(uData, 1, ulRest, fIn);
|
||||
Update((UINT_8 *)uData, ulRest);
|
||||
}
|
||||
|
||||
fclose(fIn); fIn = NULL;
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
void CSHA1::Final()
|
||||
{
|
||||
UINT_32 i;
|
||||
UINT_8 finalcount[8];
|
||||
|
||||
for(i = 0; i < 8; i++)
|
||||
finalcount[i] = (UINT_8)((m_count[((i >= 4) ? 0 : 1)]
|
||||
>> ((3 - (i & 3)) * 8) ) & 255); // Endian independent
|
||||
|
||||
Update((UINT_8 *)"\200", 1);
|
||||
|
||||
while ((m_count[0] & 504) != 448)
|
||||
Update((UINT_8 *)"\0", 1);
|
||||
|
||||
Update(finalcount, 8); // Cause a SHA1Transform()
|
||||
|
||||
for(i = 0; i < 20; i++)
|
||||
{
|
||||
m_digest[i] = (UINT_8)((m_state[i >> 2] >> ((3 - (i & 3)) * 8) ) & 255);
|
||||
}
|
||||
|
||||
// Wipe variables for security reasons
|
||||
#ifdef SHA1_WIPE_VARIABLES
|
||||
i = 0;
|
||||
memset(m_buffer, 0, 64);
|
||||
memset(m_state, 0, 20);
|
||||
memset(m_count, 0, 8);
|
||||
memset(finalcount, 0, 8);
|
||||
Transform(m_state, m_buffer);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef SHA1_UTILITY_FUNCTIONS
|
||||
// Get the final hash as a pre-formatted string
|
||||
void CSHA1::ReportHash(char *szReport, unsigned char uReportType)
|
||||
{
|
||||
unsigned char i;
|
||||
char szTemp[16];
|
||||
|
||||
if(szReport == NULL) return;
|
||||
|
||||
if(uReportType == REPORT_HEX)
|
||||
{
|
||||
sprintf(szTemp, "%02X", m_digest[0]);
|
||||
strcat(szReport, szTemp);
|
||||
|
||||
for(i = 1; i < 20; i++)
|
||||
{
|
||||
sprintf(szTemp, " %02X", m_digest[i]);
|
||||
strcat(szReport, szTemp);
|
||||
}
|
||||
}
|
||||
else if(uReportType == REPORT_DIGIT)
|
||||
{
|
||||
sprintf(szTemp, "%u", m_digest[0]);
|
||||
strcat(szReport, szTemp);
|
||||
|
||||
for(i = 1; i < 20; i++)
|
||||
{
|
||||
sprintf(szTemp, " %u", m_digest[i]);
|
||||
strcat(szReport, szTemp);
|
||||
}
|
||||
}
|
||||
else strcpy(szReport, "Error: Unknown report type!");
|
||||
}
|
||||
#endif
|
||||
|
||||
// Get the raw message digest
|
||||
void CSHA1::GetHash(UINT_8 *puDest)
|
||||
{
|
||||
memcpy(puDest, m_digest, 20);
|
||||
}
|
||||
|
|
|
@ -1,148 +1,148 @@
|
|||
/*
|
||||
100% free public domain implementation of the SHA-1 algorithm
|
||||
by Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Web: http://www.dominik-reichl.de/
|
||||
|
||||
Version 1.6 - 2005-02-07 (thanks to Howard Kapustein for patches)
|
||||
- You can set the endianness in your files, no need to modify the
|
||||
header file of the CSHA1 class any more
|
||||
- Aligned data support
|
||||
- Made support/compilation of the utility functions (ReportHash
|
||||
and HashFile) optional (useful, if bytes count, for example in
|
||||
embedded environments)
|
||||
|
||||
Version 1.5 - 2005-01-01
|
||||
- 64-bit compiler compatibility added
|
||||
- Made variable wiping optional (define SHA1_WIPE_VARIABLES)
|
||||
- Removed unnecessary variable initializations
|
||||
- ROL32 improvement for the Microsoft compiler (using _rotl)
|
||||
|
||||
======== Test Vectors (from FIPS PUB 180-1) ========
|
||||
|
||||
SHA1("abc") =
|
||||
A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D
|
||||
|
||||
SHA1("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq") =
|
||||
84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1
|
||||
|
||||
SHA1(A million repetitions of "a") =
|
||||
34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F
|
||||
*/
|
||||
|
||||
#ifndef ___SHA1_HDR___
|
||||
#define ___SHA1_HDR___
|
||||
|
||||
#if !defined(SHA1_UTILITY_FUNCTIONS) && !defined(SHA1_NO_UTILITY_FUNCTIONS)
|
||||
#define SHA1_UTILITY_FUNCTIONS
|
||||
#endif
|
||||
|
||||
#include <memory.h> // Needed for memset and memcpy
|
||||
|
||||
#ifdef SHA1_UTILITY_FUNCTIONS
|
||||
#include <stdio.h> // Needed for file access and sprintf
|
||||
#include <string.h> // Needed for strcat and strcpy
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
// You can define the endian mode in your files, without modifying the SHA1
|
||||
// source files. Just #define SHA1_LITTLE_ENDIAN or #define SHA1_BIG_ENDIAN
|
||||
// in your files, before including the SHA1.h header file. If you don't
|
||||
// define anything, the class defaults to little endian.
|
||||
|
||||
#if !defined(SHA1_LITTLE_ENDIAN) && !defined(SHA1_BIG_ENDIAN)
|
||||
#define SHA1_LITTLE_ENDIAN
|
||||
#endif
|
||||
|
||||
// Same here. If you want variable wiping, #define SHA1_WIPE_VARIABLES, if
|
||||
// not, #define SHA1_NO_WIPE_VARIABLES. If you don't define anything, it
|
||||
// defaults to wiping.
|
||||
|
||||
#if !defined(SHA1_WIPE_VARIABLES) && !defined(SHA1_NO_WIPE_VARIABLES)
|
||||
#define SHA1_WIPE_VARIABLES
|
||||
#endif
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Define 8- and 32-bit variables
|
||||
|
||||
#ifndef UINT_32
|
||||
|
||||
#ifdef _MSC_VER
|
||||
|
||||
#define UINT_8 unsigned __int8
|
||||
#define UINT_32 unsigned __int32
|
||||
|
||||
#else
|
||||
|
||||
#define UINT_8 unsigned char
|
||||
|
||||
#if (ULONG_MAX == 0xFFFFFFFF)
|
||||
#define UINT_32 unsigned long
|
||||
#else
|
||||
#define UINT_32 unsigned int
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Declare SHA1 workspace
|
||||
|
||||
typedef union
|
||||
{
|
||||
UINT_8 c[64];
|
||||
UINT_32 l[16];
|
||||
} SHA1_WORKSPACE_BLOCK;
|
||||
|
||||
class CSHA1
|
||||
{
|
||||
public:
|
||||
#ifdef SHA1_UTILITY_FUNCTIONS
|
||||
// Two different formats for ReportHash(...)
|
||||
enum
|
||||
{
|
||||
REPORT_HEX = 0,
|
||||
REPORT_DIGIT = 1
|
||||
};
|
||||
#endif
|
||||
|
||||
// Constructor and Destructor
|
||||
CSHA1();
|
||||
~CSHA1();
|
||||
|
||||
UINT_32 m_state[5];
|
||||
UINT_32 m_count[2];
|
||||
UINT_32 __reserved1[1];
|
||||
UINT_8 m_buffer[64];
|
||||
UINT_8 m_digest[20];
|
||||
UINT_32 __reserved2[3];
|
||||
|
||||
void Reset();
|
||||
|
||||
// Update the hash value
|
||||
void Update(UINT_8 *data, UINT_32 len);
|
||||
#ifdef SHA1_UTILITY_FUNCTIONS
|
||||
bool HashFile(char *szFileName);
|
||||
#endif
|
||||
|
||||
// Finalize hash and report
|
||||
void Final();
|
||||
|
||||
// Report functions: as pre-formatted and raw data
|
||||
#ifdef SHA1_UTILITY_FUNCTIONS
|
||||
void ReportHash(char *szReport, unsigned char uReportType = REPORT_HEX);
|
||||
#endif
|
||||
void GetHash(UINT_8 *puDest);
|
||||
|
||||
private:
|
||||
// Private SHA-1 transformation
|
||||
void Transform(UINT_32 *state, UINT_8 *buffer);
|
||||
|
||||
// Member variables
|
||||
UINT_8 m_workspace[64];
|
||||
SHA1_WORKSPACE_BLOCK *m_block; // SHA1 pointer to the byte array above
|
||||
};
|
||||
|
||||
#endif
|
||||
/*
|
||||
100% free public domain implementation of the SHA-1 algorithm
|
||||
by Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Web: http://www.dominik-reichl.de/
|
||||
|
||||
Version 1.6 - 2005-02-07 (thanks to Howard Kapustein for patches)
|
||||
- You can set the endianness in your files, no need to modify the
|
||||
header file of the CSHA1 class any more
|
||||
- Aligned data support
|
||||
- Made support/compilation of the utility functions (ReportHash
|
||||
and HashFile) optional (useful, if bytes count, for example in
|
||||
embedded environments)
|
||||
|
||||
Version 1.5 - 2005-01-01
|
||||
- 64-bit compiler compatibility added
|
||||
- Made variable wiping optional (define SHA1_WIPE_VARIABLES)
|
||||
- Removed unnecessary variable initializations
|
||||
- ROL32 improvement for the Microsoft compiler (using _rotl)
|
||||
|
||||
======== Test Vectors (from FIPS PUB 180-1) ========
|
||||
|
||||
SHA1("abc") =
|
||||
A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D
|
||||
|
||||
SHA1("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq") =
|
||||
84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1
|
||||
|
||||
SHA1(A million repetitions of "a") =
|
||||
34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F
|
||||
*/
|
||||
|
||||
#ifndef ___SHA1_HDR___
|
||||
#define ___SHA1_HDR___
|
||||
|
||||
#if !defined(SHA1_UTILITY_FUNCTIONS) && !defined(SHA1_NO_UTILITY_FUNCTIONS)
|
||||
#define SHA1_UTILITY_FUNCTIONS
|
||||
#endif
|
||||
|
||||
#include <memory.h> // Needed for memset and memcpy
|
||||
|
||||
#ifdef SHA1_UTILITY_FUNCTIONS
|
||||
#include <stdio.h> // Needed for file access and sprintf
|
||||
#include <string.h> // Needed for strcat and strcpy
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
// You can define the endian mode in your files, without modifying the SHA1
|
||||
// source files. Just #define SHA1_LITTLE_ENDIAN or #define SHA1_BIG_ENDIAN
|
||||
// in your files, before including the SHA1.h header file. If you don't
|
||||
// define anything, the class defaults to little endian.
|
||||
|
||||
#if !defined(SHA1_LITTLE_ENDIAN) && !defined(SHA1_BIG_ENDIAN)
|
||||
#define SHA1_LITTLE_ENDIAN
|
||||
#endif
|
||||
|
||||
// Same here. If you want variable wiping, #define SHA1_WIPE_VARIABLES, if
|
||||
// not, #define SHA1_NO_WIPE_VARIABLES. If you don't define anything, it
|
||||
// defaults to wiping.
|
||||
|
||||
#if !defined(SHA1_WIPE_VARIABLES) && !defined(SHA1_NO_WIPE_VARIABLES)
|
||||
#define SHA1_WIPE_VARIABLES
|
||||
#endif
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Define 8- and 32-bit variables
|
||||
|
||||
#ifndef UINT_32
|
||||
|
||||
#ifdef _MSC_VER
|
||||
|
||||
#define UINT_8 unsigned __int8
|
||||
#define UINT_32 unsigned __int32
|
||||
|
||||
#else
|
||||
|
||||
#define UINT_8 unsigned char
|
||||
|
||||
#if (ULONG_MAX == 0xFFFFFFFF)
|
||||
#define UINT_32 unsigned long
|
||||
#else
|
||||
#define UINT_32 unsigned int
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Declare SHA1 workspace
|
||||
|
||||
typedef union
|
||||
{
|
||||
UINT_8 c[64];
|
||||
UINT_32 l[16];
|
||||
} SHA1_WORKSPACE_BLOCK;
|
||||
|
||||
class CSHA1
|
||||
{
|
||||
public:
|
||||
#ifdef SHA1_UTILITY_FUNCTIONS
|
||||
// Two different formats for ReportHash(...)
|
||||
enum
|
||||
{
|
||||
REPORT_HEX = 0,
|
||||
REPORT_DIGIT = 1
|
||||
};
|
||||
#endif
|
||||
|
||||
// Constructor and Destructor
|
||||
CSHA1();
|
||||
~CSHA1();
|
||||
|
||||
UINT_32 m_state[5];
|
||||
UINT_32 m_count[2];
|
||||
UINT_32 __reserved1[1];
|
||||
UINT_8 m_buffer[64];
|
||||
UINT_8 m_digest[20];
|
||||
UINT_32 __reserved2[3];
|
||||
|
||||
void Reset();
|
||||
|
||||
// Update the hash value
|
||||
void Update(UINT_8 *data, UINT_32 len);
|
||||
#ifdef SHA1_UTILITY_FUNCTIONS
|
||||
bool HashFile(char *szFileName);
|
||||
#endif
|
||||
|
||||
// Finalize hash and report
|
||||
void Final();
|
||||
|
||||
// Report functions: as pre-formatted and raw data
|
||||
#ifdef SHA1_UTILITY_FUNCTIONS
|
||||
void ReportHash(char *szReport, unsigned char uReportType = REPORT_HEX);
|
||||
#endif
|
||||
void GetHash(UINT_8 *puDest);
|
||||
|
||||
private:
|
||||
// Private SHA-1 transformation
|
||||
void Transform(UINT_32 *state, UINT_8 *buffer);
|
||||
|
||||
// Member variables
|
||||
UINT_8 m_workspace[64];
|
||||
SHA1_WORKSPACE_BLOCK *m_block; // SHA1 pointer to the byte array above
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,123 +1,123 @@
|
|||
/*
|
||||
base64.cpp and base64.h
|
||||
|
||||
Copyright (C) 2004-2008 René Nyffenegger
|
||||
|
||||
This source code is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the author be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this source code must not be misrepresented; you must not
|
||||
claim that you wrote the original source code. If you use this source code
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original source code.
|
||||
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
René Nyffenegger rene.nyffenegger@adp-gmbh.ch
|
||||
|
||||
*/
|
||||
|
||||
#include "base64.h"
|
||||
#include <iostream>
|
||||
|
||||
static const std::string base64_chars =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
"abcdefghijklmnopqrstuvwxyz"
|
||||
"0123456789+/";
|
||||
|
||||
|
||||
static inline bool is_base64(unsigned char c) {
|
||||
return (isalnum(c) || (c == '+') || (c == '/'));
|
||||
}
|
||||
|
||||
std::string base64_encode(unsigned char const* bytes_to_encode, unsigned int in_len) {
|
||||
std::string ret;
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
unsigned char char_array_3[3];
|
||||
unsigned char char_array_4[4];
|
||||
|
||||
while (in_len--) {
|
||||
char_array_3[i++] = *(bytes_to_encode++);
|
||||
if (i == 3) {
|
||||
char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
|
||||
char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
|
||||
char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
|
||||
char_array_4[3] = char_array_3[2] & 0x3f;
|
||||
|
||||
for(i = 0; (i <4) ; i++)
|
||||
ret += base64_chars[char_array_4[i]];
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (i)
|
||||
{
|
||||
for(j = i; j < 3; j++)
|
||||
char_array_3[j] = '\0';
|
||||
|
||||
char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
|
||||
char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
|
||||
char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
|
||||
char_array_4[3] = char_array_3[2] & 0x3f;
|
||||
|
||||
for (j = 0; (j < i + 1); j++)
|
||||
ret += base64_chars[char_array_4[j]];
|
||||
|
||||
while((i++ < 3))
|
||||
ret += '=';
|
||||
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
std::string base64_decode(std::string const& encoded_string) {
|
||||
int in_len = encoded_string.size();
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
int in_ = 0;
|
||||
unsigned char char_array_4[4], char_array_3[3];
|
||||
std::string ret;
|
||||
|
||||
while (in_len-- && ( encoded_string[in_] != '=') && is_base64(encoded_string[in_])) {
|
||||
char_array_4[i++] = encoded_string[in_]; in_++;
|
||||
if (i ==4) {
|
||||
for (i = 0; i <4; i++)
|
||||
char_array_4[i] = base64_chars.find(char_array_4[i]);
|
||||
|
||||
char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
|
||||
char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
|
||||
char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
|
||||
|
||||
for (i = 0; (i < 3); i++)
|
||||
ret += char_array_3[i];
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (i) {
|
||||
for (j = i; j <4; j++)
|
||||
char_array_4[j] = 0;
|
||||
|
||||
for (j = 0; j <4; j++)
|
||||
char_array_4[j] = base64_chars.find(char_array_4[j]);
|
||||
|
||||
char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
|
||||
char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
|
||||
char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
|
||||
|
||||
for (j = 0; (j < i - 1); j++) ret += char_array_3[j];
|
||||
}
|
||||
|
||||
return ret;
|
||||
/*
|
||||
base64.cpp and base64.h
|
||||
|
||||
Copyright (C) 2004-2008 René Nyffenegger
|
||||
|
||||
This source code is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the author be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this source code must not be misrepresented; you must not
|
||||
claim that you wrote the original source code. If you use this source code
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original source code.
|
||||
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
René Nyffenegger rene.nyffenegger@adp-gmbh.ch
|
||||
|
||||
*/
|
||||
|
||||
#include "base64.h"
|
||||
#include <iostream>
|
||||
|
||||
static const std::string base64_chars =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
"abcdefghijklmnopqrstuvwxyz"
|
||||
"0123456789+/";
|
||||
|
||||
|
||||
static inline bool is_base64(unsigned char c) {
|
||||
return (isalnum(c) || (c == '+') || (c == '/'));
|
||||
}
|
||||
|
||||
std::string base64_encode(unsigned char const* bytes_to_encode, unsigned int in_len) {
|
||||
std::string ret;
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
unsigned char char_array_3[3];
|
||||
unsigned char char_array_4[4];
|
||||
|
||||
while (in_len--) {
|
||||
char_array_3[i++] = *(bytes_to_encode++);
|
||||
if (i == 3) {
|
||||
char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
|
||||
char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
|
||||
char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
|
||||
char_array_4[3] = char_array_3[2] & 0x3f;
|
||||
|
||||
for(i = 0; (i <4) ; i++)
|
||||
ret += base64_chars[char_array_4[i]];
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (i)
|
||||
{
|
||||
for(j = i; j < 3; j++)
|
||||
char_array_3[j] = '\0';
|
||||
|
||||
char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
|
||||
char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
|
||||
char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
|
||||
char_array_4[3] = char_array_3[2] & 0x3f;
|
||||
|
||||
for (j = 0; (j < i + 1); j++)
|
||||
ret += base64_chars[char_array_4[j]];
|
||||
|
||||
while((i++ < 3))
|
||||
ret += '=';
|
||||
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
std::string base64_decode(std::string const& encoded_string) {
|
||||
int in_len = encoded_string.size();
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
int in_ = 0;
|
||||
unsigned char char_array_4[4], char_array_3[3];
|
||||
std::string ret;
|
||||
|
||||
while (in_len-- && ( encoded_string[in_] != '=') && is_base64(encoded_string[in_])) {
|
||||
char_array_4[i++] = encoded_string[in_]; in_++;
|
||||
if (i ==4) {
|
||||
for (i = 0; i <4; i++)
|
||||
char_array_4[i] = base64_chars.find(char_array_4[i]);
|
||||
|
||||
char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
|
||||
char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
|
||||
char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
|
||||
|
||||
for (i = 0; (i < 3); i++)
|
||||
ret += char_array_3[i];
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (i) {
|
||||
for (j = i; j <4; j++)
|
||||
char_array_4[j] = 0;
|
||||
|
||||
for (j = 0; j <4; j++)
|
||||
char_array_4[j] = base64_chars.find(char_array_4[j]);
|
||||
|
||||
char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
|
||||
char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
|
||||
char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
|
||||
|
||||
for (j = 0; (j < i - 1); j++) ret += char_array_3[j];
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
#include <string>
|
||||
|
||||
std::string base64_encode(unsigned char const* , unsigned int len);
|
||||
#include <string>
|
||||
|
||||
std::string base64_encode(unsigned char const* , unsigned int len);
|
||||
std::string base64_decode(std::string const& s);
|
File diff suppressed because it is too large
Load diff
|
@ -1,93 +1,93 @@
|
|||
#ifndef __OAUTHLIB_H__
|
||||
#define __OAUTHLIB_H__
|
||||
|
||||
#include "time.h"
|
||||
#include <cstdlib>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <map>
|
||||
|
||||
typedef enum _eOAuthHttpRequestType
|
||||
{
|
||||
eOAuthHttpInvalid = 0,
|
||||
eOAuthHttpGet,
|
||||
eOAuthHttpPost,
|
||||
eOAuthHttpDelete
|
||||
} eOAuthHttpRequestType;
|
||||
|
||||
typedef std::list<std::string> oAuthKeyValueList;
|
||||
typedef std::map<std::string, std::string> oAuthKeyValuePairs;
|
||||
|
||||
class oAuth
|
||||
{
|
||||
public:
|
||||
oAuth();
|
||||
~oAuth();
|
||||
|
||||
/* OAuth public methods used by twitCurl */
|
||||
void getConsumerKey( std::string& consumerKey /* out */ );
|
||||
void setConsumerKey( const std::string& consumerKey /* in */ );
|
||||
|
||||
void getConsumerSecret( std::string& consumerSecret /* out */ );
|
||||
void setConsumerSecret( const std::string& consumerSecret /* in */ );
|
||||
|
||||
void getOAuthTokenKey( std::string& oAuthTokenKey /* out */ );
|
||||
void setOAuthTokenKey( const std::string& oAuthTokenKey /* in */ );
|
||||
|
||||
void getOAuthTokenSecret( std::string& oAuthTokenSecret /* out */ );
|
||||
void setOAuthTokenSecret( const std::string& oAuthTokenSecret /* in */ );
|
||||
|
||||
void getOAuthScreenName( std::string& oAuthScreenName /* out */ );
|
||||
void setOAuthScreenName( const std::string& oAuthScreenName /* in */ );
|
||||
|
||||
void getOAuthPin( std::string& oAuthPin /* out */ );
|
||||
void setOAuthPin( const std::string& oAuthPin /* in */ );
|
||||
|
||||
bool getOAuthHeader( const eOAuthHttpRequestType eType, /* in */
|
||||
const std::string& rawUrl, /* in */
|
||||
const std::string& rawData, /* in */
|
||||
std::string& oAuthHttpHeader, /* out */
|
||||
const bool includeOAuthVerifierPin = false /* in */ );
|
||||
|
||||
bool extractOAuthTokenKeySecret( const std::string& requestTokenResponse /* in */ );
|
||||
|
||||
oAuth clone();
|
||||
|
||||
private:
|
||||
|
||||
/* OAuth data */
|
||||
std::string m_consumerKey;
|
||||
std::string m_consumerSecret;
|
||||
std::string m_oAuthTokenKey;
|
||||
std::string m_oAuthTokenSecret;
|
||||
std::string m_oAuthPin;
|
||||
std::string m_nonce;
|
||||
std::string m_timeStamp;
|
||||
std::string m_oAuthScreenName;
|
||||
|
||||
/* OAuth twitter related utility methods */
|
||||
void buildOAuthRawDataKeyValPairs( const std::string& rawData, /* in */
|
||||
bool urlencodeData, /* in */
|
||||
oAuthKeyValuePairs& rawDataKeyValuePairs /* out */ );
|
||||
|
||||
bool buildOAuthTokenKeyValuePairs( const bool includeOAuthVerifierPin, /* in */
|
||||
const std::string& oauthSignature, /* in */
|
||||
oAuthKeyValuePairs& keyValueMap /* out */,
|
||||
const bool generateTimestamp /* in */ );
|
||||
|
||||
bool getStringFromOAuthKeyValuePairs( const oAuthKeyValuePairs& rawParamMap, /* in */
|
||||
std::string& rawParams, /* out */
|
||||
const std::string& paramsSeperator /* in */ );
|
||||
|
||||
bool getSignature( const eOAuthHttpRequestType eType, /* in */
|
||||
const std::string& rawUrl, /* in */
|
||||
const oAuthKeyValuePairs& rawKeyValuePairs, /* in */
|
||||
std::string& oAuthSignature /* out */ );
|
||||
|
||||
void generateNonceTimeStamp();
|
||||
};
|
||||
|
||||
#endif // __OAUTHLIB_H__
|
||||
#ifndef __OAUTHLIB_H__
|
||||
#define __OAUTHLIB_H__
|
||||
|
||||
#include "time.h"
|
||||
#include <cstdlib>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <map>
|
||||
|
||||
typedef enum _eOAuthHttpRequestType
|
||||
{
|
||||
eOAuthHttpInvalid = 0,
|
||||
eOAuthHttpGet,
|
||||
eOAuthHttpPost,
|
||||
eOAuthHttpDelete
|
||||
} eOAuthHttpRequestType;
|
||||
|
||||
typedef std::list<std::string> oAuthKeyValueList;
|
||||
typedef std::map<std::string, std::string> oAuthKeyValuePairs;
|
||||
|
||||
class oAuth
|
||||
{
|
||||
public:
|
||||
oAuth();
|
||||
~oAuth();
|
||||
|
||||
/* OAuth public methods used by twitCurl */
|
||||
void getConsumerKey( std::string& consumerKey /* out */ );
|
||||
void setConsumerKey( const std::string& consumerKey /* in */ );
|
||||
|
||||
void getConsumerSecret( std::string& consumerSecret /* out */ );
|
||||
void setConsumerSecret( const std::string& consumerSecret /* in */ );
|
||||
|
||||
void getOAuthTokenKey( std::string& oAuthTokenKey /* out */ );
|
||||
void setOAuthTokenKey( const std::string& oAuthTokenKey /* in */ );
|
||||
|
||||
void getOAuthTokenSecret( std::string& oAuthTokenSecret /* out */ );
|
||||
void setOAuthTokenSecret( const std::string& oAuthTokenSecret /* in */ );
|
||||
|
||||
void getOAuthScreenName( std::string& oAuthScreenName /* out */ );
|
||||
void setOAuthScreenName( const std::string& oAuthScreenName /* in */ );
|
||||
|
||||
void getOAuthPin( std::string& oAuthPin /* out */ );
|
||||
void setOAuthPin( const std::string& oAuthPin /* in */ );
|
||||
|
||||
bool getOAuthHeader( const eOAuthHttpRequestType eType, /* in */
|
||||
const std::string& rawUrl, /* in */
|
||||
const std::string& rawData, /* in */
|
||||
std::string& oAuthHttpHeader, /* out */
|
||||
const bool includeOAuthVerifierPin = false /* in */ );
|
||||
|
||||
bool extractOAuthTokenKeySecret( const std::string& requestTokenResponse /* in */ );
|
||||
|
||||
oAuth clone();
|
||||
|
||||
private:
|
||||
|
||||
/* OAuth data */
|
||||
std::string m_consumerKey;
|
||||
std::string m_consumerSecret;
|
||||
std::string m_oAuthTokenKey;
|
||||
std::string m_oAuthTokenSecret;
|
||||
std::string m_oAuthPin;
|
||||
std::string m_nonce;
|
||||
std::string m_timeStamp;
|
||||
std::string m_oAuthScreenName;
|
||||
|
||||
/* OAuth twitter related utility methods */
|
||||
void buildOAuthRawDataKeyValPairs( const std::string& rawData, /* in */
|
||||
bool urlencodeData, /* in */
|
||||
oAuthKeyValuePairs& rawDataKeyValuePairs /* out */ );
|
||||
|
||||
bool buildOAuthTokenKeyValuePairs( const bool includeOAuthVerifierPin, /* in */
|
||||
const std::string& oauthSignature, /* in */
|
||||
oAuthKeyValuePairs& keyValueMap /* out */,
|
||||
const bool generateTimestamp /* in */ );
|
||||
|
||||
bool getStringFromOAuthKeyValuePairs( const oAuthKeyValuePairs& rawParamMap, /* in */
|
||||
std::string& rawParams, /* out */
|
||||
const std::string& paramsSeperator /* in */ );
|
||||
|
||||
bool getSignature( const eOAuthHttpRequestType eType, /* in */
|
||||
const std::string& rawUrl, /* in */
|
||||
const oAuthKeyValuePairs& rawKeyValuePairs, /* in */
|
||||
std::string& oAuthSignature /* out */ );
|
||||
|
||||
void generateNonceTimeStamp();
|
||||
};
|
||||
|
||||
#endif // __OAUTHLIB_H__
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,140 +1,140 @@
|
|||
# Microsoft Developer Studio Project File - Name="twitcurl" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Static Library" 0x0104
|
||||
|
||||
CFG=twitcurl - Win32 Debug
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "twitcurl.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "twitcurl.mak" CFG="twitcurl - Win32 Debug"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "twitcurl - Win32 Release" (based on "Win32 (x86) Static Library")
|
||||
!MESSAGE "twitcurl - Win32 Debug" (based on "Win32 (x86) Static Library")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "twitcurl - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Release"
|
||||
# PROP Intermediate_Dir "Release"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
|
||||
# ADD CPP /nologo /W3 /GX /O2 /I "./curl" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LIB32=link.exe -lib
|
||||
# ADD BASE LIB32 /nologo
|
||||
# ADD LIB32 /nologo
|
||||
|
||||
!ELSEIF "$(CFG)" == "twitcurl - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "Debug"
|
||||
# PROP BASE Intermediate_Dir "Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "Debug"
|
||||
# PROP Intermediate_Dir "Debug"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "./curl" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
|
||||
# ADD BASE RSC /l 0x409 /d "_DEBUG"
|
||||
# ADD RSC /l 0x409 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LIB32=link.exe -lib
|
||||
# ADD BASE LIB32 /nologo
|
||||
# ADD LIB32 /nologo
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "twitcurl - Win32 Release"
|
||||
# Name "twitcurl - Win32 Debug"
|
||||
# Begin Group "Source Files"
|
||||
|
||||
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\base64.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\HMAC_SHA1.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\oauthlib.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\SHA1.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\twitcurl.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\urlencode.cpp
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Header Files"
|
||||
|
||||
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\base64.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\HMAC_SHA1.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\oauthlib.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\SHA1.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\twitcurl.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\urlencode.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# End Target
|
||||
# End Project
|
||||
# Microsoft Developer Studio Project File - Name="twitcurl" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Static Library" 0x0104
|
||||
|
||||
CFG=twitcurl - Win32 Debug
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "twitcurl.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "twitcurl.mak" CFG="twitcurl - Win32 Debug"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "twitcurl - Win32 Release" (based on "Win32 (x86) Static Library")
|
||||
!MESSAGE "twitcurl - Win32 Debug" (based on "Win32 (x86) Static Library")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "twitcurl - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Release"
|
||||
# PROP Intermediate_Dir "Release"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
|
||||
# ADD CPP /nologo /W3 /GX /O2 /I "./curl" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LIB32=link.exe -lib
|
||||
# ADD BASE LIB32 /nologo
|
||||
# ADD LIB32 /nologo
|
||||
|
||||
!ELSEIF "$(CFG)" == "twitcurl - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "Debug"
|
||||
# PROP BASE Intermediate_Dir "Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "Debug"
|
||||
# PROP Intermediate_Dir "Debug"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "./curl" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
|
||||
# ADD BASE RSC /l 0x409 /d "_DEBUG"
|
||||
# ADD RSC /l 0x409 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LIB32=link.exe -lib
|
||||
# ADD BASE LIB32 /nologo
|
||||
# ADD LIB32 /nologo
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "twitcurl - Win32 Release"
|
||||
# Name "twitcurl - Win32 Debug"
|
||||
# Begin Group "Source Files"
|
||||
|
||||
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\base64.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\HMAC_SHA1.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\oauthlib.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\SHA1.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\twitcurl.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\urlencode.cpp
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Header Files"
|
||||
|
||||
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\base64.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\HMAC_SHA1.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\oauthlib.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\SHA1.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\twitcurl.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\urlencode.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# End Target
|
||||
# End Project
|
||||
|
|
|
@ -1,29 +1,29 @@
|
|||
Microsoft Developer Studio Workspace File, Format Version 6.00
|
||||
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "twitcurl"=.\twitcurl.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Global:
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<3>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Microsoft Developer Studio Workspace File, Format Version 6.00
|
||||
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "twitcurl"=.\twitcurl.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Global:
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<3>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
|
|
|
@ -1,190 +1,190 @@
|
|||
#ifndef _TWITCURL_H_
|
||||
#define _TWITCURL_H_
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
#include "oauthlib.h"
|
||||
#include "curl/curl.h"
|
||||
|
||||
/* Few common types used by twitCurl */
|
||||
namespace twitCurlTypes
|
||||
{
|
||||
typedef enum _eTwitCurlApiFormatType
|
||||
{
|
||||
eTwitCurlApiFormatJson = 0,
|
||||
eTwitCurlApiFormatXml,
|
||||
eTwitCurlApiFormatMax
|
||||
} eTwitCurlApiFormatType;
|
||||
|
||||
typedef enum _eTwitCurlProtocolType
|
||||
{
|
||||
eTwitCurlProtocolHttps = 0,
|
||||
eTwitCurlProtocolHttp,
|
||||
eTwitCurlProtocolMax
|
||||
} eTwitCurlProtocolType;
|
||||
};
|
||||
|
||||
/* twitCurl class */
|
||||
class twitCurl
|
||||
{
|
||||
public:
|
||||
twitCurl();
|
||||
~twitCurl();
|
||||
|
||||
/* Twitter OAuth authorization methods */
|
||||
oAuth& getOAuth();
|
||||
bool oAuthRequestToken( std::string& authorizeUrl /* out */ );
|
||||
bool oAuthAccessToken();
|
||||
bool oAuthHandlePIN( const std::string& authorizeUrl /* in */ );
|
||||
|
||||
/* Twitter login APIs, set once and forget */
|
||||
std::string& getTwitterUsername();
|
||||
std::string& getTwitterPassword();
|
||||
void setTwitterUsername( std::string& userName /* in */ );
|
||||
void setTwitterPassword( std::string& passWord /* in */ );
|
||||
|
||||
/* Twitter search APIs */
|
||||
bool search( std::string& searchQuery /* in */, std::string resultCount = "" /* in */ );
|
||||
|
||||
/* Twitter status APIs */
|
||||
bool statusUpdate( std::string& newStatus /* in */, std::string inReplyToStatusId = "" /* in */ );
|
||||
bool statusShowById( std::string& statusId /* in */ );
|
||||
bool statusDestroyById( std::string& statusId /* in */ );
|
||||
bool retweetById( std::string& statusId /* in */ );
|
||||
|
||||
/* Twitter timeline APIs */
|
||||
bool timelineHomeGet( std::string sinceId = "" /* in */ );
|
||||
bool timelinePublicGet();
|
||||
bool timelineFriendsGet();
|
||||
bool timelineUserGet( bool trimUser /* in */, bool includeRetweets /* in */,
|
||||
unsigned int tweetCount /* in */,
|
||||
std::string userInfo = "" /* in */,
|
||||
bool isUserId = false /* in */ );
|
||||
bool featuredUsersGet();
|
||||
bool mentionsGet( std::string sinceId = "" /* in */ );
|
||||
|
||||
/* Twitter user APIs */
|
||||
bool userLookup( std::vector<std::string> &userInfo /* in */, bool isUserId = false /* in */ );
|
||||
bool userGet( std::string& userInfo /* in */, bool isUserId = false /* in */ );
|
||||
bool friendsGet( std::string userInfo = "" /* in */, bool isUserId = false /* in */ );
|
||||
bool followersGet( std::string userInfo = "" /* in */, bool isUserId = false /* in */ );
|
||||
|
||||
/* Twitter direct message APIs */
|
||||
bool directMessageGet( std::string sinceId = "" /* in */ );
|
||||
bool directMessageSend( std::string& userInfo /* in */, std::string& dMsg /* in */, bool isUserId = false /* in */ );
|
||||
bool directMessageGetSent();
|
||||
bool directMessageDestroyById( std::string& dMsgId /* in */ );
|
||||
|
||||
/* Twitter friendships APIs */
|
||||
bool friendshipCreate( std::string& userInfo /* in */, bool isUserId = false /* in */ );
|
||||
bool friendshipDestroy( std::string& userInfo /* in */, bool isUserId = false /* in */ );
|
||||
bool friendshipShow( std::string& userInfo /* in */, bool isUserId = false /* in */ );
|
||||
|
||||
/* Twitter social graphs APIs */
|
||||
bool friendsIdsGet( std::string& nextCursor /* in */,
|
||||
std::string& userInfo /* in */, bool isUserId = false /* in */ );
|
||||
bool followersIdsGet( std::string& nextCursor /* in */,
|
||||
std::string& userInfo /* in */, bool isUserId = false /* in */ );
|
||||
|
||||
/* Twitter account APIs */
|
||||
bool accountRateLimitGet();
|
||||
bool accountVerifyCredGet();
|
||||
|
||||
/* Twitter favorites APIs */
|
||||
bool favoriteGet();
|
||||
bool favoriteCreate( std::string& statusId /* in */ );
|
||||
bool favoriteDestroy( std::string& statusId /* in */ );
|
||||
|
||||
/* Twitter block APIs */
|
||||
bool blockCreate( std::string& userInfo /* in */ );
|
||||
bool blockDestroy( std::string& userInfo /* in */ );
|
||||
bool blockListGet( std::string& nextCursor /* in */,
|
||||
bool includeEntities /* in */, bool skipStatus /* in */ );
|
||||
bool blockIdsGet( std::string& nextCursor /* in */, bool stringifyIds /* in */ );
|
||||
|
||||
/* Twitter search APIs */
|
||||
bool savedSearchGet();
|
||||
bool savedSearchCreate( std::string& query /* in */ );
|
||||
bool savedSearchShow( std::string& searchId /* in */ );
|
||||
bool savedSearchDestroy( std::string& searchId /* in */ );
|
||||
|
||||
/* Twitter trends APIs (JSON) */
|
||||
bool trendsGet();
|
||||
bool trendsDailyGet();
|
||||
bool trendsWeeklyGet();
|
||||
bool trendsCurrentGet();
|
||||
bool trendsAvailableGet();
|
||||
|
||||
/* cURL APIs */
|
||||
bool isCurlInit();
|
||||
void getLastWebResponse( std::string& outWebResp /* out */ );
|
||||
void getLastCurlError( std::string& outErrResp /* out */);
|
||||
|
||||
/* Internal cURL related methods */
|
||||
int saveLastWebResponse( char*& data, size_t size );
|
||||
|
||||
/* cURL proxy APIs */
|
||||
std::string& getProxyServerIp();
|
||||
std::string& getProxyServerPort();
|
||||
std::string& getProxyUserName();
|
||||
std::string& getProxyPassword();
|
||||
void setProxyServerIp( std::string& proxyServerIp /* in */ );
|
||||
void setProxyServerPort( std::string& proxyServerPort /* in */ );
|
||||
void setProxyUserName( std::string& proxyUserName /* in */ );
|
||||
void setProxyPassword( std::string& proxyPassword /* in */ );
|
||||
|
||||
/* Clones this object */
|
||||
twitCurl* clone();
|
||||
|
||||
private:
|
||||
/* cURL data */
|
||||
CURL* m_curlHandle;
|
||||
char* m_errorBuffer;
|
||||
std::string m_callbackData;
|
||||
|
||||
/* cURL flags */
|
||||
bool m_curlProxyParamsSet;
|
||||
bool m_curlLoginParamsSet;
|
||||
bool m_curlCallbackParamsSet;
|
||||
|
||||
/* cURL proxy data */
|
||||
std::string m_proxyServerIp;
|
||||
std::string m_proxyServerPort;
|
||||
std::string m_proxyUserName;
|
||||
std::string m_proxyPassword;
|
||||
|
||||
/* Twitter data */
|
||||
std::string m_twitterUsername;
|
||||
std::string m_twitterPassword;
|
||||
|
||||
/* Twitter API type */
|
||||
twitCurlTypes::eTwitCurlApiFormatType m_eApiFormatType;
|
||||
twitCurlTypes::eTwitCurlProtocolType m_eProtocolType;
|
||||
|
||||
/* OAuth data */
|
||||
oAuth m_oAuth;
|
||||
|
||||
/* Private methods */
|
||||
void clearCurlCallbackBuffers();
|
||||
void prepareCurlProxy();
|
||||
void prepareCurlCallback();
|
||||
void prepareCurlUserPass();
|
||||
void prepareStandardParams();
|
||||
bool performGet( const std::string& getUrl );
|
||||
bool performGetInternal( const std::string& getUrl,
|
||||
const std::string& oAuthHttpHeader );
|
||||
bool performDelete( const std::string& deleteUrl );
|
||||
bool performPost( const std::string& postUrl, std::string dataStr = "" );
|
||||
|
||||
/* Internal cURL related methods */
|
||||
static int curlCallback( char* data, size_t size, size_t nmemb, twitCurl* pTwitCurlObj );
|
||||
};
|
||||
|
||||
|
||||
/* Private functions */
|
||||
void utilMakeCurlParams( std::string& outStr, std::string& inParam1, std::string& inParam2 );
|
||||
void utilMakeUrlForUser( std::string& outUrl, const std::string& baseUrl, std::string& userInfo, bool isUserId );
|
||||
|
||||
#endif // _TWITCURL_H_
|
||||
#ifndef _TWITCURL_H_
|
||||
#define _TWITCURL_H_
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
#include "oauthlib.h"
|
||||
#include "curl/curl.h"
|
||||
|
||||
/* Few common types used by twitCurl */
|
||||
namespace twitCurlTypes
|
||||
{
|
||||
typedef enum _eTwitCurlApiFormatType
|
||||
{
|
||||
eTwitCurlApiFormatJson = 0,
|
||||
eTwitCurlApiFormatXml,
|
||||
eTwitCurlApiFormatMax
|
||||
} eTwitCurlApiFormatType;
|
||||
|
||||
typedef enum _eTwitCurlProtocolType
|
||||
{
|
||||
eTwitCurlProtocolHttps = 0,
|
||||
eTwitCurlProtocolHttp,
|
||||
eTwitCurlProtocolMax
|
||||
} eTwitCurlProtocolType;
|
||||
};
|
||||
|
||||
/* twitCurl class */
|
||||
class twitCurl
|
||||
{
|
||||
public:
|
||||
twitCurl();
|
||||
~twitCurl();
|
||||
|
||||
/* Twitter OAuth authorization methods */
|
||||
oAuth& getOAuth();
|
||||
bool oAuthRequestToken( std::string& authorizeUrl /* out */ );
|
||||
bool oAuthAccessToken();
|
||||
bool oAuthHandlePIN( const std::string& authorizeUrl /* in */ );
|
||||
|
||||
/* Twitter login APIs, set once and forget */
|
||||
std::string& getTwitterUsername();
|
||||
std::string& getTwitterPassword();
|
||||
void setTwitterUsername( std::string& userName /* in */ );
|
||||
void setTwitterPassword( std::string& passWord /* in */ );
|
||||
|
||||
/* Twitter search APIs */
|
||||
bool search( std::string& searchQuery /* in */, std::string resultCount = "" /* in */ );
|
||||
|
||||
/* Twitter status APIs */
|
||||
bool statusUpdate( std::string& newStatus /* in */, std::string inReplyToStatusId = "" /* in */ );
|
||||
bool statusShowById( std::string& statusId /* in */ );
|
||||
bool statusDestroyById( std::string& statusId /* in */ );
|
||||
bool retweetById( std::string& statusId /* in */ );
|
||||
|
||||
/* Twitter timeline APIs */
|
||||
bool timelineHomeGet( std::string sinceId = "" /* in */ );
|
||||
bool timelinePublicGet();
|
||||
bool timelineFriendsGet();
|
||||
bool timelineUserGet( bool trimUser /* in */, bool includeRetweets /* in */,
|
||||
unsigned int tweetCount /* in */,
|
||||
std::string userInfo = "" /* in */,
|
||||
bool isUserId = false /* in */ );
|
||||
bool featuredUsersGet();
|
||||
bool mentionsGet( std::string sinceId = "" /* in */ );
|
||||
|
||||
/* Twitter user APIs */
|
||||
bool userLookup( std::vector<std::string> &userInfo /* in */, bool isUserId = false /* in */ );
|
||||
bool userGet( std::string& userInfo /* in */, bool isUserId = false /* in */ );
|
||||
bool friendsGet( std::string userInfo = "" /* in */, bool isUserId = false /* in */ );
|
||||
bool followersGet( std::string userInfo = "" /* in */, bool isUserId = false /* in */ );
|
||||
|
||||
/* Twitter direct message APIs */
|
||||
bool directMessageGet( std::string sinceId = "" /* in */ );
|
||||
bool directMessageSend( std::string& userInfo /* in */, std::string& dMsg /* in */, bool isUserId = false /* in */ );
|
||||
bool directMessageGetSent();
|
||||
bool directMessageDestroyById( std::string& dMsgId /* in */ );
|
||||
|
||||
/* Twitter friendships APIs */
|
||||
bool friendshipCreate( std::string& userInfo /* in */, bool isUserId = false /* in */ );
|
||||
bool friendshipDestroy( std::string& userInfo /* in */, bool isUserId = false /* in */ );
|
||||
bool friendshipShow( std::string& userInfo /* in */, bool isUserId = false /* in */ );
|
||||
|
||||
/* Twitter social graphs APIs */
|
||||
bool friendsIdsGet( std::string& nextCursor /* in */,
|
||||
std::string& userInfo /* in */, bool isUserId = false /* in */ );
|
||||
bool followersIdsGet( std::string& nextCursor /* in */,
|
||||
std::string& userInfo /* in */, bool isUserId = false /* in */ );
|
||||
|
||||
/* Twitter account APIs */
|
||||
bool accountRateLimitGet();
|
||||
bool accountVerifyCredGet();
|
||||
|
||||
/* Twitter favorites APIs */
|
||||
bool favoriteGet();
|
||||
bool favoriteCreate( std::string& statusId /* in */ );
|
||||
bool favoriteDestroy( std::string& statusId /* in */ );
|
||||
|
||||
/* Twitter block APIs */
|
||||
bool blockCreate( std::string& userInfo /* in */ );
|
||||
bool blockDestroy( std::string& userInfo /* in */ );
|
||||
bool blockListGet( std::string& nextCursor /* in */,
|
||||
bool includeEntities /* in */, bool skipStatus /* in */ );
|
||||
bool blockIdsGet( std::string& nextCursor /* in */, bool stringifyIds /* in */ );
|
||||
|
||||
/* Twitter search APIs */
|
||||
bool savedSearchGet();
|
||||
bool savedSearchCreate( std::string& query /* in */ );
|
||||
bool savedSearchShow( std::string& searchId /* in */ );
|
||||
bool savedSearchDestroy( std::string& searchId /* in */ );
|
||||
|
||||
/* Twitter trends APIs (JSON) */
|
||||
bool trendsGet();
|
||||
bool trendsDailyGet();
|
||||
bool trendsWeeklyGet();
|
||||
bool trendsCurrentGet();
|
||||
bool trendsAvailableGet();
|
||||
|
||||
/* cURL APIs */
|
||||
bool isCurlInit();
|
||||
void getLastWebResponse( std::string& outWebResp /* out */ );
|
||||
void getLastCurlError( std::string& outErrResp /* out */);
|
||||
|
||||
/* Internal cURL related methods */
|
||||
int saveLastWebResponse( char*& data, size_t size );
|
||||
|
||||
/* cURL proxy APIs */
|
||||
std::string& getProxyServerIp();
|
||||
std::string& getProxyServerPort();
|
||||
std::string& getProxyUserName();
|
||||
std::string& getProxyPassword();
|
||||
void setProxyServerIp( std::string& proxyServerIp /* in */ );
|
||||
void setProxyServerPort( std::string& proxyServerPort /* in */ );
|
||||
void setProxyUserName( std::string& proxyUserName /* in */ );
|
||||
void setProxyPassword( std::string& proxyPassword /* in */ );
|
||||
|
||||
/* Clones this object */
|
||||
twitCurl* clone();
|
||||
|
||||
private:
|
||||
/* cURL data */
|
||||
CURL* m_curlHandle;
|
||||
char* m_errorBuffer;
|
||||
std::string m_callbackData;
|
||||
|
||||
/* cURL flags */
|
||||
bool m_curlProxyParamsSet;
|
||||
bool m_curlLoginParamsSet;
|
||||
bool m_curlCallbackParamsSet;
|
||||
|
||||
/* cURL proxy data */
|
||||
std::string m_proxyServerIp;
|
||||
std::string m_proxyServerPort;
|
||||
std::string m_proxyUserName;
|
||||
std::string m_proxyPassword;
|
||||
|
||||
/* Twitter data */
|
||||
std::string m_twitterUsername;
|
||||
std::string m_twitterPassword;
|
||||
|
||||
/* Twitter API type */
|
||||
twitCurlTypes::eTwitCurlApiFormatType m_eApiFormatType;
|
||||
twitCurlTypes::eTwitCurlProtocolType m_eProtocolType;
|
||||
|
||||
/* OAuth data */
|
||||
oAuth m_oAuth;
|
||||
|
||||
/* Private methods */
|
||||
void clearCurlCallbackBuffers();
|
||||
void prepareCurlProxy();
|
||||
void prepareCurlCallback();
|
||||
void prepareCurlUserPass();
|
||||
void prepareStandardParams();
|
||||
bool performGet( const std::string& getUrl );
|
||||
bool performGetInternal( const std::string& getUrl,
|
||||
const std::string& oAuthHttpHeader );
|
||||
bool performDelete( const std::string& deleteUrl );
|
||||
bool performPost( const std::string& postUrl, std::string dataStr = "" );
|
||||
|
||||
/* Internal cURL related methods */
|
||||
static int curlCallback( char* data, size_t size, size_t nmemb, twitCurl* pTwitCurlObj );
|
||||
};
|
||||
|
||||
|
||||
/* Private functions */
|
||||
void utilMakeCurlParams( std::string& outStr, std::string& inParam1, std::string& inParam2 );
|
||||
void utilMakeUrlForUser( std::string& outUrl, const std::string& baseUrl, std::string& userInfo, bool isUserId );
|
||||
|
||||
#endif // _TWITCURL_H_
|
||||
|
|
|
@ -1,37 +1,37 @@
|
|||
<html>
|
||||
<body>
|
||||
<pre>
|
||||
<h1>Build Log</h1>
|
||||
<h3>
|
||||
--------------------Configuration: twitcurl - Win32 Release--------------------
|
||||
</h3>
|
||||
<h3>Command Lines</h3>
|
||||
Creating temporary file "C:\DOCUME~1\Mahesh\LOCALS~1\Temp\RSP239.tmp" with contents
|
||||
[
|
||||
/nologo /ML /W3 /GX /O2 /I "./curl" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /Fp"Release/twitcurl.pch" /YX /Fo"Release/" /Fd"Release/" /FD /c
|
||||
"C:\Projects\twitcurl\base64.cpp"
|
||||
"C:\Projects\twitcurl\HMAC_SHA1.cpp"
|
||||
"C:\Projects\twitcurl\oauthlib.cpp"
|
||||
"C:\Projects\twitcurl\SHA1.cpp"
|
||||
"C:\Projects\twitcurl\twitcurl.cpp"
|
||||
"C:\Projects\twitcurl\urlencode.cpp"
|
||||
]
|
||||
Creating command line "cl.exe @C:\DOCUME~1\Mahesh\LOCALS~1\Temp\RSP239.tmp"
|
||||
Creating command line "link.exe -lib /nologo /out:"Release\twitcurl.lib" .\Release\base64.obj .\Release\HMAC_SHA1.obj .\Release\oauthlib.obj .\Release\SHA1.obj .\Release\twitcurl.obj .\Release\urlencode.obj "
|
||||
<h3>Output Window</h3>
|
||||
Compiling...
|
||||
base64.cpp
|
||||
HMAC_SHA1.cpp
|
||||
oauthlib.cpp
|
||||
SHA1.cpp
|
||||
twitcurl.cpp
|
||||
urlencode.cpp
|
||||
Creating library...
|
||||
|
||||
|
||||
|
||||
<h3>Results</h3>
|
||||
twitcurl.lib - 0 error(s), 0 warning(s)
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
||||
<html>
|
||||
<body>
|
||||
<pre>
|
||||
<h1>Build Log</h1>
|
||||
<h3>
|
||||
--------------------Configuration: twitcurl - Win32 Release--------------------
|
||||
</h3>
|
||||
<h3>Command Lines</h3>
|
||||
Creating temporary file "C:\DOCUME~1\Mahesh\LOCALS~1\Temp\RSP239.tmp" with contents
|
||||
[
|
||||
/nologo /ML /W3 /GX /O2 /I "./curl" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /Fp"Release/twitcurl.pch" /YX /Fo"Release/" /Fd"Release/" /FD /c
|
||||
"C:\Projects\twitcurl\base64.cpp"
|
||||
"C:\Projects\twitcurl\HMAC_SHA1.cpp"
|
||||
"C:\Projects\twitcurl\oauthlib.cpp"
|
||||
"C:\Projects\twitcurl\SHA1.cpp"
|
||||
"C:\Projects\twitcurl\twitcurl.cpp"
|
||||
"C:\Projects\twitcurl\urlencode.cpp"
|
||||
]
|
||||
Creating command line "cl.exe @C:\DOCUME~1\Mahesh\LOCALS~1\Temp\RSP239.tmp"
|
||||
Creating command line "link.exe -lib /nologo /out:"Release\twitcurl.lib" .\Release\base64.obj .\Release\HMAC_SHA1.obj .\Release\oauthlib.obj .\Release\SHA1.obj .\Release\twitcurl.obj .\Release\urlencode.obj "
|
||||
<h3>Output Window</h3>
|
||||
Compiling...
|
||||
base64.cpp
|
||||
HMAC_SHA1.cpp
|
||||
oauthlib.cpp
|
||||
SHA1.cpp
|
||||
twitcurl.cpp
|
||||
urlencode.cpp
|
||||
Creating library...
|
||||
|
||||
|
||||
|
||||
<h3>Results</h3>
|
||||
twitcurl.lib - 0 error(s), 0 warning(s)
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 10.00
|
||||
# Visual C++ Express 2008
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "twitcurl", "twitcurl.vcproj", "{00175D8C-EA44-48AE-AC59-B3B7BE04E65C}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
Release|Win32 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{00175D8C-EA44-48AE-AC59-B3B7BE04E65C}.Debug|Win32.ActiveCfg = Release|Win32
|
||||
{00175D8C-EA44-48AE-AC59-B3B7BE04E65C}.Debug|Win32.Build.0 = Release|Win32
|
||||
{00175D8C-EA44-48AE-AC59-B3B7BE04E65C}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{00175D8C-EA44-48AE-AC59-B3B7BE04E65C}.Release|Win32.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 10.00
|
||||
# Visual C++ Express 2008
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "twitcurl", "twitcurl.vcproj", "{00175D8C-EA44-48AE-AC59-B3B7BE04E65C}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
Release|Win32 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{00175D8C-EA44-48AE-AC59-B3B7BE04E65C}.Debug|Win32.ActiveCfg = Release|Win32
|
||||
{00175D8C-EA44-48AE-AC59-B3B7BE04E65C}.Debug|Win32.Build.0 = Release|Win32
|
||||
{00175D8C-EA44-48AE-AC59-B3B7BE04E65C}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{00175D8C-EA44-48AE-AC59-B3B7BE04E65C}.Release|Win32.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
|
|
@ -1,347 +1,347 @@
|
|||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="9.00"
|
||||
Name="twitcurl"
|
||||
ProjectGUID="{00175D8C-EA44-48AE-AC59-B3B7BE04E65C}"
|
||||
TargetFrameworkVersion="0"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"
|
||||
/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory=".\Debug"
|
||||
IntermediateDirectory=".\Debug"
|
||||
ConfigurationType="4"
|
||||
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
|
||||
UseOfMFC="0"
|
||||
ATLMinimizesCRunTimeLibraryUsage="false"
|
||||
CharacterSet="2"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="./curl"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_LIB"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="1"
|
||||
PrecompiledHeaderFile=".\Debug/twitcurl.pch"
|
||||
AssemblerListingLocation=".\Debug/"
|
||||
ObjectFile=".\Debug/"
|
||||
ProgramDataBaseFileName=".\Debug/"
|
||||
WarningLevel="3"
|
||||
SuppressStartupBanner="true"
|
||||
DebugInformationFormat="4"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
PreprocessorDefinitions="_DEBUG"
|
||||
Culture="1033"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLibrarianTool"
|
||||
OutputFile=".\Debug\twitcurl.lib"
|
||||
SuppressStartupBanner="true"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
SuppressStartupBanner="true"
|
||||
OutputFile=".\Debug/twitcurl.bsc"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory=".\Release"
|
||||
IntermediateDirectory=".\Release"
|
||||
ConfigurationType="4"
|
||||
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
|
||||
UseOfMFC="0"
|
||||
ATLMinimizesCRunTimeLibraryUsage="false"
|
||||
CharacterSet="2"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
InlineFunctionExpansion="1"
|
||||
AdditionalIncludeDirectories="./include"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;CURL_STATICLIB"
|
||||
StringPooling="true"
|
||||
RuntimeLibrary="2"
|
||||
EnableFunctionLevelLinking="true"
|
||||
PrecompiledHeaderFile=".\Release/twitcurl.pch"
|
||||
AssemblerListingLocation=".\Release/"
|
||||
ObjectFile=".\Release/"
|
||||
ProgramDataBaseFileName=".\Release/"
|
||||
WarningLevel="3"
|
||||
SuppressStartupBanner="true"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
PreprocessorDefinitions="NDEBUG"
|
||||
Culture="1033"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLibrarianTool"
|
||||
LinkLibraryDependencies="true"
|
||||
AdditionalDependencies="libcurl.lib"
|
||||
OutputFile=".\Release\twitcurl.lib"
|
||||
AdditionalLibraryDirectories="./lib"
|
||||
SuppressStartupBanner="true"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
SuppressStartupBanner="true"
|
||||
OutputFile=".\Release/twitcurl.bsc"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||
>
|
||||
<File
|
||||
RelativePath="base64.cpp"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="HMAC_SHA1.cpp"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="oauthlib.cpp"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="SHA1.cpp"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="twitcurl.cpp"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="urlencode.cpp"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl"
|
||||
>
|
||||
<File
|
||||
RelativePath="base64.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="HMAC_SHA1.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="oauthlib.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="SHA1.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="twitcurl.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\twitcurlurls.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="urlencode.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="9.00"
|
||||
Name="twitcurl"
|
||||
ProjectGUID="{00175D8C-EA44-48AE-AC59-B3B7BE04E65C}"
|
||||
TargetFrameworkVersion="0"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"
|
||||
/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory=".\Debug"
|
||||
IntermediateDirectory=".\Debug"
|
||||
ConfigurationType="4"
|
||||
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
|
||||
UseOfMFC="0"
|
||||
ATLMinimizesCRunTimeLibraryUsage="false"
|
||||
CharacterSet="2"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="./curl"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_LIB"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="1"
|
||||
PrecompiledHeaderFile=".\Debug/twitcurl.pch"
|
||||
AssemblerListingLocation=".\Debug/"
|
||||
ObjectFile=".\Debug/"
|
||||
ProgramDataBaseFileName=".\Debug/"
|
||||
WarningLevel="3"
|
||||
SuppressStartupBanner="true"
|
||||
DebugInformationFormat="4"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
PreprocessorDefinitions="_DEBUG"
|
||||
Culture="1033"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLibrarianTool"
|
||||
OutputFile=".\Debug\twitcurl.lib"
|
||||
SuppressStartupBanner="true"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
SuppressStartupBanner="true"
|
||||
OutputFile=".\Debug/twitcurl.bsc"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory=".\Release"
|
||||
IntermediateDirectory=".\Release"
|
||||
ConfigurationType="4"
|
||||
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
|
||||
UseOfMFC="0"
|
||||
ATLMinimizesCRunTimeLibraryUsage="false"
|
||||
CharacterSet="2"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
InlineFunctionExpansion="1"
|
||||
AdditionalIncludeDirectories="./include"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;CURL_STATICLIB"
|
||||
StringPooling="true"
|
||||
RuntimeLibrary="2"
|
||||
EnableFunctionLevelLinking="true"
|
||||
PrecompiledHeaderFile=".\Release/twitcurl.pch"
|
||||
AssemblerListingLocation=".\Release/"
|
||||
ObjectFile=".\Release/"
|
||||
ProgramDataBaseFileName=".\Release/"
|
||||
WarningLevel="3"
|
||||
SuppressStartupBanner="true"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
PreprocessorDefinitions="NDEBUG"
|
||||
Culture="1033"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLibrarianTool"
|
||||
LinkLibraryDependencies="true"
|
||||
AdditionalDependencies="libcurl.lib"
|
||||
OutputFile=".\Release\twitcurl.lib"
|
||||
AdditionalLibraryDirectories="./lib"
|
||||
SuppressStartupBanner="true"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
SuppressStartupBanner="true"
|
||||
OutputFile=".\Release/twitcurl.bsc"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||
>
|
||||
<File
|
||||
RelativePath="base64.cpp"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="HMAC_SHA1.cpp"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="oauthlib.cpp"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="SHA1.cpp"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="twitcurl.cpp"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="urlencode.cpp"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl"
|
||||
>
|
||||
<File
|
||||
RelativePath="base64.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="HMAC_SHA1.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="oauthlib.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="SHA1.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="twitcurl.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\twitcurlurls.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="urlencode.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
|
|
|
@ -1,156 +1,156 @@
|
|||
#ifndef _TWITCURLURLS_H_
|
||||
#define _TWITCURLURLS_H_
|
||||
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
|
||||
/* Default values used in twitcurl */
|
||||
namespace twitCurlDefaults
|
||||
{
|
||||
/* Constants */
|
||||
const int TWITCURL_DEFAULT_BUFFSIZE = 1024;
|
||||
const std::string TWITCURL_COLON = ":";
|
||||
const char TWITCURL_EOS = '\0';
|
||||
const unsigned int MAX_TIMELINE_TWEET_COUNT = 200;
|
||||
|
||||
/* Miscellaneous data used to build twitter URLs*/
|
||||
const std::string TWITCURL_STATUSSTRING = "status=";
|
||||
const std::string TWITCURL_TEXTSTRING = "text=";
|
||||
const std::string TWITCURL_QUERYSTRING = "query=";
|
||||
const std::string TWITCURL_SEARCHQUERYSTRING = "q=";
|
||||
const std::string TWITCURL_SCREENNAME = "screen_name=";
|
||||
const std::string TWITCURL_USERID = "user_id=";
|
||||
const std::string TWITCURL_EXTENSIONFORMATS[2] = { ".json",
|
||||
".xml"
|
||||
};
|
||||
const std::string TWITCURL_PROTOCOLS[2] = { "https://",
|
||||
"http://"
|
||||
};
|
||||
const std::string TWITCURL_TARGETSCREENNAME = "target_screen_name=";
|
||||
const std::string TWITCURL_TARGETUSERID = "target_id=";
|
||||
const std::string TWITCURL_SINCEID = "since_id=";
|
||||
const std::string TWITCURL_TRIMUSER = "trim_user=true";
|
||||
const std::string TWITCURL_INCRETWEETS = "include_rts=true";
|
||||
const std::string TWITCURL_COUNT = "count=";
|
||||
const std::string TWITCURL_NEXT_CURSOR = "cursor=";
|
||||
const std::string TWITCURL_SKIP_STATUS = "skip_status=";
|
||||
const std::string TWITCURL_INCLUDE_ENTITIES = "include_entities=";
|
||||
const std::string TWITCURL_STRINGIFY_IDS = "stringify_ids=";
|
||||
const std::string TWITCURL_INREPLYTOSTATUSID = "in_reply_to_status_id=";
|
||||
|
||||
/* URL separators */
|
||||
const std::string TWITCURL_URL_SEP_AMP = "&";
|
||||
const std::string TWITCURL_URL_SEP_QUES = "?";
|
||||
};
|
||||
|
||||
/* Default twitter URLs */
|
||||
namespace twitterDefaults
|
||||
{
|
||||
/* Base URL */
|
||||
const std::string TWITCURL_BASE_URL = "api.twitter.com/1.1/";
|
||||
|
||||
/* Search URLs */
|
||||
const std::string TWITCURL_SEARCH_URL = TWITCURL_BASE_URL + "search/tweets";
|
||||
|
||||
/* Status URLs */
|
||||
const std::string TWITCURL_STATUSUPDATE_URL = TWITCURL_BASE_URL + "statuses/update";
|
||||
const std::string TWITCURL_STATUSSHOW_URL = TWITCURL_BASE_URL + "statuses/show/";
|
||||
const std::string TWITCURL_STATUDESTROY_URL = TWITCURL_BASE_URL + "statuses/destroy/";
|
||||
const std::string TWITCURL_RETWEET_URL = TWITCURL_BASE_URL + "statuses/retweet/";
|
||||
|
||||
/* Timeline URLs */
|
||||
const std::string TWITCURL_HOME_TIMELINE_URL = TWITCURL_BASE_URL + "statuses/home_timeline";
|
||||
const std::string TWITCURL_PUBLIC_TIMELINE_URL = TWITCURL_BASE_URL + "statuses/public_timeline";
|
||||
const std::string TWITCURL_FEATURED_USERS_URL = TWITCURL_BASE_URL + "statuses/featured";
|
||||
const std::string TWITCURL_FRIENDS_TIMELINE_URL = TWITCURL_BASE_URL + "statuses/friends_timeline";
|
||||
const std::string TWITCURL_MENTIONS_URL = TWITCURL_BASE_URL + "statuses/mentions";
|
||||
const std::string TWITCURL_USERTIMELINE_URL = TWITCURL_BASE_URL + "statuses/user_timeline";
|
||||
|
||||
/* Users URLs */
|
||||
const std::string TWITCURL_LOOKUPUSERS_URL = TWITCURL_BASE_URL + "users/lookup";
|
||||
const std::string TWITCURL_SHOWUSERS_URL = TWITCURL_BASE_URL + "users/show";
|
||||
const std::string TWITCURL_SHOWFRIENDS_URL = TWITCURL_BASE_URL + "statuses/friends";
|
||||
const std::string TWITCURL_SHOWFOLLOWERS_URL = TWITCURL_BASE_URL + "statuses/followers";
|
||||
|
||||
/* Direct messages URLs */
|
||||
const std::string TWITCURL_DIRECTMESSAGES_URL = TWITCURL_BASE_URL + "direct_messages";
|
||||
const std::string TWITCURL_DIRECTMESSAGENEW_URL = TWITCURL_BASE_URL + "direct_messages/new";
|
||||
const std::string TWITCURL_DIRECTMESSAGESSENT_URL = TWITCURL_BASE_URL + "direct_messages/sent";
|
||||
const std::string TWITCURL_DIRECTMESSAGEDESTROY_URL = TWITCURL_BASE_URL + "direct_messages/destroy/";
|
||||
|
||||
/* Friendships URLs */
|
||||
const std::string TWITCURL_FRIENDSHIPSCREATE_URL = TWITCURL_BASE_URL + "friendships/create";
|
||||
const std::string TWITCURL_FRIENDSHIPSDESTROY_URL = TWITCURL_BASE_URL + "friendships/destroy";
|
||||
const std::string TWITCURL_FRIENDSHIPSSHOW_URL = TWITCURL_BASE_URL + "friendships/show";
|
||||
|
||||
/* Social graphs URLs */
|
||||
const std::string TWITCURL_FRIENDSIDS_URL = TWITCURL_BASE_URL + "friends/ids";
|
||||
const std::string TWITCURL_FOLLOWERSIDS_URL = TWITCURL_BASE_URL + "followers/ids";
|
||||
|
||||
/* Account URLs */
|
||||
const std::string TWITCURL_ACCOUNTRATELIMIT_URL = TWITCURL_BASE_URL + "account/rate_limit_status";
|
||||
const std::string TWITCURL_ACCOUNTVERIFYCRED_URL = TWITCURL_BASE_URL + "account/verify_credentials";
|
||||
|
||||
/* Favorites URLs */
|
||||
const std::string TWITCURL_FAVORITESGET_URL = TWITCURL_BASE_URL + "favorites";
|
||||
const std::string TWITCURL_FAVORITECREATE_URL = TWITCURL_BASE_URL + "favorites/create/";
|
||||
const std::string TWITCURL_FAVORITEDESTROY_URL = TWITCURL_BASE_URL + "favorites/destroy/";
|
||||
|
||||
/* Block URLs */
|
||||
const std::string TWITCURL_BLOCKSCREATE_URL = TWITCURL_BASE_URL + "blocks/create/";
|
||||
const std::string TWITCURL_BLOCKSDESTROY_URL = TWITCURL_BASE_URL + "blocks/destroy/";
|
||||
const std::string TWITCURL_BLOCKSLIST_URL = TWITCURL_BASE_URL + "blocks/list";
|
||||
const std::string TWITCURL_BLOCKSIDS_URL = TWITCURL_BASE_URL + "blocks/ids";
|
||||
|
||||
/* Saved Search URLs */
|
||||
const std::string TWITCURL_SAVEDSEARCHGET_URL = TWITCURL_BASE_URL + "saved_searches";
|
||||
const std::string TWITCURL_SAVEDSEARCHSHOW_URL = TWITCURL_BASE_URL + "saved_searches/show/";
|
||||
const std::string TWITCURL_SAVEDSEARCHCREATE_URL = TWITCURL_BASE_URL + "saved_searches/create";
|
||||
const std::string TWITCURL_SAVEDSEARCHDESTROY_URL = TWITCURL_BASE_URL + "saved_searches/destroy/";
|
||||
|
||||
/* Trends URLs */
|
||||
const std::string TWITCURL_TRENDS_URL = TWITCURL_BASE_URL + "trends";
|
||||
const std::string TWITCURL_TRENDSDAILY_URL = TWITCURL_BASE_URL + "trends/daily";
|
||||
const std::string TWITCURL_TRENDSCURRENT_URL = TWITCURL_BASE_URL + "trends/current";
|
||||
const std::string TWITCURL_TRENDSWEEKLY_URL = TWITCURL_BASE_URL + "trends/weekly";
|
||||
const std::string TWITCURL_TRENDSAVAILABLE_URL = TWITCURL_BASE_URL + "trends/available";
|
||||
|
||||
};
|
||||
|
||||
namespace oAuthLibDefaults
|
||||
{
|
||||
/* Constants */
|
||||
const int OAUTHLIB_BUFFSIZE = 1024;
|
||||
const int OAUTHLIB_BUFFSIZE_LARGE = 1024;
|
||||
const std::string OAUTHLIB_CONSUMERKEY_KEY = "oauth_consumer_key";
|
||||
const std::string OAUTHLIB_CALLBACK_KEY = "oauth_callback";
|
||||
const std::string OAUTHLIB_VERSION_KEY = "oauth_version";
|
||||
const std::string OAUTHLIB_SIGNATUREMETHOD_KEY = "oauth_signature_method";
|
||||
const std::string OAUTHLIB_SIGNATURE_KEY = "oauth_signature";
|
||||
const std::string OAUTHLIB_TIMESTAMP_KEY = "oauth_timestamp";
|
||||
const std::string OAUTHLIB_NONCE_KEY = "oauth_nonce";
|
||||
const std::string OAUTHLIB_TOKEN_KEY = "oauth_token";
|
||||
const std::string OAUTHLIB_TOKENSECRET_KEY = "oauth_token_secret";
|
||||
const std::string OAUTHLIB_VERIFIER_KEY = "oauth_verifier";
|
||||
const std::string OAUTHLIB_SCREENNAME_KEY = "screen_name";
|
||||
const std::string OAUTHLIB_AUTHENTICITY_TOKEN_KEY = "authenticity_token";
|
||||
const std::string OAUTHLIB_SESSIONUSERNAME_KEY = "session[username_or_email]";
|
||||
const std::string OAUTHLIB_SESSIONPASSWORD_KEY = "session[password]";
|
||||
const std::string OAUTHLIB_AUTHENTICITY_TOKEN_TWITTER_RESP_KEY = "authenticity_token\" type=\"hidden\" value=\"";
|
||||
const std::string OAUTHLIB_TOKEN_TWITTER_RESP_KEY = "oauth_token\" type=\"hidden\" value=\"";
|
||||
const std::string OAUTHLIB_PIN_TWITTER_RESP_KEY = "code-desc\"><code>";
|
||||
const std::string OAUTHLIB_TOKEN_END_TAG_TWITTER_RESP = "\" />";
|
||||
const std::string OAUTHLIB_PIN_END_TAG_TWITTER_RESP = "</code>";
|
||||
|
||||
const std::string OAUTHLIB_AUTHHEADER_STRING = "Authorization: OAuth ";
|
||||
};
|
||||
|
||||
namespace oAuthTwitterApiUrls
|
||||
{
|
||||
/* Twitter OAuth API URLs */
|
||||
const std::string OAUTHLIB_TWITTER_REQUEST_TOKEN_URL = "api.twitter.com/oauth/request_token";
|
||||
const std::string OAUTHLIB_TWITTER_AUTHORIZE_URL = "api.twitter.com/oauth/authorize?oauth_token=";
|
||||
const std::string OAUTHLIB_TWITTER_ACCESS_TOKEN_URL = "api.twitter.com/oauth/access_token";
|
||||
};
|
||||
|
||||
#endif // _TWITCURLURLS_H_
|
||||
#ifndef _TWITCURLURLS_H_
|
||||
#define _TWITCURLURLS_H_
|
||||
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
|
||||
/* Default values used in twitcurl */
|
||||
namespace twitCurlDefaults
|
||||
{
|
||||
/* Constants */
|
||||
const int TWITCURL_DEFAULT_BUFFSIZE = 1024;
|
||||
const std::string TWITCURL_COLON = ":";
|
||||
const char TWITCURL_EOS = '\0';
|
||||
const unsigned int MAX_TIMELINE_TWEET_COUNT = 200;
|
||||
|
||||
/* Miscellaneous data used to build twitter URLs*/
|
||||
const std::string TWITCURL_STATUSSTRING = "status=";
|
||||
const std::string TWITCURL_TEXTSTRING = "text=";
|
||||
const std::string TWITCURL_QUERYSTRING = "query=";
|
||||
const std::string TWITCURL_SEARCHQUERYSTRING = "q=";
|
||||
const std::string TWITCURL_SCREENNAME = "screen_name=";
|
||||
const std::string TWITCURL_USERID = "user_id=";
|
||||
const std::string TWITCURL_EXTENSIONFORMATS[2] = { ".json",
|
||||
".xml"
|
||||
};
|
||||
const std::string TWITCURL_PROTOCOLS[2] = { "https://",
|
||||
"http://"
|
||||
};
|
||||
const std::string TWITCURL_TARGETSCREENNAME = "target_screen_name=";
|
||||
const std::string TWITCURL_TARGETUSERID = "target_id=";
|
||||
const std::string TWITCURL_SINCEID = "since_id=";
|
||||
const std::string TWITCURL_TRIMUSER = "trim_user=true";
|
||||
const std::string TWITCURL_INCRETWEETS = "include_rts=true";
|
||||
const std::string TWITCURL_COUNT = "count=";
|
||||
const std::string TWITCURL_NEXT_CURSOR = "cursor=";
|
||||
const std::string TWITCURL_SKIP_STATUS = "skip_status=";
|
||||
const std::string TWITCURL_INCLUDE_ENTITIES = "include_entities=";
|
||||
const std::string TWITCURL_STRINGIFY_IDS = "stringify_ids=";
|
||||
const std::string TWITCURL_INREPLYTOSTATUSID = "in_reply_to_status_id=";
|
||||
|
||||
/* URL separators */
|
||||
const std::string TWITCURL_URL_SEP_AMP = "&";
|
||||
const std::string TWITCURL_URL_SEP_QUES = "?";
|
||||
};
|
||||
|
||||
/* Default twitter URLs */
|
||||
namespace twitterDefaults
|
||||
{
|
||||
/* Base URL */
|
||||
const std::string TWITCURL_BASE_URL = "api.twitter.com/1.1/";
|
||||
|
||||
/* Search URLs */
|
||||
const std::string TWITCURL_SEARCH_URL = TWITCURL_BASE_URL + "search/tweets";
|
||||
|
||||
/* Status URLs */
|
||||
const std::string TWITCURL_STATUSUPDATE_URL = TWITCURL_BASE_URL + "statuses/update";
|
||||
const std::string TWITCURL_STATUSSHOW_URL = TWITCURL_BASE_URL + "statuses/show/";
|
||||
const std::string TWITCURL_STATUDESTROY_URL = TWITCURL_BASE_URL + "statuses/destroy/";
|
||||
const std::string TWITCURL_RETWEET_URL = TWITCURL_BASE_URL + "statuses/retweet/";
|
||||
|
||||
/* Timeline URLs */
|
||||
const std::string TWITCURL_HOME_TIMELINE_URL = TWITCURL_BASE_URL + "statuses/home_timeline";
|
||||
const std::string TWITCURL_PUBLIC_TIMELINE_URL = TWITCURL_BASE_URL + "statuses/public_timeline";
|
||||
const std::string TWITCURL_FEATURED_USERS_URL = TWITCURL_BASE_URL + "statuses/featured";
|
||||
const std::string TWITCURL_FRIENDS_TIMELINE_URL = TWITCURL_BASE_URL + "statuses/friends_timeline";
|
||||
const std::string TWITCURL_MENTIONS_URL = TWITCURL_BASE_URL + "statuses/mentions";
|
||||
const std::string TWITCURL_USERTIMELINE_URL = TWITCURL_BASE_URL + "statuses/user_timeline";
|
||||
|
||||
/* Users URLs */
|
||||
const std::string TWITCURL_LOOKUPUSERS_URL = TWITCURL_BASE_URL + "users/lookup";
|
||||
const std::string TWITCURL_SHOWUSERS_URL = TWITCURL_BASE_URL + "users/show";
|
||||
const std::string TWITCURL_SHOWFRIENDS_URL = TWITCURL_BASE_URL + "statuses/friends";
|
||||
const std::string TWITCURL_SHOWFOLLOWERS_URL = TWITCURL_BASE_URL + "statuses/followers";
|
||||
|
||||
/* Direct messages URLs */
|
||||
const std::string TWITCURL_DIRECTMESSAGES_URL = TWITCURL_BASE_URL + "direct_messages";
|
||||
const std::string TWITCURL_DIRECTMESSAGENEW_URL = TWITCURL_BASE_URL + "direct_messages/new";
|
||||
const std::string TWITCURL_DIRECTMESSAGESSENT_URL = TWITCURL_BASE_URL + "direct_messages/sent";
|
||||
const std::string TWITCURL_DIRECTMESSAGEDESTROY_URL = TWITCURL_BASE_URL + "direct_messages/destroy/";
|
||||
|
||||
/* Friendships URLs */
|
||||
const std::string TWITCURL_FRIENDSHIPSCREATE_URL = TWITCURL_BASE_URL + "friendships/create";
|
||||
const std::string TWITCURL_FRIENDSHIPSDESTROY_URL = TWITCURL_BASE_URL + "friendships/destroy";
|
||||
const std::string TWITCURL_FRIENDSHIPSSHOW_URL = TWITCURL_BASE_URL + "friendships/show";
|
||||
|
||||
/* Social graphs URLs */
|
||||
const std::string TWITCURL_FRIENDSIDS_URL = TWITCURL_BASE_URL + "friends/ids";
|
||||
const std::string TWITCURL_FOLLOWERSIDS_URL = TWITCURL_BASE_URL + "followers/ids";
|
||||
|
||||
/* Account URLs */
|
||||
const std::string TWITCURL_ACCOUNTRATELIMIT_URL = TWITCURL_BASE_URL + "account/rate_limit_status";
|
||||
const std::string TWITCURL_ACCOUNTVERIFYCRED_URL = TWITCURL_BASE_URL + "account/verify_credentials";
|
||||
|
||||
/* Favorites URLs */
|
||||
const std::string TWITCURL_FAVORITESGET_URL = TWITCURL_BASE_URL + "favorites";
|
||||
const std::string TWITCURL_FAVORITECREATE_URL = TWITCURL_BASE_URL + "favorites/create/";
|
||||
const std::string TWITCURL_FAVORITEDESTROY_URL = TWITCURL_BASE_URL + "favorites/destroy/";
|
||||
|
||||
/* Block URLs */
|
||||
const std::string TWITCURL_BLOCKSCREATE_URL = TWITCURL_BASE_URL + "blocks/create/";
|
||||
const std::string TWITCURL_BLOCKSDESTROY_URL = TWITCURL_BASE_URL + "blocks/destroy/";
|
||||
const std::string TWITCURL_BLOCKSLIST_URL = TWITCURL_BASE_URL + "blocks/list";
|
||||
const std::string TWITCURL_BLOCKSIDS_URL = TWITCURL_BASE_URL + "blocks/ids";
|
||||
|
||||
/* Saved Search URLs */
|
||||
const std::string TWITCURL_SAVEDSEARCHGET_URL = TWITCURL_BASE_URL + "saved_searches";
|
||||
const std::string TWITCURL_SAVEDSEARCHSHOW_URL = TWITCURL_BASE_URL + "saved_searches/show/";
|
||||
const std::string TWITCURL_SAVEDSEARCHCREATE_URL = TWITCURL_BASE_URL + "saved_searches/create";
|
||||
const std::string TWITCURL_SAVEDSEARCHDESTROY_URL = TWITCURL_BASE_URL + "saved_searches/destroy/";
|
||||
|
||||
/* Trends URLs */
|
||||
const std::string TWITCURL_TRENDS_URL = TWITCURL_BASE_URL + "trends";
|
||||
const std::string TWITCURL_TRENDSDAILY_URL = TWITCURL_BASE_URL + "trends/daily";
|
||||
const std::string TWITCURL_TRENDSCURRENT_URL = TWITCURL_BASE_URL + "trends/current";
|
||||
const std::string TWITCURL_TRENDSWEEKLY_URL = TWITCURL_BASE_URL + "trends/weekly";
|
||||
const std::string TWITCURL_TRENDSAVAILABLE_URL = TWITCURL_BASE_URL + "trends/available";
|
||||
|
||||
};
|
||||
|
||||
namespace oAuthLibDefaults
|
||||
{
|
||||
/* Constants */
|
||||
const int OAUTHLIB_BUFFSIZE = 1024;
|
||||
const int OAUTHLIB_BUFFSIZE_LARGE = 1024;
|
||||
const std::string OAUTHLIB_CONSUMERKEY_KEY = "oauth_consumer_key";
|
||||
const std::string OAUTHLIB_CALLBACK_KEY = "oauth_callback";
|
||||
const std::string OAUTHLIB_VERSION_KEY = "oauth_version";
|
||||
const std::string OAUTHLIB_SIGNATUREMETHOD_KEY = "oauth_signature_method";
|
||||
const std::string OAUTHLIB_SIGNATURE_KEY = "oauth_signature";
|
||||
const std::string OAUTHLIB_TIMESTAMP_KEY = "oauth_timestamp";
|
||||
const std::string OAUTHLIB_NONCE_KEY = "oauth_nonce";
|
||||
const std::string OAUTHLIB_TOKEN_KEY = "oauth_token";
|
||||
const std::string OAUTHLIB_TOKENSECRET_KEY = "oauth_token_secret";
|
||||
const std::string OAUTHLIB_VERIFIER_KEY = "oauth_verifier";
|
||||
const std::string OAUTHLIB_SCREENNAME_KEY = "screen_name";
|
||||
const std::string OAUTHLIB_AUTHENTICITY_TOKEN_KEY = "authenticity_token";
|
||||
const std::string OAUTHLIB_SESSIONUSERNAME_KEY = "session[username_or_email]";
|
||||
const std::string OAUTHLIB_SESSIONPASSWORD_KEY = "session[password]";
|
||||
const std::string OAUTHLIB_AUTHENTICITY_TOKEN_TWITTER_RESP_KEY = "authenticity_token\" type=\"hidden\" value=\"";
|
||||
const std::string OAUTHLIB_TOKEN_TWITTER_RESP_KEY = "oauth_token\" type=\"hidden\" value=\"";
|
||||
const std::string OAUTHLIB_PIN_TWITTER_RESP_KEY = "code-desc\"><code>";
|
||||
const std::string OAUTHLIB_TOKEN_END_TAG_TWITTER_RESP = "\" />";
|
||||
const std::string OAUTHLIB_PIN_END_TAG_TWITTER_RESP = "</code>";
|
||||
|
||||
const std::string OAUTHLIB_AUTHHEADER_STRING = "Authorization: OAuth ";
|
||||
};
|
||||
|
||||
namespace oAuthTwitterApiUrls
|
||||
{
|
||||
/* Twitter OAuth API URLs */
|
||||
const std::string OAUTHLIB_TWITTER_REQUEST_TOKEN_URL = "api.twitter.com/oauth/request_token";
|
||||
const std::string OAUTHLIB_TWITTER_AUTHORIZE_URL = "api.twitter.com/oauth/authorize?oauth_token=";
|
||||
const std::string OAUTHLIB_TWITTER_ACCESS_TOKEN_URL = "api.twitter.com/oauth/access_token";
|
||||
};
|
||||
|
||||
#endif // _TWITCURLURLS_H_
|
||||
|
|
|
@ -1,40 +1,40 @@
|
|||
#include "urlencode.h"
|
||||
|
||||
std::string char2hex( char dec )
|
||||
{
|
||||
char dig1 = (dec&0xF0)>>4;
|
||||
char dig2 = (dec&0x0F);
|
||||
if ( 0<= dig1 && dig1<= 9) dig1+=48; //0,48 in ascii
|
||||
if (10<= dig1 && dig1<=15) dig1+=65-10; //A,65 in ascii
|
||||
if ( 0<= dig2 && dig2<= 9) dig2+=48;
|
||||
if (10<= dig2 && dig2<=15) dig2+=65-10;
|
||||
|
||||
std::string r;
|
||||
r.append( &dig1, 1);
|
||||
r.append( &dig2, 1);
|
||||
return r;
|
||||
}
|
||||
|
||||
std::string urlencode( const std::string &c )
|
||||
{
|
||||
|
||||
std::string escaped;
|
||||
int max = c.length();
|
||||
for(int i=0; i<max; i++)
|
||||
{
|
||||
if ( (48 <= c[i] && c[i] <= 57) ||//0-9
|
||||
(65 <= c[i] && c[i] <= 90) ||//ABC...XYZ
|
||||
(97 <= c[i] && c[i] <= 122) || //abc...xyz
|
||||
(c[i]=='~' || c[i]=='-' || c[i]=='_' || c[i]=='.')
|
||||
)
|
||||
{
|
||||
escaped.append( &c[i], 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
escaped.append("%");
|
||||
escaped.append( char2hex(c[i]) );//converts char 255 to string "FF"
|
||||
}
|
||||
}
|
||||
return escaped;
|
||||
#include "urlencode.h"
|
||||
|
||||
std::string char2hex( char dec )
|
||||
{
|
||||
char dig1 = (dec&0xF0)>>4;
|
||||
char dig2 = (dec&0x0F);
|
||||
if ( 0<= dig1 && dig1<= 9) dig1+=48; //0,48 in ascii
|
||||
if (10<= dig1 && dig1<=15) dig1+=65-10; //A,65 in ascii
|
||||
if ( 0<= dig2 && dig2<= 9) dig2+=48;
|
||||
if (10<= dig2 && dig2<=15) dig2+=65-10;
|
||||
|
||||
std::string r;
|
||||
r.append( &dig1, 1);
|
||||
r.append( &dig2, 1);
|
||||
return r;
|
||||
}
|
||||
|
||||
std::string urlencode( const std::string &c )
|
||||
{
|
||||
|
||||
std::string escaped;
|
||||
int max = c.length();
|
||||
for(int i=0; i<max; i++)
|
||||
{
|
||||
if ( (48 <= c[i] && c[i] <= 57) ||//0-9
|
||||
(65 <= c[i] && c[i] <= 90) ||//ABC...XYZ
|
||||
(97 <= c[i] && c[i] <= 122) || //abc...xyz
|
||||
(c[i]=='~' || c[i]=='-' || c[i]=='_' || c[i]=='.')
|
||||
)
|
||||
{
|
||||
escaped.append( &c[i], 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
escaped.append("%");
|
||||
escaped.append( char2hex(c[i]) );//converts char 255 to string "FF"
|
||||
}
|
||||
}
|
||||
return escaped;
|
||||
}
|
|
@ -1,10 +1,10 @@
|
|||
#ifndef __URLENCODE_H__
|
||||
#define __URLENCODE_H__
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
std::string char2hex( char dec );
|
||||
std::string urlencode( const std::string &c );
|
||||
|
||||
#ifndef __URLENCODE_H__
|
||||
#define __URLENCODE_H__
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
std::string char2hex( char dec );
|
||||
std::string urlencode( const std::string &c );
|
||||
|
||||
#endif // __URLENCODE_H__
|
|
@ -1,13 +1,14 @@
|
|||
find_package(Qt4)
|
||||
include( ${QT_USE_FILE} )
|
||||
|
||||
FIND_LIBRARY(IRC_LIBRARY NAMES Communi PATHS ${QT_LIBRARY_DIR})
|
||||
FIND_PATH(IRC_INCLUDE_DIR NAMES "ircglobal.h" PATHS ${QT_INCLUDE_DIR} PATH_SUFFIXES Communi)
|
||||
FIND_LIBRARY(IRC_LIBRARY NAMES IrcCore PATHS ${QT_LIBRARY_DIR})
|
||||
FIND_PATH(IRC_INCLUDE_DIR NAMES "IrcCore/ircglobal.h" PATHS ${QT_INCLUDE_DIR} PATH_SUFFIXES Communi)
|
||||
|
||||
# message( STATUS ${IRC_LIBRARY})
|
||||
if( IRC_LIBRARY AND IRC_INCLUDE_DIR )
|
||||
message( STATUS "Found libCommuni ${IRC_LIBRARY}, ${IRC_INCLUDE_DIR}")
|
||||
set( IRC_FOUND 1 )
|
||||
set(IRC_INCLUDE_DIR ${IRC_INCLUDE_DIR}/IrcCore ${IRC_INCLUDE_DIR}/IrcUtil ${IRC_INCLUDE_DIR}/IrcModel)
|
||||
message( STATUS "Found libCommuni ${IRC_LIBRARY}, ${IRC_INCLUDE_DIR}")
|
||||
set( IRC_FOUND 1 )
|
||||
else()
|
||||
message( STATUS "Could NOT find libCommuni" )
|
||||
message( STATUS "Could NOT find libCommuni" )
|
||||
endif()
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
FIND_LIBRARY(SWIFTEN_LIBRARY NAMES Swiften HINTS ../lib)
|
||||
FIND_LIBRARY(SWIFTEN_LIBRARY NAMES Swiften Swiften3 HINTS ../lib)
|
||||
FIND_PATH(SWIFTEN_INCLUDE_DIR NAMES "Swiften/Swiften.h" PATH_SUFFIXES libSwiften Swiften HINTS ../include)
|
||||
|
||||
if( SWIFTEN_LIBRARY AND SWIFTEN_INCLUDE_DIR )
|
||||
|
@ -10,8 +10,15 @@ if( SWIFTEN_LIBRARY AND SWIFTEN_INCLUDE_DIR )
|
|||
OUTPUT_VARIABLE SWIFTEN_LIB)
|
||||
string(REGEX REPLACE "[\r\n]" " " SWIFTEN_LIB ${SWIFTEN_LIB})
|
||||
string(REGEX REPLACE " +$" "" SWIFTEN_LIB ${SWIFTEN_LIB})
|
||||
string(REGEX REPLACE " " ";" SWIFTEN_LIB ${SWIFTEN_LIB})
|
||||
set(SWIFTEN_LIBRARY "")
|
||||
if (APPLE)
|
||||
string(REGEX MATCHALL "-framework [A-Za-z]+" APPLE_FRAMEWORKS ${SWIFTEN_LIB})
|
||||
foreach(framework ${APPLE_FRAMEWORKS})
|
||||
list(APPEND SWIFTEN_LIBRARY ${framework} )
|
||||
endforeach(framework)
|
||||
string(REGEX REPLACE "-framework [A-Za-z]+" "" SWIFTEN_LIB ${SWIFTEN_LIB})
|
||||
endif(APPLE)
|
||||
string(REGEX REPLACE " " ";" SWIFTEN_LIB ${SWIFTEN_LIB})
|
||||
foreach(f ${SWIFTEN_LIB})
|
||||
STRING(SUBSTRING ${f} 0 2 f_out)
|
||||
STRING(COMPARE EQUAL ${f_out} "/L" IS_PATH)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
FIND_PATH(EVENT_INCLUDE_DIRS event.h PATH_SUFFIXES libev)
|
||||
FIND_PATH(EVENT_INCLUDE_DIRS event.h ev.h PATH_SUFFIXES libev)
|
||||
|
||||
SET(EVENT_NAMES ${EVENT_NAMES} ev libev)
|
||||
FIND_LIBRARY(EVENT_LIBRARIES NAMES ${EVENT_NAMES} PATH)
|
||||
|
|
|
@ -1 +1 @@
|
|||
ADD_SUBDIRECTORY(transport)
|
||||
ADD_SUBDIRECTORY(transport)
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2011 Jan Kaluza
|
||||
* Licensed under the Simplified BSD license.
|
||||
* See Documentation/Licenses/BSD-simplified.txt for more information.
|
||||
*/
|
||||
|
||||
#include <Swiften/Elements/PubSubItem.h>
|
||||
|
||||
namespace Swift {
|
||||
|
||||
PubSubItem::PubSubItem() {
|
||||
}
|
||||
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue