Allow compiling on Windows
This commit is contained in:
parent
b8e73f819c
commit
8562eb342c
5 changed files with 57 additions and 29 deletions
|
@ -95,7 +95,9 @@ int read_pubkey_file (const char *name, struct rsa_pubkey *dst) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
if (n_len != read (pubkey_fd, n_raw, n_len)) {
|
||||
gint readret;
|
||||
readret = read (pubkey_fd, n_raw, n_len);
|
||||
if (readret <= 0 || (n_len != (guint) readret)) {
|
||||
free (n_raw);
|
||||
close (pubkey_fd);
|
||||
return 0;
|
||||
|
@ -110,9 +112,7 @@ int read_pubkey_file (const char *name, struct rsa_pubkey *dst) {
|
|||
|
||||
void read_state_file (struct tgl_state *TLS) {
|
||||
char *name = 0;
|
||||
if (asprintf (&name, "%s/%s", TLS->base_path, "state") < 0) {
|
||||
return;
|
||||
}
|
||||
name = g_strdup_printf("%s/%s", TLS->base_path, "state");
|
||||
|
||||
int state_file_fd = open (name, O_CREAT | O_RDWR, 0600);
|
||||
free (name);
|
||||
|
@ -148,9 +148,7 @@ void write_state_file (struct tgl_state *TLS) {
|
|||
wseq = TLS->seq; wpts = TLS->pts; wqts = TLS->qts; wdate = TLS->date;
|
||||
|
||||
char *name = 0;
|
||||
if (asprintf (&name, "%s/%s", TLS->base_path, "state") < 0) {
|
||||
return;
|
||||
}
|
||||
name = g_strdup_printf("%s/%s", TLS->base_path, "state");
|
||||
|
||||
int state_file_fd = open (name, O_CREAT | O_RDWR, 0600);
|
||||
free (name);
|
||||
|
@ -210,9 +208,7 @@ void write_dc (struct tgl_dc *DC, void *extra) {
|
|||
|
||||
void write_auth_file (struct tgl_state *TLS) {
|
||||
char *name = 0;
|
||||
if (asprintf (&name, "%s/%s", TLS->base_path, "auth") < 0) {
|
||||
return;
|
||||
}
|
||||
name = g_strdup_printf("%s/%s", TLS->base_path, "auth");
|
||||
int auth_file_fd = open (name, O_CREAT | O_RDWR, 0600);
|
||||
free (name);
|
||||
if (auth_file_fd < 0) { return; }
|
||||
|
@ -277,9 +273,7 @@ void empty_auth_file (struct tgl_state *TLS) {
|
|||
|
||||
void read_auth_file (struct tgl_state *TLS) {
|
||||
char *name = 0;
|
||||
if (asprintf (&name, "%s/%s", TLS->base_path, "auth") < 0) {
|
||||
return;
|
||||
}
|
||||
name = g_strdup_printf("%s/%s", TLS->base_path, "auth");
|
||||
int auth_file_fd = open (name, O_CREAT | O_RDWR, 0600);
|
||||
free (name);
|
||||
if (auth_file_fd < 0) {
|
||||
|
@ -350,9 +344,7 @@ void write_secret_chat (tgl_peer_t *_P, void *extra) {
|
|||
|
||||
void write_secret_chat_file (struct tgl_state *TLS) {
|
||||
char *name = 0;
|
||||
if (asprintf (&name, "%s/%s", TLS->base_path, "secret") < 0) {
|
||||
return;
|
||||
}
|
||||
name = g_strdup_printf("%s/%s", TLS->base_path, "secret");
|
||||
int secret_chat_fd = open (name, O_CREAT | O_RDWR, 0600);
|
||||
free (name);
|
||||
assert (secret_chat_fd >= 0);
|
||||
|
@ -414,9 +406,7 @@ void read_secret_chat (struct tgl_state *TLS, int fd, int v) {
|
|||
|
||||
void read_secret_chat_file (struct tgl_state *TLS) {
|
||||
char *name = 0;
|
||||
if (asprintf (&name, "%s/%s", TLS->base_path, "secret") < 0) {
|
||||
return;
|
||||
}
|
||||
name = g_strdup_printf("%s/%s", TLS->base_path, "secret");
|
||||
|
||||
int secret_chat_fd = open (name, O_RDWR, 0600);
|
||||
free (name);
|
||||
|
|
|
@ -29,8 +29,10 @@
|
|||
#include <assert.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#ifndef WIN32
|
||||
#include <pwd.h>
|
||||
#include <regex.h>
|
||||
#endif
|
||||
|
||||
#include "accountopt.h"
|
||||
#include "blist.h"
|
||||
|
@ -47,6 +49,9 @@
|
|||
#include "util.h"
|
||||
#include "eventloop.h"
|
||||
#include "request.h"
|
||||
#ifdef WIN32
|
||||
#include "win32/win32dep.h"
|
||||
#endif
|
||||
|
||||
#include <tgl.h>
|
||||
#include <tgl-binlog.h>
|
||||
|
@ -80,7 +85,11 @@ static void on_user_get_info (struct tgl_state *TLS, void *info_data, int succes
|
|||
|
||||
const char *config_dir = "telegram-purple";
|
||||
const char *user_pk_filename = "server.tglpub";
|
||||
#ifdef WIN32
|
||||
const char *pk_path = "server.tglpub";
|
||||
#else
|
||||
const char *pk_path = "/etc/telegram-purple/server.tglpub";
|
||||
#endif
|
||||
|
||||
struct tgl_update_callback tgp_callback = {
|
||||
.logprintf = debug,
|
||||
|
@ -574,8 +583,14 @@ static void tgprpl_login (PurpleAccount * acct) {
|
|||
debug ("base configuration path: '%s'", TLS->base_path);
|
||||
|
||||
struct rsa_pubkey pubkey;
|
||||
debug ("trying global pubkey at %s", pk_path);
|
||||
gboolean global_pk_loaded = read_pubkey_file (pk_path, &pubkey);
|
||||
#ifdef WIN32
|
||||
gchar *global_pk_path = g_strdup_printf("%s/%s", DATADIR, pk_path);
|
||||
#else
|
||||
gchar *global_pk_path = g_strdup(pk_path);
|
||||
#endif
|
||||
debug ("trying global pubkey at %s", global_pk_path);
|
||||
gboolean global_pk_loaded = read_pubkey_file (global_pk_path, &pubkey);
|
||||
g_free(global_pk_path);
|
||||
|
||||
tgl_set_verbosity (TLS, 4);
|
||||
if (global_pk_loaded) {
|
||||
|
@ -607,7 +622,7 @@ static void tgprpl_login (PurpleAccount * acct) {
|
|||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
tgl_set_ev_base (TLS, conn);
|
||||
tgl_set_net_methods (TLS, &tgp_conn_methods);
|
||||
tgl_set_timer_methods (TLS, &tgp_timers);
|
||||
|
|
2
tgp-ft.c
2
tgp-ft.c
|
@ -63,7 +63,7 @@ static char *tgp_strdup_determine_filename (const char *mime, const char *captio
|
|||
type = "bin";
|
||||
}
|
||||
}
|
||||
return g_strdup_printf ("%lld.%s", ABS(hash), type);
|
||||
return g_strdup_printf ("%" G_GINT64_MODIFIER "d.%s", ABS(hash), type);
|
||||
}
|
||||
|
||||
static void tgprpl_xfer_recv_on_finished (struct tgl_state *TLS, void *_data, int success, const char *filename) {
|
||||
|
|
19
tgp-msg.c
19
tgp-msg.c
|
@ -27,6 +27,25 @@
|
|||
#include <locale.h>
|
||||
#include <tgl-queries.h>
|
||||
|
||||
#if !GLIB_CHECK_VERSION(2,30,0)
|
||||
gchar *
|
||||
g_utf8_substring (const gchar *str,
|
||||
glong start_pos,
|
||||
glong end_pos)
|
||||
{
|
||||
gchar *start, *end, *out;
|
||||
|
||||
start = g_utf8_offset_to_pointer (str, start_pos);
|
||||
end = g_utf8_offset_to_pointer (start, end_pos - start_pos);
|
||||
|
||||
out = g_malloc (end - start + 1);
|
||||
memcpy (out, start, end - start);
|
||||
out[end - start] = 0;
|
||||
|
||||
return out;
|
||||
}
|
||||
#endif
|
||||
|
||||
#include "telegram-base.h"
|
||||
#include "tgp-structs.h"
|
||||
#include "tgp-msg.h"
|
||||
|
|
16
tgp-net.c
16
tgp-net.c
|
@ -23,16 +23,20 @@
|
|||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <sys/types.h>
|
||||
#ifndef WIN32
|
||||
#include <netdb.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <poll.h>
|
||||
#include <arpa/inet.h>
|
||||
#else
|
||||
#include <winsock2.h>
|
||||
#endif
|
||||
#include <sys/fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <poll.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
|
||||
|
@ -259,7 +263,7 @@ static void net_on_connected (gpointer arg, gint fd, const gchar *error_message)
|
|||
|
||||
if (fd == -1) {
|
||||
const char *msg = "Connection not possible, either your network or a Telegram data center is down, or the"
|
||||
" Telegram network configuratio has changed.";
|
||||
" Telegram network configuration has changed.";
|
||||
warning (msg);
|
||||
return;
|
||||
}
|
||||
|
@ -403,7 +407,7 @@ static void try_write (struct connection *c) {
|
|||
delete_connection_buffer (b);
|
||||
} else {
|
||||
if (errno != EAGAIN && errno != EWOULDBLOCK) {
|
||||
info ("fail_connection: write_error %m\n");
|
||||
info ("fail_connection: write_error %s\n", g_strerror(errno));
|
||||
fail_connection (c);
|
||||
return;
|
||||
} else {
|
||||
|
@ -481,7 +485,7 @@ static void try_read (struct connection *c) {
|
|||
c->in_tail = b;
|
||||
} else {
|
||||
if (errno != EAGAIN && errno != EWOULDBLOCK) {
|
||||
debug ("fail_connection: read_error %m\n");
|
||||
debug ("fail_connection: read_error %s\n", strerror(errno));
|
||||
fail_connection (c);
|
||||
return;
|
||||
} else {
|
||||
|
|
Loading…
Add table
Reference in a new issue