1 /*
2  * Hangouts Plugin for libpurple/Pidgin
3  * Copyright (c) 2015-2016 Eion Robb, Mike Ruprecht
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 
20 
21 
22 #ifndef _LIBHANGOUTS_H_
23 #define _LIBHANGOUTS_H_
24 
25 #ifndef PURPLE_PLUGINS
26 #	define PURPLE_PLUGINS
27 #endif
28 
29 #define PROTOBUF_C_UNPACK_ERROR(...) purple_debug_error("hangouts-protobuf", __VA_ARGS__)
30 
31 #include "purplecompat.h"
32 
33 #include "account.h"
34 #include "connection.h"
35 #include "http.h"
36 
37 #include "hangouts.pb-c.h"
38 
39 #define HANGOUTS_PLUGIN_ID "prpl-hangouts"
40 #define HANGOUTS_PLUGIN_VERSION "0.1"
41 
42 #define HANGOUTS_BUFFER_DEFAULT_SIZE 4096
43 
44 #ifndef N_
45 #	define N_(a) (a)
46 #endif
47 #ifndef _
48 #	define _(a) (a)
49 #endif
50 
51 #define HANGOUTS_API_OAUTH2_TOKEN_URL "https://www.googleapis.com/oauth2/v3/token"
52 
53 // #define GOOGLE_CLIENT_ID "1055179169992-mvb9smig5gflo8bq6m5pao05jqmov76h.apps.googleusercontent.com"
54 // #define GOOGLE_CLIENT_SECRET "Hj5Cv38ZM__uO1bTQxOtWwkT"
55 
56 #define GOOGLE_CLIENT_ID "936475272427.apps.googleusercontent.com"
57 #define GOOGLE_CLIENT_SECRET "KWsJlkaMn1jGLxQpWxMnOox-"
58 #define GOOGLE_GPLUS_KEY "AIzaSyAfFJCeph-euFSwtmqFZi0kaKk-cZ5wufM"
59 
60 #define MINIFIED_OAUTH_URL "https://goo.gl/eJHvDX"
61 #define HANGOUTS_API_OAUTH2_REDIRECT_URI "urn:ietf:wg:oauth:2.0:oob"
62 // #define HANGOUTS_API_OAUTH2_AUTHORIZATION_CODE_URL MINIFIED_OAUTH_URL
63 
64 #define HANGOUTS_API_OAUTH2_AUTHORIZATION_CODE_URL "https://accounts.google.com/o/oauth2/auth?client_id=" GOOGLE_CLIENT_ID "&scope=https://www.google.com/accounts/OAuthLogin&redirect_uri=urn:ietf:wg:oauth:2.0:oob&response_type=code&device_name=purple-hangouts"
65 
66 #define HANGOUTS_IMAGE_UPLOAD_URL "https://docs.google.com/upload/photos/resumable?authuser=0"
67 
68 #define HANGOUTS_ACTIVE_CLIENT_TIMEOUT 120
69 
70 #define HANGOUTS_MAGIC_HALF_EIGHT_SLASH_ME_TYPE 4
71 
72 typedef struct {
73 	PurpleAccount *account;
74 	PurpleConnection *pc;
75 
76 	PurpleHttpCookieJar *cookie_jar;
77 	gchar *refresh_token;
78 	gchar *access_token;
79 	gchar *gsessionid_param;
80 	gchar *sid_param;
81 	gchar *client_id;
82 	gchar *self_gaia_id;
83 	gchar *self_phone;
84 	ActiveClientState active_client_state;
85 	gint64 last_event_timestamp;
86 	PurpleConversation *last_conversation_focused;
87 	guint poll_buddy_status_timeout;
88 
89 	GByteArray *channel_buffer;
90 	guint channel_watchdog;
91 	PurpleHttpConnection *channel_connection;
92 	PurpleHttpKeepalivePool *channel_keepalive_pool;
93 	PurpleHttpKeepalivePool *icons_keepalive_pool;
94 	PurpleHttpKeepalivePool *client6_keepalive_pool;
95 	gint idle_time;
96 	gint active_client_timeout;
97 	gint last_data_received; // A timestamp of when we last received data from the stream
98 
99 	GHashTable *one_to_ones;     // A store of known conv_id's->gaia_id's
100 	GHashTable *one_to_ones_rev; // A store of known gaia_id's->conv_id's
101 	GHashTable *group_chats;     // A store of known conv_id's
102 	GHashTable *sent_message_ids;// A store of message id's that we generated from this instance
103 	GHashTable *google_voice_conversations; // A store of known SMS conv_id's
104 } HangoutsAccount;
105 
106 
107 typedef enum
108 {
109     HANGOUTS_DEVICE_TYPE_UNKNOWN = 0x0000,
110     HANGOUTS_DEVICE_TYPE_MOBILE  = 0x0001,
111     HANGOUTS_DEVICE_TYPE_DESKTOP = 0x0002,
112     HANGOUTS_DEVICE_TYPE_TABLET  = 0x0004
113 } HangoutsDeviceTypeFlags;
114 
115 typedef struct {
116 	PurpleBuddy *buddy;
117 	gboolean in_call;
118 	gint64 last_seen;
119 	HangoutsDeviceTypeFlags device_type;
120 } HangoutsBuddy;
121 
122 
123 gboolean hangouts_is_valid_id(const gchar *id);
124 
125 #endif /*_LIBHANGOUTS_H_*/