aboutsummaryrefslogtreecommitdiffstats
path: root/protocols/twitter/twitter_lib.h
blob: b06f5055faeea7a860ec0734b9c7b04424fda0a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/***************************************************************************\
*                                                                           *
*  BitlBee - An IRC to IM gateway                                           *
*  Simple module to facilitate twitter functionality.                       *
*                                                                           *
*  Copyright 2009 Geert Mulders <g.c.w.m.mulders@gmail.com>                 *
*                                                                           *
*  This 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, version            *
*  2.1.                                                                     *
*                                                                           *
*  This 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 this library; if not, write to the Free Software Foundation,  *
*  Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA           *
*                                                                           *
****************************************************************************/


#ifndef _TWITTER_LIB_H
#define _TWITTER_LIB_H

#include "nogaim.h"
#include "twitter_http.h"

#define TWITTER_API_URL "http://api.twitter.com/1"
#define IDENTICA_API_URL "https://identi.ca/api"

/* Status URLs */
#define TWITTER_STATUS_UPDATE_URL "/statuses/update.xml"
#define TWITTER_STATUS_SHOW_URL "/statuses/show/"
#define TWITTER_STATUS_DESTROY_URL "/statuses/destroy/"
#define TWITTER_STATUS_RETWEET_URL "/statuses/retweet/"

/* Timeline URLs */
#define TWITTER_PUBLIC_TIMELINE_URL "/statuses/public_timeline.xml"
#define TWITTER_FEATURED_USERS_URL "/statuses/featured.xml"
#define TWITTER_FRIENDS_TIMELINE_URL "/statuses/friends_timeline.xml"
#define TWITTER_HOME_TIMELINE_URL "/statuses/home_timeline.xml"
#define TWITTER_MENTIONS_URL "/statuses/mentions.xml"
#define TWITTER_USER_TIMELINE_URL "/statuses/user_timeline.xml"

/* Users URLs */
#define TWITTER_USERS_LOOKUP_URL "/users/lookup.xml"

/* Direct messages URLs */
#define TWITTER_DIRECT_MESSAGES_URL "/direct_messages.xml"
#define TWITTER_DIRECT_MESSAGES_NEW_URL "/direct_messages/new.xml"
#define TWITTER_DIRECT_MESSAGES_SENT_URL "/direct_messages/sent.xml"
#define TWITTER_DIRECT_MESSAGES_DESTROY_URL "/direct_messages/destroy/"

/* Friendships URLs */
#define TWITTER_FRIENDSHIPS_CREATE_URL "/friendships/create.xml"
#define TWITTER_FRIENDSHIPS_DESTROY_URL "/friendships/destroy.xml"
#define TWITTER_FRIENDSHIPS_SHOW_URL "/friendships/show.xml"

/* Social graphs URLs */
#define TWITTER_FRIENDS_IDS_URL "/friends/ids.xml"
#define TWITTER_FOLLOWERS_IDS_URL "/followers/ids.xml"

/* Account URLs */
#define TWITTER_ACCOUNT_RATE_LIMIT_URL "/account/rate_limit_status.xml"

/* Favorites URLs */
#define TWITTER_FAVORITES_GET_URL "/favorites.xml"
#define TWITTER_FAVORITE_CREATE_URL "/favorites/create/"
#define TWITTER_FAVORITE_DESTROY_URL "/favorites/destroy/"

/* Block URLs */
#define TWITTER_BLOCKS_CREATE_URL "/blocks/create/"
#define TWITTER_BLOCKS_DESTROY_URL "/blocks/destroy/"

void twitter_get_timeline(struct im_connection *ic, gint64 next_cursor);
void twitter_get_friends_ids(struct im_connection *ic, gint64 next_cursor);
void twitter_get_home_timeline(struct im_connection *ic, gint64 next_cursor);
void twitter_get_mentions(struct im_connection *ic, gint64 next_cursor);
void twitter_get_statuses_friends(struct im_connection *ic, gint64 next_cursor);

void twitter_post_status(struct im_connection *ic, char *msg, guint64 in_reply_to);
void twitter_direct_messages_new(struct im_connection *ic, char *who, char *message);
void twitter_friendships_create_destroy(struct im_connection *ic, char *who, int create);
void twitter_status_destroy(struct im_connection *ic, guint64 id);
void twitter_status_retweet(struct im_connection *ic, guint64 id);

