[refactor] fix all build warnings

This commit is contained in:
Julian Sparber
2017-09-30 20:05:35 +02:00
parent 42d3dda0ab
commit 3baef0382b
5 changed files with 48 additions and 133 deletions

View File

@@ -13,11 +13,12 @@
#include <glib/gstdio.h> #include <glib/gstdio.h>
#include "get.h" #include "get.h"
#include "server.h"
#include "teleportapp.h" #include "teleportapp.h"
static int port; static int port;
static SoupServer *server; static SoupServer *glob_server;
static const char *tls_cert_file, *tls_key_file; //static const char *tls_cert_file, *tls_key_file;
static int static int
compare_strings (gconstpointer a, gconstpointer b) compare_strings (gconstpointer a, gconstpointer b)
@@ -151,91 +152,11 @@ do_get (SoupServer *server, SoupMessage *msg, const char *path)
soup_message_set_status (msg, SOUP_STATUS_OK); soup_message_set_status (msg, SOUP_STATUS_OK);
} }
static void
do_get_response_json (SoupServer *server, SoupMessage *msg, const char *path)
{
char *slash;
GStatBuf st;
printf("paths: %s", path);
if (g_stat (path, &st) == -1) {
if (errno == EPERM)
soup_message_set_status (msg, SOUP_STATUS_FORBIDDEN);
else if (errno == ENOENT)
soup_message_set_status (msg, SOUP_STATUS_NOT_FOUND);
else
soup_message_set_status (msg, SOUP_STATUS_INTERNAL_SERVER_ERROR);
return;
}
if (g_file_test (path, G_FILE_TEST_IS_DIR)) {
GString *listing;
char *index_path;
slash = strrchr (path, '/');
if (!slash || slash[1]) {
char *redir_uri;
redir_uri = g_strdup_printf ("%s/", soup_message_get_uri (msg)->path);
soup_message_set_redirect (msg, SOUP_STATUS_MOVED_PERMANENTLY,
redir_uri);
g_free (redir_uri);
return;
}
index_path = g_strdup_printf ("%s/index.html", path);
if (g_stat (path, &st) != -1) {
do_get (server, msg, index_path);
g_free (index_path);
return;
}
g_free (index_path);
listing = get_directory_listing (path);
soup_message_set_response (msg, "text/html",
SOUP_MEMORY_TAKE,
listing->str, listing->len);
soup_message_set_status (msg, SOUP_STATUS_OK);
g_string_free (listing, FALSE);
return;
}
if (msg->method == SOUP_METHOD_GET) {
GMappedFile *mapping;
SoupBuffer *buffer;
mapping = g_mapped_file_new (path, FALSE, NULL);
if (!mapping) {
soup_message_set_status (msg, SOUP_STATUS_INTERNAL_SERVER_ERROR);
return;
}
buffer = soup_buffer_new_with_owner (g_mapped_file_get_contents (mapping),
g_mapped_file_get_length (mapping),
mapping, (GDestroyNotify)g_mapped_file_unref);
soup_message_body_append_buffer (msg->response_body, buffer);
soup_buffer_free (buffer);
} else /* msg->method == SOUP_METHOD_HEAD */ {
char *length;
/* We could just use the same code for both GET and
* HEAD (soup-message-server-io.c will fix things up).
* But we'll optimize and avoid the extra I/O.
*/
length = g_strdup_printf ("%lu", (gulong)st.st_size);
soup_message_headers_append (msg->response_headers,
"Content-Length", length);
g_free (length);
}
soup_message_set_status (msg, SOUP_STATUS_OK);
}
static void handle_incoming_file(const char *hash, const char *filename, const int size, const char *origin) { static void handle_incoming_file(const char *hash, const char *filename, const int size, const char *origin) {
g_print("Got a new file form %s with size:%d with title: %s\n", origin, size, filename);
GVariantBuilder *builder; GVariantBuilder *builder;
GVariant *value; GVariant *value;
g_print("Got a new file form %s with size:%d with title: %s\n", origin, size, filename);
builder = g_variant_builder_new (G_VARIANT_TYPE ("as")); builder = g_variant_builder_new (G_VARIANT_TYPE ("as"));
g_variant_builder_add (builder, "s", origin); g_variant_builder_add (builder, "s", origin);
g_variant_builder_add (builder, g_variant_builder_add (builder,
@@ -274,7 +195,7 @@ server_callback (SoupServer *server, SoupMessage *msg,
g_print ("%s\n", msg->request_body->data); g_print ("%s\n", msg->request_body->data);
if (data != NULL) { if (data != NULL) {
g_print("File to share %s\n", data); g_print("File to share %s\n", (char *)data);
file_path = g_strdup(data); file_path = g_strdup(data);
response = g_string_new("{\"error\": false, \"message\": \"Success\"}"); response = g_string_new("{\"error\": false, \"message\": \"Success\"}");
} }
@@ -325,22 +246,14 @@ server_callback (SoupServer *server, SoupMessage *msg,
g_print (" -> %d %s\n\n", msg->status_code, msg->reason_phrase); g_print (" -> %d %s\n\n", msg->status_code, msg->reason_phrase);
} }
static void
quit (int sig)
{
/* Exit cleanly on ^C in case we're valgrinding. */
exit (0);
}
int addRouteToServer(char *name, char *file_to_send, char *destination) { int addRouteToServer(char *name, char *file_to_send, char *destination) {
soup_server_add_handler (server, g_strdup_printf("/transfer/%s", name), GFile *file;
GFileInfo *fileInfo;
soup_server_add_handler (glob_server, g_strdup_printf("/transfer/%s", name),
server_callback, g_strdup(file_to_send), NULL); server_callback, g_strdup(file_to_send), NULL);
//send notification of available file to the client //send notification of available file to the client
//For getting file size //For getting file size
//https://developer.gnome.org/gio/stable/GFile.html#g-file-query-info //https://developer.gnome.org/gio/stable/GFile.html#g-file-query-info
GFile *file;
GFileInfo *fileInfo;
file = g_file_new_for_path(file_to_send); file = g_file_new_for_path(file_to_send);
//G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME, G_FILE_ATTRIBUTE_STANDARD_SIZE //G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME, G_FILE_ATTRIBUTE_STANDARD_SIZE
fileInfo = g_file_query_info(file, "standard::display-name,standard::size", G_FILE_QUERY_INFO_NONE, NULL, NULL); fileInfo = g_file_query_info(file, "standard::display-name,standard::size", G_FILE_QUERY_INFO_NONE, NULL, NULL);
@@ -356,21 +269,20 @@ int addRouteToServer(char *name, char *file_to_send, char *destination) {
} }
extern int run_http_server(void) { extern int run_http_server(void) {
//GMainLoop *loop;
GSList *uris, *u; GSList *uris, *u;
char *str; char *str;
GTlsCertificate *cert; //GTlsCertificate *cert;
GError *error = NULL; GError *error = NULL;
port = 3000; port = 3000;
server = soup_server_new (SOUP_SERVER_SERVER_HEADER, "teleport-httpd ", glob_server = soup_server_new (SOUP_SERVER_SERVER_HEADER, "teleport-httpd ",
NULL); NULL);
soup_server_listen_all (server, port, 0, &error); soup_server_listen_all (glob_server, port, 0, &error);
soup_server_add_handler (server, NULL, soup_server_add_handler (glob_server, NULL,
server_callback, NULL, NULL); server_callback, NULL, NULL);
uris = soup_server_get_uris (server); uris = soup_server_get_uris (glob_server);
for (u = uris; u; u = u->next) { for (u = uris; u; u = u->next) {
str = soup_uri_to_string (u->data, FALSE); str = soup_uri_to_string (u->data, FALSE);
g_print ("Listening on %s\n", str); g_print ("Listening on %s\n", str);
@@ -381,17 +293,5 @@ extern int run_http_server(void) {
g_print ("\nWaiting for requests...\n"); g_print ("\nWaiting for requests...\n");
//loop = g_main_loop_new (NULL, TRUE);
//g_main_loop_run (loop);
return 0; return 0;
} }
/*int
main (int argc, char **argv)
{
char *file_to_send = "/home/julian/teleport/docs/flow-diagram.svg";
createServer(file_to_send);
return 0;
}
*/

View File

@@ -71,13 +71,14 @@ void open_file_callback (GSimpleAction *simple,
} }
void create_user_notification (const char *file_name, const int file_size, const char *origin_device, GVariant *target) { void create_user_notification (const char *file_name, const int file_size, const char *origin_device, GVariant *target) {
GIcon *icon;
GNotification *notification = g_notification_new ("Teleport"); GNotification *notification = g_notification_new ("Teleport");
g_notification_set_body (notification, g_notification_set_body (notification,
g_strdup_printf("%s is sending %s (%s)", g_strdup_printf("%s is sending %s (%s)",
origin_device, origin_device,
file_name, file_name,
g_format_size (file_size))); g_format_size (file_size)));
GIcon *icon = g_themed_icon_new ("dialog-information"); icon = g_themed_icon_new ("dialog-information");
g_notification_set_icon (notification, icon); g_notification_set_icon (notification, icon);
g_notification_set_default_action_and_target_value (notification, "app.do-nothing", target); g_notification_set_default_action_and_target_value (notification, "app.do-nothing", target);
g_notification_add_button_with_target_value (notification, "Decline", "app.decline", target); g_notification_add_button_with_target_value (notification, "Decline", "app.decline", target);
@@ -91,9 +92,10 @@ void create_user_notification (const char *file_name, const int file_size, const
} }
void create_finished_notification (const char *origin, const int filesize, const char *filename, GVariant *target) { void create_finished_notification (const char *origin, const int filesize, const char *filename, GVariant *target) {
GIcon *icon;
GNotification *notification = g_notification_new ("Teleport"); GNotification *notification = g_notification_new ("Teleport");
g_notification_set_body (notification, g_strdup_printf("Transfer of %s from %s is complete", filename, origin)); g_notification_set_body (notification, g_strdup_printf("Transfer of %s from %s is complete", filename, origin));
GIcon *icon = g_themed_icon_new ("dialog-information"); icon = g_themed_icon_new ("dialog-information");
g_notification_set_icon (notification, icon); g_notification_set_icon (notification, icon);
g_notification_set_default_action_and_target_value (notification, "app.do-nothing", target); g_notification_set_default_action_and_target_value (notification, "app.do-nothing", target);
g_notification_add_button_with_target_value (notification, "Open", "app.open-file", target); g_notification_add_button_with_target_value (notification, "Open", "app.open-file", target);
@@ -115,15 +117,15 @@ gboolean mainLoopRemovePeerCallback (gpointer peer) {
return G_SOURCE_REMOVE; return G_SOURCE_REMOVE;
} }
void callback_add_peer (GObject *instance, Peer *peer, TeleportAppWindow *win ) { void callback_add_peer (GObject *instance, Peer *peer, gpointer window) {
g_idle_add(mainLoopAddPeerCallback, peer); g_idle_add(mainLoopAddPeerCallback, peer);
} }
void callback_remove_peer (GObject *instance, Peer *peer, TeleportAppWindow *win ) { void callback_remove_peer (GObject *instance, Peer *peer, gpointer window) {
g_idle_add(mainLoopRemovePeerCallback, peer); g_idle_add(mainLoopRemovePeerCallback, peer);
} }
void callback_notify_user (GObject *instance, char *name, TeleportAppWindow *win ) { void callback_notify_user (GObject *instance, gchar *name, gpointer window) {
//create_user_notification("icon.png", 2000, "Mark's laptop"); //create_user_notification("icon.png", 2000, "Mark's laptop");
} }
@@ -135,8 +137,8 @@ teleport_app_init (TeleportApp *app) {
static void static void
teleport_app_activate (GApplication *app) { teleport_app_activate (GApplication *app) {
//TeleportAppWindow *win; //TeleportAppWindow *win;
application = app;
TeleportPeer *peerList = g_object_new (TELEPORT_TYPE_PEER, NULL); TeleportPeer *peerList = g_object_new (TELEPORT_TYPE_PEER, NULL);
application = app;
win = teleport_app_window_new (TELEPORT_APP (app)); win = teleport_app_window_new (TELEPORT_APP (app));
gtk_window_present (GTK_WINDOW (win)); gtk_window_present (GTK_WINDOW (win));

View File

@@ -2,7 +2,7 @@
#define __TELEPORTAPP_H #define __TELEPORTAPP_H
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include "teleportpeer.h"
#define TELEPORT_APP_TYPE (teleport_app_get_type ()) #define TELEPORT_APP_TYPE (teleport_app_get_type ())
G_DECLARE_FINAL_TYPE (TeleportApp, teleport_app, TELEPORT, APP, GtkApplication) G_DECLARE_FINAL_TYPE (TeleportApp, teleport_app, TELEPORT, APP, GtkApplication)
@@ -19,4 +19,18 @@ extern void create_finished_notification (const char *,
const char *, const char *,
GVariant *); GVariant *);
gboolean mainLoopAddPeerCallback (gpointer);
gboolean mainLoopRemovePeerCallback (gpointer);
void callback_add_peer (GObject *,
Peer *,
gpointer);
void callback_remove_peer (GObject *,
Peer *peer,
gpointer);
void callback_notify_user (GObject *,
gchar *,
gpointer);
#endif /* __TELEPORTAPP_H */ #endif /* __TELEPORTAPP_H */

View File

@@ -60,7 +60,7 @@ open_file_picker(GtkButton *btn, Peer *device) {
gint res; gint res;
g_print("Open file chooser for submitting a file to %s with Address %s\n", device->name, device->ip); g_print("Open file chooser for submitting a file to %s with Address %s\n", device->name, device->ip);
dialog = ("Open File", dialog = gtk_file_chooser_dialog_new ("Open File",
GTK_WINDOW(mainWin), GTK_WINDOW(mainWin),
action, action,
("_Cancel"), ("_Cancel"),
@@ -116,7 +116,6 @@ void update_remote_device_list_remove(TeleportAppWindow *win, Peer *device) {
GtkWidget *box; GtkWidget *box;
GtkListBoxRow *remote_row; GtkListBoxRow *remote_row;
GtkLabel *name_label; GtkLabel *name_label;
GtkWidget *line;
gint i = 0; gint i = 0;
priv = teleport_app_window_get_instance_private (win); priv = teleport_app_window_get_instance_private (win);
@@ -163,11 +162,11 @@ find_child(GtkWidget *parent, const gchar *name)
static void static void
teleport_app_window_dispose (GObject *object) teleport_app_window_dispose (GObject *object)
{ {
TeleportAppWindow *win; //TeleportAppWindow *win;
TeleportAppWindowPrivate *priv; //TeleportAppWindowPrivate *priv;
win = TELEPORT_APP_WINDOW (object); //win = TELEPORT_APP_WINDOW (object);
priv = teleport_app_window_get_instance_private (win); //priv = teleport_app_window_get_instance_private (win);
//g_clear_object (&priv->settings); //g_clear_object (&priv->settings);
@@ -197,6 +196,6 @@ teleport_app_window_new (TeleportApp *app)
teleport_app_window_open (TeleportAppWindow *win, teleport_app_window_open (TeleportAppWindow *win,
GFile *file) GFile *file)
{ {
TeleportAppWindowPrivate *priv; //TeleportAppWindowPrivate *priv;
priv = teleport_app_window_get_instance_private (win); //priv = teleport_app_window_get_instance_private (win);
} }

View File

@@ -60,11 +60,12 @@ teleport_peer_init (TeleportPeer *self)
gchar * teleport_peer_get_name (TeleportPeer *self, gint index, GError **error) gchar * teleport_peer_get_name (TeleportPeer *self, gint index, GError **error)
{ {
Peer *element;
//g_return_if_fail (TELEPORT_IS_PEER (self)); //g_return_if_fail (TELEPORT_IS_PEER (self));
//g_return_if_fail (error == NULL || *error == NULL); //g_return_if_fail (error == NULL || *error == NULL);
if (index > self->list->len-1) if (index > self->list->len-1)
return NULL; return NULL;
Peer *element = g_array_index(self->list, Peer *, index); element = g_array_index(self->list, Peer *, index);
return element->name; return element->name;
} }
@@ -113,10 +114,9 @@ void teleport_peer_remove_peer (TeleportPeer *self, Peer *device)
void teleport_peer_remove_peer_by_name (TeleportPeer *self, gchar *name) void teleport_peer_remove_peer_by_name (TeleportPeer *self, gchar *name)
{ {
Peer *element = NULL;
g_print("Remove this device %s", name);
Peer *element;
gboolean found = FALSE; gboolean found = FALSE;
g_print("Remove this device %s", name);
for (int i = 0; i < self->list->len && !found; i++) { for (int i = 0; i < self->list->len && !found; i++) {
element = g_array_index(self->list, Peer *, i); element = g_array_index(self->list, Peer *, i);
if (g_strcmp0(element->name, name) == 0) { if (g_strcmp0(element->name, name) == 0) {