#endif //_TWITTER_LIB_H
pan class="p">, gint, GaimInputCondition); void sspi_global_init(void) { /* FIXME */ } void sspi_global_deinit(void) { /* FIXME */ } void *ssl_connect(char *host, int port, ssl_input_function func, gpointer data) { struct scd *conn = g_new0(struct scd, 1); conn->fd = proxy_connect(host, port, ssl_connected, conn); sock_make_nonblocking(conn->fd); conn->func = func; conn->data = data; conn->host = g_strdup(host); if (conn->fd < 0) { g_free(conn); return NULL; } if (!initialized) { sspi_global_init(); initialized = TRUE; atexit(sspi_global_deinit); } return conn; } static void ssl_connected(gpointer _conn, gint fd, GaimInputCondition cond) { struct scd *conn = _conn; SCHANNEL_CRED ssl_cred; TimeStamp timestamp; SecBuffer ibuf[2],obuf[1]; SecBufferDesc ibufs,obufs; ULONG req = ISC_REQ_REPLAY_DETECT | ISC_REQ_SEQUENCE_DETECT | ISC_REQ_CONFIDENTIALITY | ISC_REQ_USE_SESSION_KEY | ISC_REQ_ALLOCATE_MEMORY | ISC_REQ_STREAM | ISC_REQ_EXTENDED_ERROR | ISC_REQ_MANUAL_CRED_VALIDATION; ULONG a; gsize size = 0; gchar *data = NULL; memset(&ssl_cred, 0, sizeof(SCHANNEL_CRED)); ssl_cred.dwVersion = SCHANNEL_CRED_VERSION; ssl_cred.grbitEnabledProtocols = SP_PROT_SSL3_CLIENT; SECURITY_STATUS st = AcquireCredentialsHandle(NULL, UNISP_NAME, SECPKG_CRED_OUTBOUND, NULL, &ssl_cred, NULL, NULL, &conn->cred, &timestamp); if (st != SEC_E_OK) { conn->func(conn->data, NULL, cond); return; } do { /* initialize buffers */ ibuf[0].cbBuffer = size; ibuf[0].pvBuffer = data; ibuf[1].cbBuffer = 0; ibuf[1].pvBuffer = NULL; obuf[0].cbBuffer = 0; obuf[0].pvBuffer = NULL; ibuf[0].BufferType = obuf[0].BufferType = SECBUFFER_TOKEN; ibuf[1].BufferType = SECBUFFER_EMPTY; /* initialize buffer descriptors */ ibufs.ulVersion = obufs.ulVersion = SECBUFFER_VERSION; ibufs.cBuffers = 2; obufs.cBuffers = 1; ibufs.pBuffers = ibuf; obufs.pBuffers = obuf; st = InitializeSecurityContext(&conn->cred, size?&conn->context:NULL, conn->host, req, 0, SECURITY_NETWORK_DREP, size?&ibufs:NULL, 0, &conn->context, &obufs, &a, &timestamp); if (obuf[0].pvBuffer && obuf[0].cbBuffer) { /* FIXME: Check return value */ send(conn->fd, obuf[0].pvBuffer, obuf[0].cbBuffer, 0); } switch (st) { case SEC_I_INCOMPLETE_CREDENTIALS: break; case SEC_I_CONTINUE_NEEDED: break; case SEC_E_INCOMPLETE_MESSAGE: break; case SEC_E_OK: break; } QueryContextAttributes(&conn->context, SECPKG_ATTR_STREAM_SIZES, &conn->sizes); } while (1); conn->func(conn->data, conn, cond); } int ssl_read(void *conn, char *retdata, int len) { struct scd *scd = conn; SecBufferDesc msg; SecBuffer buf[4]; int ret = -1, i; char *data = g_malloc(scd->sizes.cbHeader + scd->sizes.cbMaximumMessage + scd->sizes.cbTrailer); /* FIXME: Try to read some data */ msg.ulVersion = SECBUFFER_VERSION; msg.cBuffers = 4; msg.pBuffers = buf; buf[0].BufferType = SECBUFFER_DATA; buf[0].cbBuffer = len; buf[0].pvBuffer = data; buf[1].BufferType = SECBUFFER_EMPTY; buf[2].BufferType = SECBUFFER_EMPTY; buf[3].BufferType = SECBUFFER_EMPTY; SECURITY_STATUS st = DecryptMessage(&scd->context, &msg, 0, NULL); if (st != SEC_E_OK) { /* FIXME */ return -1; } for (i = 0; i < 4; i++) { if (buf[i].BufferType == SECBUFFER_DATA) { memcpy(retdata, buf[i].pvBuffer, len); ret = len; } } g_free(data); return -1; } int ssl_write(void *conn, const char *userdata, int len) { struct scd *scd = conn; SecBuffer buf[4]; SecBufferDesc msg; char *data; int ret; msg.ulVersion = SECBUFFER_VERSION; msg.cBuffers = 4; msg.pBuffers = buf; data = g_malloc(scd->sizes.cbHeader + scd->sizes.cbMaximumMessage + scd->sizes.cbTrailer); memcpy(data + scd->sizes.cbHeader, userdata, len); buf[0].BufferType = SECBUFFER_STREAM_HEADER; buf[0].cbBuffer = scd->sizes.cbHeader; buf[0].pvBuffer = data; buf[1].BufferType = SECBUFFER_DATA; buf[1].cbBuffer = len; buf[1].pvBuffer = data + scd->sizes.cbHeader; buf[2].BufferType = SECBUFFER_STREAM_TRAILER; buf[2].cbBuffer = scd->sizes.cbTrailer; buf[2].pvBuffer = data + scd->sizes.cbHeader + len; buf[3].BufferType = SECBUFFER_EMPTY; SECURITY_STATUS st = EncryptMessage(&scd->context, 0, &msg, 0); ret = send(scd->fd, data, buf[0].cbBuffer + buf[1].cbBuffer + buf[2].cbBuffer, 0); g_free(data); return ret; } void ssl_disconnect(void *conn) { struct scd *scd = conn; SecBufferDesc msg; SecBuffer buf; DWORD dw; dw = SCHANNEL_SHUTDOWN; buf.cbBuffer = sizeof(dw); buf.BufferType = SECBUFFER_TOKEN; buf.pvBuffer = &dw; msg.ulVersion = SECBUFFER_VERSION; msg.cBuffers = 1; msg.pBuffers = &buf; SECURITY_STATUS st = ApplyControlToken(&scd->context, &msg); if (st != SEC_E_OK) { /* FIXME */ } /* FIXME: call InitializeSecurityContext(Schannel), passing * in empty buffers*/ DeleteSecurityContext(&scd->context); FreeCredentialsHandle(&scd->cred); closesocket(scd->fd); g_free(scd->host); g_free(scd); } int ssl_getfd(void *conn) { return ((struct scd*)conn)->fd; } GaimInputCondition ssl_getdirection( void *conn ) { return GAIM_INPUT_WRITE; /* FIXME: or GAIM_INPUT_READ */ }