Merge lp:~kalikiana/midori/gap into lp:midori

Proposed by Cris Dywan
Status: Merged
Approved by: Paweł Forysiuk
Approved revision: 6362
Merged at revision: 6369
Proposed branch: lp:~kalikiana/midori/gap
Merge into: lp:midori
Diff against target: 2433 lines (+174/-2049)
7 files modified
midori/midori-app.c (+166/-362)
midori/midori-frontend.c (+8/-8)
midori/midori-view.c (+0/-7)
midori/socket.c (+0/-1542)
midori/socket.h (+0/-105)
po/POTFILES.in (+0/-1)
wscript (+0/-24)
To merge this branch: bzr merge lp:~kalikiana/midori/gap
Reviewer Review Type Date Requested Status
Paweł Forysiuk Approve
Review via email: mp+181431@code.launchpad.net

Commit message

Port MidoriApp from Unique/ sockets to GApplication

To post a comment you must log in.
lp:~kalikiana/midori/gap updated
6357. By Cris Dywan

Separate open from command and use n_files in loops

6358. By Cris Dywan

Use pseudo command URIs to prevent GFile constructing filenames

6359. By Cris Dywan

Use open hint to pass individual commands

6360. By Cris Dywan

Don't escape URLs passed between application instances

6361. By Cris Dywan

Add tracing for app code paths via MIDORI_DEBUG=app

6362. By Cris Dywan

Use send/ receive to disambiguate app debug output

Revision history for this message
Paweł Forysiuk (tuxator) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'midori/midori-app.c'
2--- midori/midori-app.c 2013-08-09 08:13:23 +0000
3+++ midori/midori-app.c 2013-09-01 12:49:57 +0000
4@@ -33,23 +33,6 @@
5 #include <locale.h>
6 #endif
7
8-#if HAVE_UNIQUE
9- typedef gpointer MidoriAppInstance;
10- #define MidoriAppInstanceNull NULL
11- #if defined(G_DISABLE_DEPRECATED) && !defined(G_CONST_RETURN)
12- #define G_CONST_RETURN
13- #endif
14- #include <unique/unique.h>
15- #ifdef G_DISABLE_DEPRECATED
16- #undef G_CONST_RETUTN
17- #endif
18- #define MIDORI_UNIQUE_COMMAND 1
19-#else
20- typedef gint MidoriAppInstance;
21- #define MidoriAppInstanceNull -1
22- #include "socket.h"
23-#endif
24-
25 #if HAVE_LIBNOTIFY
26 #include <libnotify/notify.h>
27 #ifndef NOTIFY_CHECK_VERSION
28@@ -63,7 +46,7 @@
29
30 struct _MidoriApp
31 {
32- GObject parent_instance;
33+ GApplication parent_instance;
34
35 MidoriWebSettings* settings;
36 KatzeArray* bookmarks;
37@@ -75,14 +58,13 @@
38 KatzeArray* browsers;
39
40 MidoriBrowser* browser;
41- MidoriAppInstance instance;
42 };
43
44 static gchar* app_name = NULL;
45
46 struct _MidoriAppClass
47 {
48- GObjectClass parent_class;
49+ GApplicationClass parent_class;
50
51 /* Signals */
52 void
53@@ -95,7 +77,7 @@
54 (*quit) (MidoriApp* app);
55 };
56
57-G_DEFINE_TYPE (MidoriApp, midori_app, G_TYPE_OBJECT)
58+G_DEFINE_TYPE (MidoriApp, midori_app, G_TYPE_APPLICATION);
59
60 enum
61 {
62@@ -246,12 +228,6 @@
63 #endif
64
65 app->browser = browser;
66- #if HAVE_UNIQUE
67- /* We *do not* let unique watch windows because that includes
68- bringing windows in the foreground, even from other workspaces.
69- if (app->instance)
70- unique_app_watch_window (app->instance, GTK_WINDOW (browser)); */
71- #endif
72 }
73
74 #ifdef HAVE_SIGNAL_H
75@@ -473,265 +449,161 @@
76 midori_app_raise_window (GtkWindow* window,
77 GdkScreen* screen)
78 {
79- gtk_window_set_screen (window, screen);
80+ if (screen)
81+ gtk_window_set_screen (window, screen);
82 gtk_window_present (window);
83 gtk_window_deiconify (window);
84 }
85
86-static gboolean
87-midori_app_command_received (MidoriApp* app,
88- const gchar* command,
89- gchar** uris,
90- GdkScreen* screen)
91-{
92- if (!screen)
93- {
94- if (app->browser && gtk_widget_has_screen (GTK_WIDGET (app->browser)))
95- screen = gtk_widget_get_screen (GTK_WIDGET (app->browser));
96- else
97- screen = gdk_screen_get_default ();
98- }
99-
100- if (g_str_equal (command, "activate"))
101- {
102- if (!app->browser)
103- return FALSE;
104-
105- midori_app_raise_window (GTK_WINDOW (app->browser), screen);
106- return TRUE;
107- }
108- else if (g_str_equal (command, "new"))
109+static void
110+midori_app_debug_open (MidoriApp* app,
111+ GFile** files,
112+ gint n_files,
113+ const gchar* hint)
114+{
115+ if (midori_debug ("app"))
116+ {
117+ g_print ("app(%s) open: %d files [",
118+ g_application_get_is_remote (G_APPLICATION (app)) ? "send" : "receive",
119+ n_files);
120+ gint i;
121+ for (i = 0; i < n_files; i++)
122+ {
123+ gchar* uri = g_file_get_uri (files[i]);
124+ g_print ("%s ", uri);
125+ g_free (uri);
126+ }
127+ g_print ("] hint '%s'\n", hint);
128+ }
129+}
130+
131+static void
132+midori_app_activate_cb (MidoriApp* app,
133+ gpointer user_data)
134+{
135+ if (midori_debug ("app"))
136+ g_print ("app(receive) activate\n");
137+ if (app->browser)
138+ midori_app_raise_window (GTK_WINDOW (app->browser), NULL);
139+}
140+
141+static void
142+midori_app_open_cb (MidoriApp* app,
143+ GFile** files,
144+ gint n_files,
145+ gchar* hint,
146+ gpointer user_data)
147+{
148+ midori_app_debug_open (app, files, n_files, hint);
149+
150+ if (!strcmp (hint, "window"))
151 {
152 MidoriBrowser* browser = midori_app_create_browser (app);
153 midori_app_add_browser (app, browser);
154 midori_browser_add_uri (browser, "about:home");
155 midori_browser_activate_action (browser, "Location");
156 gtk_widget_show (GTK_WIDGET (browser));
157- midori_app_raise_window (GTK_WINDOW (browser), screen);
158- return TRUE;
159- }
160- else if (g_str_equal (command, "open"))
161- {
162- if (!app->browser)
163- return FALSE;
164-
165- if (!uris)
166- return FALSE;
167- else
168+ midori_app_raise_window (GTK_WINDOW (browser), NULL);
169+ return;
170+ }
171+
172+ if (n_files == 0 && strcmp (hint, ""))
173+ {
174+ midori_browser_activate_action (app->browser, hint);
175+ return;
176+ }
177+
178+ MidoriBrowser* browser;
179+ MidoriNewPage open_external_pages_in;
180+ gboolean first;
181+
182+ g_object_get (app->settings, "open-new-pages-in", &open_external_pages_in, NULL);
183+ if (open_external_pages_in == MIDORI_NEW_PAGE_WINDOW)
184+ {
185+ browser = midori_app_create_browser (app);
186+ midori_app_add_browser (app, browser);
187+ gtk_widget_show (GTK_WIDGET (browser));
188+ }
189+ else
190+ browser = app->browser;
191+ midori_app_raise_window (GTK_WINDOW (browser), NULL);
192+
193+ first = (open_external_pages_in == MIDORI_NEW_PAGE_CURRENT);
194+
195+ gint i;
196+ for (i = 0; i < n_files; i++)
197+ {
198+ gchar* uri = g_file_get_uri (files[i]);
199+ if (sokoke_recursive_fork_protection (uri, FALSE))
200 {
201- MidoriBrowser* browser;
202- MidoriNewPage open_external_pages_in;
203- gboolean first;
204-
205- g_object_get (app->settings, "open-new-pages-in",
206- &open_external_pages_in, NULL);
207- if (open_external_pages_in == MIDORI_NEW_PAGE_WINDOW)
208+ if (first)
209 {
210- browser = midori_app_create_browser (app);
211- midori_app_add_browser (app, browser);
212- gtk_widget_show (GTK_WIDGET (browser));
213+ midori_browser_set_current_uri (browser, uri);
214+ first = FALSE;
215 }
216 else
217- browser = app->browser;
218-
219- midori_app_raise_window (GTK_WINDOW (browser), screen);
220-
221- first = (open_external_pages_in == MIDORI_NEW_PAGE_CURRENT);
222- while (*uris)
223- {
224- gchar* fixed_uri = g_uri_unescape_string (*uris, NULL);
225- if (sokoke_recursive_fork_protection (fixed_uri, FALSE))
226- {
227- if (first)
228- {
229- midori_browser_set_current_uri (browser, fixed_uri);
230- first = FALSE;
231- }
232- else
233- {
234- /* Switch to already open tab if possible */
235- KatzeArray* items = midori_browser_get_proxy_array (browser);
236- KatzeItem* found = katze_array_find_uri (items, fixed_uri);
237- if (found != NULL)
238- midori_browser_set_current_item (browser, found);
239- else
240- midori_browser_set_current_tab (browser,
241- midori_browser_add_uri (browser, fixed_uri));
242- }
243- }
244- g_free (fixed_uri);
245- uris++;
246- }
247- return TRUE;
248- }
249- }
250- else if (g_str_equal (command, "command"))
251- {
252- if (!uris || !app->browser)
253- return FALSE;
254- gint i;
255- for (i = 0; uris && uris[i]; i++)
256- midori_browser_activate_action (app->browser, uris[i]);
257- return TRUE;
258- }
259-
260- return FALSE;
261-}
262-
263-#if HAVE_UNIQUE
264-static UniqueResponse
265-midori_browser_message_received_cb (UniqueApp* instance,
266- gint command,
267- UniqueMessageData* message,
268- guint timestamp,
269- MidoriApp* app)
270-{
271- gboolean success;
272- GdkScreen* screen = unique_message_data_get_screen (message);
273-
274- switch (command)
275- {
276- case UNIQUE_ACTIVATE:
277- success = midori_app_command_received (app, "activate", NULL, screen);
278- break;
279- case UNIQUE_NEW:
280- success = midori_app_command_received (app, "new", NULL, screen);
281- break;
282- case UNIQUE_OPEN:
283- {
284- gchar** uris = unique_message_data_get_uris (message);
285- success = midori_app_command_received (app, "open", uris, screen);
286- /* g_strfreev (uris); */
287- break;
288- }
289- case MIDORI_UNIQUE_COMMAND:
290- {
291- gchar** uris = unique_message_data_get_uris (message);
292- success = midori_app_command_received (app, "command", uris, screen);
293- /* g_strfreev (uris); */
294- break;
295- }
296- default:
297- success = FALSE;
298- break;
299- }
300-
301- return success ? UNIQUE_RESPONSE_OK : UNIQUE_RESPONSE_FAIL;
302-}
303-#else
304-static gboolean
305-midori_app_io_channel_watch_cb (GIOChannel* channel,
306- GIOCondition condition,
307- MidoriApp* app)
308-{
309- GdkScreen* screen = gtk_widget_get_screen (GTK_WIDGET (app->browser));
310- gint fd, sock;
311- gchar buf[4096];
312- struct sockaddr_in caddr;
313- guint caddr_len = sizeof(caddr);
314-
315- fd = app->instance;
316- sock = accept (fd, (struct sockaddr *)&caddr, &caddr_len);
317-
318- while (fd_gets (sock, buf, sizeof (buf)) != -1)
319- {
320- if (strncmp (buf, "activate", 8) == 0)
321- {
322- midori_app_command_received (app, "open", NULL, screen);
323- }
324- else if (strncmp (buf, "new", 3) == 0)
325- {
326- midori_app_command_received (app, "new", NULL, screen);
327- }
328- else if (strncmp (buf, "open", 4) == 0)
329- {
330- while (fd_gets (sock, buf, sizeof (buf)) != -1 && *buf != '.')
331- {
332- gchar** uris = g_strsplit (g_strstrip (buf), "\n", 2);
333- midori_app_command_received (app, "open", uris, screen);
334- g_strfreev (uris);
335- }
336- }
337- else if (strncmp (buf, "command", 7) == 0)
338- {
339- guint i = 0;
340- gchar** uris = g_new (gchar*, 100);
341- while (fd_gets (sock, buf, sizeof (buf)) != -1 && *buf != '.')
342- {
343- uris[i++] = g_strdup (g_strstrip (buf));
344- if (i == 99)
345- break;
346- }
347- uris[i] = NULL;
348- midori_app_command_received (app, "command", uris, screen);
349- g_strfreev (uris);
350- }
351- }
352-
353- fd_close (sock);
354-
355- return TRUE;
356-}
357-#endif
358-
359-static MidoriAppInstance
360+ {
361+ /* Switch to already open tab if possible */
362+ KatzeArray* items = midori_browser_get_proxy_array (browser);
363+ KatzeItem* found = katze_array_find_uri (items, uri);
364+ if (found != NULL)
365+ midori_browser_set_current_item (browser, found);
366+ else
367+ midori_browser_set_current_tab (browser,
368+ midori_browser_add_uri (browser, uri));
369+ }
370+ }
371+ g_free (uri);
372+ }
373+}
374+
375+static void
376+midori_app_startup_cb (GApplication* app,
377+ gpointer user_data)
378+{
379+ g_signal_connect (app, "activate",
380+ G_CALLBACK (midori_app_activate_cb), NULL);
381+ g_signal_connect (app, "open",
382+ G_CALLBACK (midori_app_open_cb), NULL);
383+}
384+
385+static void
386 midori_app_create_instance (MidoriApp* app)
387 {
388- MidoriAppInstance instance;
389- GdkDisplay* display;
390- gchar* display_name;
391- gchar* instance_name;
392- #if !HAVE_UNIQUE
393- gboolean exists;
394- GIOChannel* channel;
395- #endif
396-
397- if (!(display = gdk_display_get_default ()))
398- return MidoriAppInstanceNull;
399-
400- {
401- #if HAVE_UNIQUE
402- const gchar* config = midori_paths_get_config_dir_for_reading ();
403- gchar* config_hash = g_compute_checksum_for_string (G_CHECKSUM_MD5, config, -1);
404- gchar* name_hash = g_compute_checksum_for_string (G_CHECKSUM_MD5, app_name, -1);
405- katze_assign (app_name, g_strconcat (PACKAGE_NAME,
406- "_", config_hash, "_", name_hash, NULL));
407- g_free (config_hash);
408- g_free (name_hash);
409- #else
410- katze_assign (app_name, g_strdup (PACKAGE_NAME));
411- #endif
412- g_object_notify (G_OBJECT (app), "name");
413- }
414-
415+ if (g_application_get_is_registered (G_APPLICATION (app)))
416+ return;
417+
418+ const gchar* config = midori_paths_get_config_dir_for_reading ();
419+ gchar* config_hash = g_compute_checksum_for_string (G_CHECKSUM_MD5, config, -1);
420+ gchar* name_hash = g_compute_checksum_for_string (G_CHECKSUM_MD5, app_name, -1);
421+ katze_assign (app_name, g_strconcat (PACKAGE_NAME,
422+ "_", config_hash, "_", name_hash, NULL));
423+ g_free (config_hash);
424+ g_free (name_hash);
425+ g_object_notify (G_OBJECT (app), "name");
426+
427+ GdkDisplay* display = gdk_display_get_default ();
428 #ifdef GDK_WINDOWING_X11
429 /* On X11: :0 or :0.0 which is equivalent */
430- display_name = g_strndup (gdk_display_get_name (display), 2);
431+ gchar* display_name = g_strndup (gdk_display_get_name (display), 2);
432 #else
433- display_name = g_strdup (gdk_display_get_name (display));
434+ gchar* display_name = g_strdup (gdk_display_get_name (display));
435 #endif
436 g_strdelimit (display_name, ":.\\/", '_');
437- instance_name = g_strdup_printf ("de.twotoasts.%s_%s", app_name, display_name);
438+ gchar* instance_name = g_strdup_printf ("de.twotoasts.%s_%s", app_name, display_name);
439 g_free (display_name);
440 katze_assign (app_name, instance_name);
441
442- #if HAVE_UNIQUE
443- instance = unique_app_new (instance_name, NULL);
444- unique_app_add_command (instance, "midori-command", MIDORI_UNIQUE_COMMAND);
445- g_signal_connect (instance, "message-received",
446- G_CALLBACK (midori_browser_message_received_cb), app);
447- #else
448- instance = socket_init (instance_name, midori_paths_get_config_dir_for_writing (), &exists);
449- g_object_set_data (G_OBJECT (app), "sock-exists",
450- exists ? (gpointer)0xdeadbeef : NULL);
451- if (instance != MidoriAppInstanceNull)
452- {
453- channel = g_io_channel_unix_new (instance);
454- g_io_add_watch (channel, G_IO_IN | G_IO_PRI | G_IO_ERR,
455- (GIOFunc)midori_app_io_channel_watch_cb, app);
456- }
457- #endif
458- return instance;
459+ if (midori_debug ("app"))
460+ g_print ("app registering %s\n", app_name);
461+ g_object_set (app,
462+ "application-id", app_name,
463+ "flags", G_APPLICATION_HANDLES_OPEN,
464+ NULL);
465+ g_signal_connect (app, "startup", G_CALLBACK (midori_app_startup_cb), NULL);
466+ GError* error = NULL;
467+ if (!g_application_register (G_APPLICATION (app), NULL, &error))
468+ midori_error (error->message);
469 }
470
471 const gchar*
472@@ -787,8 +659,6 @@
473 app->extensions = katze_array_new (KATZE_TYPE_ARRAY);
474 app->browsers = katze_array_new (MIDORI_TYPE_BROWSER);
475
476- app->instance = MidoriAppInstanceNull;
477-
478 #if HAVE_LIBNOTIFY
479 notify_init (PACKAGE_NAME);
480 #endif
481@@ -809,12 +679,6 @@
482 katze_object_assign (app->extensions, NULL);
483 katze_object_assign (app->browsers, NULL);
484
485- #if HAVE_UNIQUE
486- katze_object_assign (app->instance, NULL);
487- #else
488- sock_cleanup ();
489- #endif
490-
491 #if HAVE_LIBNOTIFY
492 if (notify_is_initted ())
493 notify_uninit ();
494@@ -973,14 +837,8 @@
495 else if (instance_is_running)
496 return TRUE;
497
498- if (app->instance == MidoriAppInstanceNull)
499- app->instance = midori_app_create_instance (app);
500-
501- #if HAVE_UNIQUE
502- return app->instance && unique_app_is_running (app->instance);
503- #else
504- return g_object_get_data (G_OBJECT (app), "sock-exists") != NULL;
505- #endif
506+ midori_app_create_instance (app);
507+ return g_application_get_is_remote (G_APPLICATION (app));
508 }
509
510 /**
511@@ -1000,21 +858,10 @@
512 g_return_val_if_fail (MIDORI_IS_APP (app), FALSE);
513 g_return_val_if_fail (midori_app_instance_is_running (app), FALSE);
514
515- #if HAVE_UNIQUE
516- if (app->instance)
517- {
518- UniqueResponse response = unique_app_send_message (app->instance, UNIQUE_ACTIVATE, NULL);
519- if (response == UNIQUE_RESPONSE_OK)
520- return TRUE;
521- }
522- #else
523- if (app->instance > -1)
524- {
525- send_open_command (app->instance, "activate", NULL);
526- return TRUE;
527- }
528- #endif
529- return FALSE;
530+ if (midori_debug ("app"))
531+ g_print ("app(send) activate\n");
532+ g_application_activate (G_APPLICATION (app));
533+ return TRUE;
534 }
535
536 /**
537@@ -1032,21 +879,9 @@
538 g_return_val_if_fail (MIDORI_IS_APP (app), FALSE);
539 g_return_val_if_fail (midori_app_instance_is_running (app), FALSE);
540
541- #if HAVE_UNIQUE
542- if (app->instance)
543- {
544- UniqueResponse response = unique_app_send_message (app->instance, UNIQUE_NEW, NULL);
545- if (response == UNIQUE_RESPONSE_OK)
546- return TRUE;
547- }
548- #else
549- if (app->instance > -1)
550- {
551- send_open_command (app->instance, "new", NULL);
552- return TRUE;
553- }
554- #endif
555- return FALSE;
556+ midori_app_debug_open (app, NULL, -1, "window");
557+ g_application_open (G_APPLICATION (app), NULL, -1, "window");
558+ return TRUE;
559 }
560
561 /**
562@@ -1069,37 +904,19 @@
563 g_return_val_if_fail (midori_app_instance_is_running (app), FALSE);
564 g_return_val_if_fail (uris != NULL, FALSE);
565
566- #if HAVE_UNIQUE
567- if (app->instance)
568- {
569- UniqueMessageData* message;
570- UniqueResponse response;
571- /* Encode any IDN addresses because libUnique doesn't like them */
572- int i = 0;
573- while (uris[i] != NULL)
574- {
575- gchar* new_uri = sokoke_magic_uri (uris[i], TRUE, TRUE);
576- gchar* escaped_uri = g_uri_escape_string (new_uri, NULL, FALSE);
577- g_free (new_uri);
578- katze_assign (uris[i], escaped_uri);
579- i++;
580- }
581-
582- message = unique_message_data_new ();
583- unique_message_data_set_uris (message, uris);
584- response = unique_app_send_message (app->instance, UNIQUE_OPEN, message);
585- unique_message_data_free (message);
586- if (response == UNIQUE_RESPONSE_OK)
587- return TRUE;
588- }
589- #else
590- if (app->instance > -1)
591- {
592- send_open_command (app->instance, "open", uris);
593- return TRUE;
594- }
595- #endif
596- return FALSE;
597+ gint n_files = g_strv_length (uris);
598+ GFile** files = g_new (GFile*, n_files);
599+ /* Encode URLs to avoid GFile treating them wrongly */
600+ int i;
601+ for (i = 0; i < n_files; i++)
602+ {
603+ gchar* new_uri = sokoke_magic_uri (uris[i], TRUE, TRUE);
604+ files[i] = g_file_new_for_uri (new_uri);
605+ g_free (new_uri);
606+ }
607+ midori_app_debug_open (app, files, n_files, "");
608+ g_application_open (G_APPLICATION (app), files, n_files, "");
609+ return TRUE;
610 }
611
612 /**
613@@ -1128,32 +945,19 @@
614 {
615 MidoriBrowser* browser = midori_browser_new ();
616 int i;
617- for (i=0; command && command[i]; i++)
618+ for (i = 0; command && command[i]; i++)
619 midori_browser_assert_action (browser, command[i]);
620 gtk_widget_destroy (GTK_WIDGET (browser));
621- return midori_app_command_received (app, "command", command, NULL);
622 }
623
624- #if HAVE_UNIQUE
625- if (app->instance)
626- {
627- UniqueResponse response;
628- UniqueMessageData* message = unique_message_data_new ();
629- unique_message_data_set_uris (message, command);
630- response = unique_app_send_message (app->instance,
631- MIDORI_UNIQUE_COMMAND, message);
632- unique_message_data_free (message);
633- if (response == UNIQUE_RESPONSE_OK)
634- return TRUE;
635- }
636- #else
637- if (app->instance > -1)
638- {
639- send_open_command (app->instance, "command", command);
640- return TRUE;
641- }
642- #endif
643- return FALSE;
644+ gint n_files = g_strv_length (command);
645+ int i;
646+ for (i = 0; i < n_files; i++)
647+ {
648+ midori_app_debug_open (app, NULL, 0, command[i]);
649+ g_application_open (G_APPLICATION (app), NULL, 0, command[i]);
650+ }
651+ return TRUE;
652 }
653
654 /**
655@@ -1443,7 +1247,7 @@
656 midori_debug (const gchar* token)
657 {
658 static const gchar* debug_token = NULL;
659- const gchar* debug_tokens = "headers body referer cookies paths hsts unarmed bookmarks mouse ";
660+ const gchar* debug_tokens = "headers body referer cookies paths hsts unarmed bookmarks mouse app ";
661 const gchar* full_debug_tokens = "adblock:match adblock:time startup ";
662 if (debug_token == NULL)
663 {
664
665=== modified file 'midori/midori-frontend.c'
666--- midori/midori-frontend.c 2013-08-12 19:21:06 +0000
667+++ midori/midori-frontend.c 2013-09-01 12:49:57 +0000
668@@ -446,14 +446,14 @@
669 /* It makes no sense to show a crash dialog while running */
670 if (!diagnostic_dialog)
671 {
672- gboolean success = FALSE;
673- if (execute_commands != NULL && midori_app_send_command (app, execute_commands))
674- success = TRUE;
675- if (open_uris != NULL && midori_app_instance_send_uris (app, open_uris))
676- success = TRUE;
677- if (!execute_commands && !open_uris && midori_app_instance_send_new_browser (app))
678- success = TRUE;
679- if (success)
680+ if (execute_commands != NULL)
681+ midori_app_send_command (app, execute_commands);
682+ if (open_uris != NULL)
683+ midori_app_instance_send_uris (app, open_uris);
684+ if (!execute_commands && !open_uris)
685+ midori_app_instance_send_new_browser (app);
686+
687+ if (g_application_get_is_registered (G_APPLICATION (app)))
688 return NULL;
689 }
690
691
692=== modified file 'midori/midori-view.c'
693--- midori/midori-view.c 2013-09-01 12:20:28 +0000
694+++ midori/midori-view.c 2013-09-01 12:49:57 +0000
695@@ -3666,13 +3666,6 @@
696 LIBNOTIFY_VERSION));
697 midori_view_add_version (markup, html, g_strdup_printf ("gcr %s\tgranite %s",
698 GCR_VERSION, GRANITE_VERSION));
699- midori_view_add_version (markup, html, g_strdup_printf ("single instance %s",
700- #if HAVE_UNIQUE
701- "libunique " UNIQUE_VERSION
702- #else
703- "Sockets"
704- #endif
705- ));
706 }
707
708 #ifdef HAVE_WEBKIT2
709
710=== removed file 'midori/socket.c'
711--- midori/socket.c 2013-04-07 19:34:42 +0000
712+++ midori/socket.c 1970-01-01 00:00:00 +0000
713@@ -1,1542 +0,0 @@
714-/*
715- Copyright 1999-2008 Hiroyuki Yamamoto
716- Copyright 2006-2009 Enrico Tröger <enrico.troeger@uvena.de>
717-
718- This library is free software; you can redistribute it and/or
719- modify it under the terms of the GNU Lesser General Public
720- License as published by the Free Software Foundation; either
721- version 2.1 of the License, or (at your option) any later version.
722-
723- See the file COPYING for the full license text.
724-*/
725-
726-/*
727- This file is based on socket.c in libSylph.
728- socket_init(), remove_socket_link_full() and send_open_command() were
729- relicensed and taken from Geany and adjusted to be more generic.
730-*/
731-
732-#if HAVE_CONFIG_H
733-# include "config.h"
734-#endif
735-
736-#if !HAVE_UNIQUE
737-
738-#include <glib.h>
739-#include <glib/gstdio.h>
740-#include <sys/time.h>
741-#include <sys/types.h>
742-#ifdef G_OS_WIN32
743-# include <winsock2.h>
744-# include <ws2tcpip.h>
745-#else
746-# if HAVE_SYS_WAIT_H
747-# include <sys/wait.h>
748-# endif
749-# include <sys/socket.h>
750-# include <sys/un.h>
751-# include <netinet/in.h>
752-# include <arpa/inet.h>
753-# include <netdb.h>
754-#endif /* G_OS_WIN32 */
755-#if HAVE_UNISTD_H
756-# include <unistd.h>
757-#endif
758-#include <stdio.h>
759-#include <string.h>
760-#include <stdarg.h>
761-#include <fcntl.h>
762-#include <errno.h>
763-#include <signal.h>
764-#include <setjmp.h>
765-#if HAVE_SYS_SELECT_H
766-# include <sys/select.h>
767-#endif
768-
769-#include "socket.h"
770-
771-#define BUFFSIZE 8192
772-
773-#ifdef G_OS_WIN32
774-#define SockDesc SOCKET
775-#define SOCKET_IS_VALID(s) ((s) != INVALID_SOCKET)
776-#else
777-#define SockDesc gint
778-#define SOCKET_IS_VALID(s) ((s) >= 0)
779-#define INVALID_SOCKET (-1)
780-#endif
781-
782-typedef gint (*SockAddrFunc) (GList *addr_list,
783- gpointer data);
784-
785-typedef struct _SockConnectData SockConnectData;
786-typedef struct _SockLookupData SockLookupData;
787-typedef struct _SockAddrData SockAddrData;
788-typedef struct _SockSource SockSource;
789-
790-struct _SockConnectData {
791- gint id;
792- gchar *hostname;
793- gushort port;
794- GList *addr_list;
795- GList *cur_addr;
796- SockLookupData *lookup_data;
797- GIOChannel *channel;
798- guint io_tag;
799- SockConnectFunc func;
800- gpointer data;
801-};
802-
803-struct _SockLookupData {
804- gchar *hostname;
805- pid_t child_pid;
806- GIOChannel *channel;
807- guint io_tag;
808- SockAddrFunc func;
809- gpointer data;
810-};
811-
812-struct _SockAddrData {
813- gint family;
814- gint socktype;
815- gint protocol;
816- gint addr_len;
817- struct sockaddr *addr;
818-};
819-
820-struct _SockSource {
821- GSource parent;
822- SockInfo *sock;
823-};
824-
825-static guint io_timeout = 60;
826-
827-static GList *sock_list = NULL;
828-
829-#ifdef G_OS_UNIX
830-static GList *sock_connect_data_list = NULL;
831-
832-static gchar *socket_filename = NULL;
833-#endif
834-
835-static gboolean sock_prepare (GSource *source,
836- gint *timeout);
837-static gboolean sock_check (GSource *source);
838-static gboolean sock_dispatch (GSource *source,
839- GSourceFunc callback,
840- gpointer user_data);
841-
842-GSourceFuncs sock_watch_funcs = {
843- sock_prepare,
844- sock_check,
845- sock_dispatch,
846- NULL
847-};
848-
849-gint fd_recv (gint fd,
850- gchar *buf,
851- gint len,
852- gint flags);
853-
854-#ifdef G_OS_WIN32
855-static SockInfo *sock_find_from_fd (gint fd);
856-#endif
857-
858-static gint sock_connect_with_timeout (gint sock,
859- const struct sockaddr *serv_addr,
860- gint addrlen,
861- guint timeout_secs);
862-
863-#ifndef INET6
864-static gint sock_connect_by_hostname (gint sock,
865- const gchar *hostname,
866- gushort port);
867-#else
868-static SockDesc sock_connect_by_getaddrinfo (const gchar *hostname,
869- gushort port);
870-#endif
871-
872-#ifdef G_OS_UNIX
873-static void sock_address_list_free (GList *addr_list);
874-
875-static gboolean sock_connect_async_cb (GIOChannel *source,
876- GIOCondition condition,
877- gpointer data);
878-static gint sock_connect_async_get_address_info_cb
879- (GList *addr_list,
880- gpointer data);
881-
882-static gint sock_connect_address_list_async (SockConnectData *conn_data);
883-
884-static gboolean sock_get_address_info_async_cb (GIOChannel *source,
885- GIOCondition condition,
886- gpointer data);
887-static SockLookupData *sock_get_address_info_async
888- (const gchar *hostname,
889- gushort port,
890- SockAddrFunc func,
891- gpointer data);
892-static gint sock_get_address_info_async_cancel (SockLookupData *lookup_data);
893-#endif /* G_OS_UNIX */
894-
895-void send_open_command(gint sock, const gchar* command, gchar **args)
896-{
897- gsize i;
898-
899- g_return_if_fail(sock > -1);
900- g_return_if_fail(command != NULL);
901-
902- fd_write_all(sock, command, strlen(command));
903- fd_write_all(sock, "\n", 1);
904-
905- if(!args)
906- return;
907-
908- for (i = 0; args[i] != NULL; i++)
909- {
910- fd_write_all(sock, args[i], strlen(args[i]));
911- fd_write_all(sock, "\n", 1);
912- }
913- fd_write_all(sock, ".\n", 2);
914-}
915-
916-#ifndef G_OS_WIN32
917-static void remove_socket_link_full(void)
918-{
919- gchar real_path[512];
920- gsize len;
921-
922- real_path[0] = '\0';
923-
924- /* read the contents of the symbolic link socket_info.file_name and delete it
925- * readlink should return something like "/tmp/appname_socket.499602d2" */
926- len = readlink(socket_filename, real_path, sizeof(real_path) - 1);
927- if ((gint) len > 0)
928- {
929- real_path[len] = '\0';
930- g_unlink(real_path);
931- }
932- g_unlink(socket_filename);
933-}
934-#endif
935-
936-/* (Unix domain) socket support to replace the old FIFO code
937- * Returns created socket, -1 if an error occurred */
938-gint socket_init(const gchar *instance_name, const gchar *config_dir, gboolean *exists)
939-{
940- gint sock;
941-#ifdef G_OS_WIN32
942- HANDLE hmutex;
943- WSADATA wsadata;
944- gint result;
945-
946- *exists = FALSE;
947- result = WSAStartup(MAKEWORD(2, 2), &wsadata);
948- if (result != NO_ERROR) {
949- g_warning("WSAStartup() failed\n");
950- return -1;
951- }
952-
953- hmutex = CreateMutexA(NULL, FALSE, instance_name);
954- if (! hmutex)
955- {
956- g_debug ("cannot create Mutex\n");
957- return -1;
958- }
959- if (GetLastError() != ERROR_ALREADY_EXISTS)
960- {
961- /* To support multiple instances with different configuration directories (as we do on
962- * non-Windows systems) we would need to use different port number s but it might be
963- * difficult to get a port number which is unique for a configuration directory (path)
964- * and which is unused. This port number has to be guessed by the first and new instance
965- * and the only data is the configuration directory path.
966- * For now we use one port number, that is we support only one instance at all. */
967- sock = fd_open_inet(49876);
968- if (sock < 0)
969- return 0;
970- return sock;
971- }
972-
973- sock = fd_connect_inet(49876);
974- if (sock < 0)
975- return -1;
976-#else
977- *exists = FALSE;
978- if (socket_filename == NULL)
979- socket_filename = g_strdup_printf("%s%c%s_socket_%s_%s",
980- config_dir, G_DIR_SEPARATOR, PACKAGE_NAME, g_get_host_name(), instance_name);
981-
982- sock = fd_connect_unix(socket_filename);
983- if (sock < 0)
984- {
985- remove_socket_link_full(); /* deletes the socket file and the symlink */
986- return fd_open_unix(socket_filename);
987- }
988-#endif
989- *exists = TRUE;
990- return sock;
991-}
992-
993-gint sock_cleanup(void)
994-{
995-#ifdef G_OS_WIN32
996- WSACleanup();
997-#else
998- if (socket_filename != NULL)
999- {
1000- remove_socket_link_full(); /* deletes the socket file and the symlink */
1001- g_free(socket_filename);
1002- }
1003-#endif
1004- return 0;
1005-}
1006-
1007-gint sock_set_io_timeout(guint sec)
1008-{
1009- io_timeout = sec;
1010- return 0;
1011-}
1012-
1013-gint fd_connect_inet(gushort port)
1014-{
1015- SockDesc sock;
1016- struct sockaddr_in addr;
1017-
1018- sock = socket(AF_INET, SOCK_STREAM, 0);
1019- if (!SOCKET_IS_VALID(sock)) {
1020-#ifdef G_OS_WIN32
1021- g_warning("fd_connect_inet(): socket() failed: %d\n",
1022- WSAGetLastError());
1023-#else
1024- perror("fd_connect_inet(): socket");
1025-#endif
1026- return -1;
1027- }
1028-
1029- memset(&addr, 0, sizeof(addr));
1030- addr.sin_family = AF_INET;
1031- addr.sin_port = htons(port);
1032- addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
1033-
1034- if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
1035- fd_close(sock);
1036- return -1;
1037- }
1038-
1039- return sock;
1040-}
1041-
1042-gint fd_open_inet(gushort port)
1043-{
1044- SockDesc sock;
1045- struct sockaddr_in addr;
1046- gint val;
1047-
1048- sock = socket(AF_INET, SOCK_STREAM, 0);
1049- if (!SOCKET_IS_VALID(sock)) {
1050-#ifdef G_OS_WIN32
1051- g_warning("fd_open_inet(): socket() failed: %d\n",
1052- WSAGetLastError());
1053-#else
1054- perror("fd_open_inet(): socket");
1055-#endif
1056- return -1;
1057- }
1058-
1059- val = 1;
1060- if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val)) < 0) {
1061- perror("setsockopt");
1062- fd_close(sock);
1063- return -1;
1064- }
1065-
1066- memset(&addr, 0, sizeof(addr));
1067- addr.sin_family = AF_INET;
1068- addr.sin_port = htons(port);
1069- addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
1070-
1071- if (bind(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
1072- perror("bind");
1073- fd_close(sock);
1074- return -1;
1075- }
1076-
1077- if (listen(sock, 1) < 0) {
1078- perror("listen");
1079- fd_close(sock);
1080- return -1;
1081- }
1082-
1083- return sock;
1084-}
1085-
1086-gint fd_connect_unix(const gchar *path)
1087-{
1088-#ifdef G_OS_UNIX
1089- gint sock;
1090- struct sockaddr_un addr;
1091-
1092- sock = socket(PF_UNIX, SOCK_STREAM, 0);
1093- if (sock < 0) {
1094- perror("fd_connect_unix(): socket");
1095- return -1;
1096- }
1097-
1098- memset(&addr, 0, sizeof(addr));
1099- addr.sun_family = AF_UNIX;
1100- strncpy(addr.sun_path, path, sizeof(addr.sun_path) - 1);
1101-
1102- if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
1103- fd_close(sock);
1104- return -1;
1105- }
1106-
1107- return sock;
1108-#else
1109- return -1;
1110-#endif
1111-}
1112-
1113-gint fd_open_unix(const gchar *path)
1114-{
1115-#ifdef G_OS_UNIX
1116- gint sock;
1117- struct sockaddr_un addr;
1118- gint val;
1119-
1120- sock = socket(PF_UNIX, SOCK_STREAM, 0);
1121-
1122- if (sock < 0) {
1123- perror("sock_open_unix(): socket");
1124- return -1;
1125- }
1126-
1127- val = 1;
1128- if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val)) < 0) {
1129- perror("setsockopt");
1130- fd_close(sock);
1131- return -1;
1132- }
1133-
1134- memset(&addr, 0, sizeof(addr));
1135- addr.sun_family = AF_UNIX;
1136- strncpy(addr.sun_path, path, sizeof(addr.sun_path) - 1);
1137-
1138- if (bind(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
1139- perror("bind");
1140- fd_close(sock);
1141- return -1;
1142- }
1143-
1144- if (listen(sock, 1) < 0) {
1145- perror("listen");
1146- fd_close(sock);
1147- return -1;
1148- }
1149-
1150- return sock;
1151-#else
1152- return -1;
1153-#endif
1154-}
1155-
1156-gint fd_accept(gint sock)
1157-{
1158- struct sockaddr_in caddr;
1159- guint caddr_len;
1160-
1161- caddr_len = sizeof(caddr);
1162- return accept(sock, (struct sockaddr *)&caddr, &caddr_len);
1163-}
1164-
1165-#ifdef G_OS_WIN32
1166-static SockInfo *sock_find_from_fd(gint fd)
1167-{
1168- GList *cur;
1169-
1170- for (cur = sock_list; cur != NULL; cur = cur->next) {
1171- if (((SockInfo *)cur->data)->sock == fd)
1172- return (SockInfo *)cur->data;
1173- }
1174-
1175- return NULL;
1176-}
1177-#endif
1178-
1179-static gint set_nonblocking_mode(gint fd, gboolean nonblock)
1180-{
1181-#ifdef G_OS_WIN32
1182- gulong val = nonblock ? 1 : 0;
1183- SockInfo *sock;
1184-
1185- if (!nonblock)
1186- WSAEventSelect(fd, NULL, 0);
1187- if (ioctlsocket(fd, FIONBIO, &val) == SOCKET_ERROR) {
1188- g_warning("set_nonblocking_mode(): ioctlsocket() failed: %d\n",
1189- WSAGetLastError());
1190- return -1;
1191- }
1192-
1193- sock = sock_find_from_fd(fd);
1194- if (sock)
1195- sock->nonblock = nonblock;
1196- g_debug ("set nonblocking mode to %d\n", nonblock);
1197-
1198- return 0;
1199-#else
1200- gint flags;
1201-
1202- flags = fcntl(fd, F_GETFL, 0);
1203- if (flags < 0) {
1204- perror("fcntl");
1205- return -1;
1206- }
1207-
1208- if (nonblock)
1209- flags |= O_NONBLOCK;
1210- else
1211- flags &= ~O_NONBLOCK;
1212-
1213- return fcntl(fd, F_SETFL, flags);
1214-#endif
1215-}
1216-
1217-gint sock_set_nonblocking_mode(SockInfo *sock, gboolean nonblock)
1218-{
1219- gint ret;
1220-
1221- g_return_val_if_fail(sock != NULL, -1);
1222-
1223- ret = set_nonblocking_mode(sock->sock, nonblock);
1224- if (ret == 0)
1225- sock->nonblock = nonblock;
1226-
1227- return ret;
1228-}
1229-
1230-static gboolean is_nonblocking_mode(gint fd)
1231-{
1232-#ifdef G_OS_WIN32
1233- SockInfo *sock;
1234-
1235- sock = sock_find_from_fd(fd);
1236- if (sock)
1237- return sock->nonblock;
1238-
1239- return FALSE;
1240-#else
1241- gint flags;
1242-
1243- flags = fcntl(fd, F_GETFL, 0);
1244- if (flags < 0) {
1245- perror("fcntl");
1246- return FALSE;
1247- }
1248-
1249- return ((flags & O_NONBLOCK) != 0);
1250-#endif
1251-}
1252-
1253-gboolean sock_is_nonblocking_mode(SockInfo *sock)
1254-{
1255- g_return_val_if_fail(sock != NULL, FALSE);
1256-
1257-#ifdef G_OS_WIN32
1258- return sock->nonblock;
1259-#else
1260- return is_nonblocking_mode(sock->sock);
1261-#endif
1262-}
1263-
1264-gboolean sock_has_read_data(SockInfo *sock)
1265-{
1266-#ifdef G_OS_WIN32
1267- gulong val;
1268-
1269- if (ioctlsocket(sock->sock, FIONREAD, &val) < 0) {
1270- g_warning("sock_has_read_data(): ioctlsocket() failed: %d\n",
1271- WSAGetLastError());
1272- return TRUE;
1273- }
1274-
1275- if (val == 0)
1276- return FALSE;
1277- else
1278- return TRUE;
1279-#else
1280- return TRUE;
1281-#endif
1282-}
1283-
1284-
1285-static gboolean sock_prepare(GSource *source, gint *timeout)
1286-{
1287- *timeout = 1;
1288- return FALSE;
1289-}
1290-
1291-static gboolean sock_check(GSource *source)
1292-{
1293- SockInfo *sock = ((SockSource *)source)->sock;
1294- struct timeval timeout = {0, 0};
1295- fd_set fds;
1296- GIOCondition condition = sock->condition;
1297-
1298- FD_ZERO(&fds);
1299- FD_SET(sock->sock, &fds);
1300-
1301- select(sock->sock + 1,
1302- (condition & G_IO_IN) ? &fds : NULL,
1303- (condition & G_IO_OUT) ? &fds : NULL,
1304- NULL, &timeout);
1305-
1306- return FD_ISSET(sock->sock, &fds) != 0;
1307-}
1308-
1309-static gboolean sock_dispatch(GSource *source, GSourceFunc callback,
1310- gpointer user_data)
1311-{
1312- SockInfo *sock = ((SockSource *)source)->sock;
1313-
1314- return sock->callback(sock, sock->condition, sock->data);
1315-}
1316-
1317-static gboolean sock_watch_cb(GIOChannel *source, GIOCondition condition,
1318- gpointer data)
1319-{
1320- SockInfo *sock = (SockInfo *)data;
1321-
1322- if ((condition & sock->condition) == 0)
1323- return TRUE;
1324-
1325- return sock->callback(sock, sock->condition, sock->data);
1326-}
1327-
1328-guint sock_add_watch(SockInfo *sock, GIOCondition condition, SockFunc func,
1329- gpointer data)
1330-{
1331- sock->callback = func;
1332- sock->condition = condition;
1333- sock->data = data;
1334- return g_io_add_watch(sock->sock_ch, condition, sock_watch_cb, sock);
1335-}
1336-
1337-static gint fd_check_io(gint fd, GIOCondition cond)
1338-{
1339- struct timeval timeout;
1340- fd_set fds;
1341-
1342- if (is_nonblocking_mode(fd))
1343- return 0;
1344-
1345- timeout.tv_sec = io_timeout;
1346- timeout.tv_usec = 0;
1347-
1348- FD_ZERO(&fds);
1349- FD_SET(fd, &fds);
1350-
1351- if (cond == G_IO_IN) {
1352- select(fd + 1, &fds, NULL, NULL,
1353- io_timeout > 0 ? &timeout : NULL);
1354- } else {
1355- select(fd + 1, NULL, &fds, NULL,
1356- io_timeout > 0 ? &timeout : NULL);
1357- }
1358-
1359- if (FD_ISSET(fd, &fds)) {
1360- return 0;
1361- } else {
1362- g_warning("Socket IO timeout\n");
1363- return -1;
1364- }
1365-}
1366-
1367-#ifdef G_OS_UNIX
1368-static sigjmp_buf jmpenv;
1369-
1370-static void G_GNUC_NORETURN timeout_handler(gint sig)
1371-{
1372- siglongjmp(jmpenv, 1);
1373-}
1374-#endif
1375-
1376-static gint sock_connect_with_timeout(gint sock,
1377- const struct sockaddr *serv_addr,
1378- gint addrlen,
1379- guint timeout_secs)
1380-{
1381- gint ret;
1382-#ifdef G_OS_UNIX
1383- void (*prev_handler)(gint);
1384-
1385- alarm(0);
1386- prev_handler = signal(SIGALRM, timeout_handler);
1387- if (sigsetjmp(jmpenv, 1)) {
1388- alarm(0);
1389- signal(SIGALRM, prev_handler);
1390- errno = ETIMEDOUT;
1391- return -1;
1392- }
1393- alarm(timeout_secs);
1394-#endif
1395-
1396- ret = connect(sock, serv_addr, addrlen);
1397-
1398-#ifdef G_OS_UNIX
1399- alarm(0);
1400- signal(SIGALRM, prev_handler);
1401-#endif
1402-
1403- return ret;
1404-}
1405-
1406-struct hostent *my_gethostbyname(const gchar *hostname)
1407-{
1408- struct hostent *hp;
1409-#ifdef G_OS_UNIX
1410- void (*prev_handler)(gint);
1411-
1412- alarm(0);
1413- prev_handler = signal(SIGALRM, timeout_handler);
1414- if (sigsetjmp(jmpenv, 1)) {
1415- alarm(0);
1416- signal(SIGALRM, prev_handler);
1417- fprintf(stderr, "%s: host lookup timed out.\n", hostname);
1418- errno = 0;
1419- return NULL;
1420- }
1421- alarm(io_timeout);
1422-#endif
1423-
1424- if ((hp = gethostbyname(hostname)) == NULL) {
1425-#ifdef G_OS_UNIX
1426- alarm(0);
1427- signal(SIGALRM, prev_handler);
1428-#endif
1429- fprintf(stderr, "%s: unknown host.\n", hostname);
1430- errno = 0;
1431- return NULL;
1432- }
1433-
1434-#ifdef G_OS_UNIX
1435- alarm(0);
1436- signal(SIGALRM, prev_handler);
1437-#endif
1438-
1439- return hp;
1440-}
1441-
1442-#ifndef INET6
1443-static gint my_inet_aton(const gchar *hostname, struct in_addr *inp)
1444-{
1445-#ifdef HAVE_INET_ATON
1446- return inet_aton(hostname, inp);
1447-#else
1448-#ifdef HAVE_INET_ADDR
1449- guint32 inaddr;
1450-
1451- inaddr = inet_addr(hostname);
1452- if (inaddr != -1) {
1453- memcpy(inp, &inaddr, sizeof(inaddr));
1454- return 1;
1455- } else
1456- return 0;
1457-#else
1458- return 0;
1459-#endif
1460-#endif /* HAVE_INET_ATON */
1461-}
1462-
1463-static gint sock_connect_by_hostname(gint sock, const gchar *hostname,
1464- gushort port)
1465-{
1466- struct hostent *hp;
1467- struct sockaddr_in ad;
1468-
1469- memset(&ad, 0, sizeof(ad));
1470- ad.sin_family = AF_INET;
1471- ad.sin_port = htons(port);
1472-
1473- if (!my_inet_aton(hostname, &ad.sin_addr)) {
1474- if ((hp = my_gethostbyname(hostname)) == NULL) {
1475- fprintf(stderr, "%s: unknown host.\n", hostname);
1476- errno = 0;
1477- return -1;
1478- }
1479-
1480- if (hp->h_length != 4 && hp->h_length != 8) {
1481- fprintf(stderr, "illegal address length received for host %s\n", hostname);
1482- errno = 0;
1483- return -1;
1484- }
1485-
1486- memcpy(&ad.sin_addr, hp->h_addr, hp->h_length);
1487- }
1488-
1489- return sock_connect_with_timeout(sock, (struct sockaddr *)&ad,
1490- sizeof(ad), io_timeout);
1491-}
1492-
1493-#else /* INET6 */
1494-
1495-#ifdef G_OS_WIN32
1496-/* MinGW defines gai_strerror() in ws2tcpip.h, but it is not implemented. */
1497-#undef gai_strerror
1498-const gchar *gai_strerror(gint errcode)
1499-{
1500- static gchar str[32];
1501-
1502- g_snprintf(str, sizeof(str), "gai errcode: (%d)", errcode);
1503- return str;
1504-}
1505-#endif
1506-
1507-static SockDesc sock_connect_by_getaddrinfo(const gchar *hostname, gushort port)
1508-{
1509- SockDesc sock = INVALID_SOCKET;
1510- gint gai_error;
1511- struct addrinfo hints, *res, *ai;
1512- gchar port_str[6];
1513-
1514- memset(&hints, 0, sizeof(hints));
1515- /* hints.ai_flags = AI_CANONNAME; */
1516- hints.ai_family = AF_UNSPEC;
1517- hints.ai_socktype = SOCK_STREAM;
1518- hints.ai_protocol = IPPROTO_TCP;
1519-
1520- /* convert port from integer to string. */
1521- g_snprintf(port_str, sizeof(port_str), "%d", port);
1522-
1523- if ((gai_error = getaddrinfo(hostname, port_str, &hints, &res)) != 0) {
1524- fprintf(stderr, "getaddrinfo for %s:%s failed: %s\n",
1525- hostname, port_str, gai_strerror(gai_error));
1526- return INVALID_SOCKET;
1527- }
1528-
1529- for (ai = res; ai != NULL; ai = ai->ai_next) {
1530- sock = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
1531- if (!SOCKET_IS_VALID(sock))
1532- continue;
1533-
1534- if (sock_connect_with_timeout
1535- (sock, ai->ai_addr, ai->ai_addrlen, io_timeout) == 0)
1536- break;
1537-
1538- fd_close(sock);
1539- }
1540-
1541- if (res != NULL)
1542- freeaddrinfo(res);
1543-
1544- if (ai == NULL)
1545- return INVALID_SOCKET;
1546-
1547- return sock;
1548-}
1549-#endif /* !INET6 */
1550-
1551-SockInfo *sock_connect(const gchar *hostname, gushort port)
1552-{
1553- SockDesc sock;
1554- SockInfo *sockinfo;
1555-
1556-#ifdef INET6
1557- sock = sock_connect_by_getaddrinfo(hostname, port);
1558- if (!SOCKET_IS_VALID(sock))
1559- return NULL;
1560-#else
1561- sock = socket(AF_INET, SOCK_STREAM, 0);
1562- if (!SOCKET_IS_VALID(sock)) {
1563-#ifdef G_OS_WIN32
1564- g_warning("socket() failed: %d\n", WSAGetLastError());
1565-#else
1566- perror("socket");
1567-#endif /* G_OS_WIN32 */
1568- return NULL;
1569- }
1570-
1571- if (sock_connect_by_hostname(sock, hostname, port) < 0) {
1572- if (errno != 0) perror("connect");
1573- fd_close(sock);
1574- return NULL;
1575- }
1576-#endif /* INET6 */
1577-
1578- sockinfo = g_new0(SockInfo, 1);
1579- sockinfo->sock = sock;
1580- sockinfo->sock_ch = g_io_channel_unix_new(sock);
1581- sockinfo->hostname = g_strdup(hostname);
1582- sockinfo->port = port;
1583- sockinfo->state = CONN_ESTABLISHED;
1584- sockinfo->nonblock = FALSE;
1585-
1586- sock_list = g_list_prepend(sock_list, sockinfo);
1587-
1588- g_usleep(100000);
1589-
1590- return sockinfo;
1591-}
1592-
1593-#ifdef G_OS_UNIX
1594-static void sock_address_list_free(GList *addr_list)
1595-{
1596- GList *cur;
1597-
1598- for (cur = addr_list; cur != NULL; cur = cur->next) {
1599- SockAddrData *addr_data = (SockAddrData *)cur->data;
1600- g_free(addr_data->addr);
1601- g_free(addr_data);
1602- }
1603-
1604- g_list_free(addr_list);
1605-}
1606-
1607-/* asynchronous TCP connection */
1608-
1609-static gboolean sock_connect_async_cb(GIOChannel *source,
1610- GIOCondition condition, gpointer data)
1611-{
1612- SockConnectData *conn_data = (SockConnectData *)data;
1613- gint fd;
1614- gint val;
1615- guint len;
1616- SockInfo *sockinfo;
1617-
1618- fd = g_io_channel_unix_get_fd(source);
1619-
1620- conn_data->io_tag = 0;
1621- conn_data->channel = NULL;
1622- g_io_channel_unref(source);
1623-
1624- if (condition & (G_IO_ERR | G_IO_HUP)) {
1625- g_debug ("sock_connect_async_cb: condition = %d\n",
1626- condition);
1627- fd_close(fd);
1628- sock_connect_address_list_async(conn_data);
1629- return FALSE;
1630- }
1631-
1632- len = sizeof(val);
1633- if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &val, &len) < 0) {
1634- perror("getsockopt");
1635- fd_close(fd);
1636- sock_connect_address_list_async(conn_data);
1637- return FALSE;
1638- }
1639-
1640- if (val != 0) {
1641- fd_close(fd);
1642- sock_connect_address_list_async(conn_data);
1643- return FALSE;
1644- }
1645-
1646- sockinfo = g_new0(SockInfo, 1);
1647- sockinfo->sock = fd;
1648- sockinfo->sock_ch = g_io_channel_unix_new(fd);
1649- sockinfo->hostname = g_strdup(conn_data->hostname);
1650- sockinfo->port = conn_data->port;
1651- sockinfo->state = CONN_ESTABLISHED;
1652- sockinfo->nonblock = TRUE;
1653-
1654- sock_list = g_list_prepend(sock_list, sockinfo);
1655-
1656- conn_data->func(sockinfo, conn_data->data);
1657-
1658- sock_connect_async_cancel(conn_data->id);
1659-
1660- return FALSE;
1661-}
1662-
1663-static gint sock_connect_async_get_address_info_cb(GList *addr_list,
1664- gpointer data)
1665-{
1666- SockConnectData *conn_data = (SockConnectData *)data;
1667-
1668- conn_data->addr_list = addr_list;
1669- conn_data->cur_addr = addr_list;
1670- conn_data->lookup_data = NULL;
1671-
1672- return sock_connect_address_list_async(conn_data);
1673-}
1674-
1675-gint sock_connect_async(const gchar *hostname, gushort port,
1676- SockConnectFunc func, gpointer data)
1677-{
1678- static gint id = 1;
1679- SockConnectData *conn_data;
1680-
1681- conn_data = g_new0(SockConnectData, 1);
1682- conn_data->id = id++;
1683- conn_data->hostname = g_strdup(hostname);
1684- conn_data->port = port;
1685- conn_data->addr_list = NULL;
1686- conn_data->cur_addr = NULL;
1687- conn_data->io_tag = 0;
1688- conn_data->func = func;
1689- conn_data->data = data;
1690-
1691- conn_data->lookup_data = sock_get_address_info_async
1692- (hostname, port, sock_connect_async_get_address_info_cb,
1693- conn_data);
1694-
1695- if (conn_data->lookup_data == NULL) {
1696- g_free(conn_data->hostname);
1697- g_free(conn_data);
1698- return -1;
1699- }
1700-
1701- sock_connect_data_list = g_list_append(sock_connect_data_list,
1702- conn_data);
1703-
1704- return conn_data->id;
1705-}
1706-
1707-gint sock_connect_async_cancel(gint id)
1708-{
1709- SockConnectData *conn_data = NULL;
1710- GList *cur;
1711-
1712- for (cur = sock_connect_data_list; cur != NULL; cur = cur->next) {
1713- if (((SockConnectData *)cur->data)->id == id) {
1714- conn_data = (SockConnectData *)cur->data;
1715- break;
1716- }
1717- }
1718-
1719- if (conn_data) {
1720- sock_connect_data_list = g_list_remove(sock_connect_data_list,
1721- conn_data);
1722-
1723- if (conn_data->lookup_data)
1724- sock_get_address_info_async_cancel
1725- (conn_data->lookup_data);
1726-
1727- if (conn_data->io_tag > 0)
1728- g_source_remove(conn_data->io_tag);
1729- if (conn_data->channel) {
1730- g_io_channel_shutdown(conn_data->channel, FALSE, NULL);
1731- g_io_channel_unref(conn_data->channel);
1732- }
1733-
1734- sock_address_list_free(conn_data->addr_list);
1735- g_free(conn_data->hostname);
1736- g_free(conn_data);
1737- } else {
1738- g_warning("sock_connect_async_cancel: id %d not found.\n", id);
1739- return -1;
1740- }
1741-
1742- return 0;
1743-}
1744-
1745-static gint sock_connect_address_list_async(SockConnectData *conn_data)
1746-{
1747- SockAddrData *addr_data;
1748- gint sock = -1;
1749-
1750- for (; conn_data->cur_addr != NULL;
1751- conn_data->cur_addr = conn_data->cur_addr->next) {
1752- addr_data = (SockAddrData *)conn_data->cur_addr->data;
1753-
1754- if ((sock = socket(addr_data->family, addr_data->socktype,
1755- addr_data->protocol)) < 0) {
1756- perror("socket");
1757- continue;
1758- }
1759-
1760- set_nonblocking_mode(sock, TRUE);
1761-
1762- if (connect(sock, addr_data->addr, addr_data->addr_len) < 0) {
1763- if (EINPROGRESS == errno) {
1764- break;
1765- } else {
1766- perror("connect");
1767- fd_close(sock);
1768- }
1769- } else
1770- break;
1771- }
1772-
1773- if (conn_data->cur_addr == NULL) {
1774- g_warning("sock_connect_address_list_async: "
1775- "connection to %s:%d failed\n",
1776- conn_data->hostname, conn_data->port);
1777- conn_data->func(NULL, conn_data->data);
1778- sock_connect_async_cancel(conn_data->id);
1779- return -1;
1780- }
1781-
1782- g_debug ("sock_connect_address_list_async: waiting for connect\n");
1783-
1784- conn_data->cur_addr = conn_data->cur_addr->next;
1785-
1786- conn_data->channel = g_io_channel_unix_new(sock);
1787- conn_data->io_tag = g_io_add_watch(conn_data->channel,
1788- G_IO_OUT | G_IO_ERR | G_IO_HUP,
1789- sock_connect_async_cb, conn_data);
1790-
1791- return 0;
1792-}
1793-
1794-static gint sock_kill_process(pid_t pid)
1795-{
1796- pid_t ret = (pid_t)-1;
1797-
1798- kill(pid, SIGKILL);
1799-
1800- while (ret == (pid_t)-1) {
1801- if ((ret = waitpid(pid, NULL, 0)) != pid) {
1802- perror("sock_kill_process(): waitpid");
1803- if (ret == (pid_t)-1 && errno != EINTR)
1804- break;
1805- }
1806- }
1807-
1808- return (gint)pid;
1809-}
1810-
1811-/* asynchronous DNS lookup */
1812-
1813-static gboolean sock_get_address_info_async_cb(GIOChannel *source,
1814- GIOCondition condition,
1815- gpointer data)
1816-{
1817- SockLookupData *lookup_data = (SockLookupData *)data;
1818- GList *addr_list = NULL;
1819- SockAddrData *addr_data;
1820- gsize bytes_read;
1821- gint ai_member[4];
1822- struct sockaddr *addr;
1823-
1824- for (;;) {
1825- if (g_io_channel_read(source, (gchar *)ai_member,
1826- sizeof(ai_member), &bytes_read)
1827- != G_IO_ERROR_NONE) {
1828- g_warning("sock_get_address_info_async_cb: "
1829- "address length read error\n");
1830- break;
1831- }
1832-
1833- if (bytes_read == 0 || bytes_read != sizeof(ai_member))
1834- break;
1835-
1836- if (ai_member[0] == AF_UNSPEC) {
1837- g_warning("DNS lookup failed\n");
1838- break;
1839- }
1840-
1841- addr = g_malloc(ai_member[3]);
1842- if (g_io_channel_read(source, (gchar *)addr, ai_member[3],
1843- &bytes_read)
1844- != G_IO_ERROR_NONE) {
1845- g_warning("sock_get_address_info_async_cb: "
1846- "address data read error\n");
1847- g_free(addr);
1848- break;
1849- }
1850-
1851- if (bytes_read != (gsize)ai_member[3]) {
1852- g_warning("sock_get_address_info_async_cb: "
1853- "incomplete address data\n");
1854- g_free(addr);
1855- break;
1856- }
1857-
1858- addr_data = g_new0(SockAddrData, 1);
1859- addr_data->family = ai_member[0];
1860- addr_data->socktype = ai_member[1];
1861- addr_data->protocol = ai_member[2];
1862- addr_data->addr_len = ai_member[3];
1863- addr_data->addr = addr;
1864-
1865- addr_list = g_list_append(addr_list, addr_data);
1866- }
1867-
1868- g_io_channel_shutdown(source, FALSE, NULL);
1869- g_io_channel_unref(source);
1870-
1871- sock_kill_process(lookup_data->child_pid);
1872-
1873- lookup_data->func(addr_list, lookup_data->data);
1874-
1875- g_free(lookup_data->hostname);
1876- g_free(lookup_data);
1877-
1878- return FALSE;
1879-}
1880-
1881-static SockLookupData *sock_get_address_info_async(const gchar *hostname,
1882- gushort port,
1883- SockAddrFunc func,
1884- gpointer data)
1885-{
1886- SockLookupData *lookup_data = NULL;
1887- gint pipe_fds[2];
1888- pid_t pid;
1889-
1890- if (pipe(pipe_fds) < 0) {
1891- perror("pipe");
1892- func(NULL, data);
1893- return NULL;
1894- }
1895-
1896- if ((pid = fork()) < 0) {
1897- perror("fork");
1898- func(NULL, data);
1899- return NULL;
1900- }
1901-
1902- /* child process */
1903- if (pid == 0) {
1904-#ifdef INET6
1905- gint gai_err;
1906- struct addrinfo hints, *res, *ai;
1907- gchar port_str[6];
1908-#else /* !INET6 */
1909- struct hostent *hp;
1910- gchar **addr_list_p;
1911- struct sockaddr_in ad;
1912-#endif /* INET6 */
1913- gint ai_member[4] = {AF_UNSPEC, 0, 0, 0};
1914-
1915- close(pipe_fds[0]);
1916-
1917-#ifdef INET6
1918- memset(&hints, 0, sizeof(hints));
1919- /* hints.ai_flags = AI_CANONNAME; */
1920- hints.ai_family = AF_UNSPEC;
1921- hints.ai_socktype = SOCK_STREAM;
1922- hints.ai_protocol = IPPROTO_TCP;
1923-
1924- g_snprintf(port_str, sizeof(port_str), "%d", port);
1925-
1926- gai_err = getaddrinfo(hostname, port_str, &hints, &res);
1927- if (gai_err != 0) {
1928- g_warning("getaddrinfo for %s:%s failed: %s\n",
1929- hostname, port_str, gai_strerror(gai_err));
1930- fd_write_all(pipe_fds[1], (gchar *)ai_member,
1931- sizeof(ai_member));
1932- close(pipe_fds[1]);
1933- _exit(1);
1934- }
1935-
1936- for (ai = res; ai != NULL; ai = ai->ai_next) {
1937- ai_member[0] = ai->ai_family;
1938- ai_member[1] = ai->ai_socktype;
1939- ai_member[2] = ai->ai_protocol;
1940- ai_member[3] = ai->ai_addrlen;
1941-
1942- fd_write_all(pipe_fds[1], (gchar *)ai_member,
1943- sizeof(ai_member));
1944- fd_write_all(pipe_fds[1], (gchar *)ai->ai_addr,
1945- ai->ai_addrlen);
1946- }
1947-
1948- if (res != NULL)
1949- freeaddrinfo(res);
1950-#else /* !INET6 */
1951- hp = my_gethostbyname(hostname);
1952- if (hp == NULL || hp->h_addrtype != AF_INET) {
1953- fd_write_all(pipe_fds[1], (gchar *)ai_member,
1954- sizeof(ai_member));
1955- close(pipe_fds[1]);
1956- _exit(1);
1957- }
1958-
1959- ai_member[0] = AF_INET;
1960- ai_member[1] = SOCK_STREAM;
1961- ai_member[2] = IPPROTO_TCP;
1962- ai_member[3] = sizeof(ad);
1963-
1964- memset(&ad, 0, sizeof(ad));
1965- ad.sin_family = AF_INET;
1966- ad.sin_port = htons(port);
1967-
1968- for (addr_list_p = hp->h_addr_list; *addr_list_p != NULL;
1969- addr_list_p++) {
1970- memcpy(&ad.sin_addr, *addr_list_p, hp->h_length);
1971- fd_write_all(pipe_fds[1], (gchar *)ai_member,
1972- sizeof(ai_member));
1973- fd_write_all(pipe_fds[1], (gchar *)&ad, sizeof(ad));
1974- }
1975-#endif /* INET6 */
1976-
1977- close(pipe_fds[1]);
1978-
1979- _exit(0);
1980- } else {
1981- close(pipe_fds[1]);
1982-
1983- lookup_data = g_new0(SockLookupData, 1);
1984- lookup_data->hostname = g_strdup(hostname);
1985- lookup_data->child_pid = pid;
1986- lookup_data->func = func;
1987- lookup_data->data = data;
1988-
1989- lookup_data->channel = g_io_channel_unix_new(pipe_fds[0]);
1990- lookup_data->io_tag = g_io_add_watch
1991- (lookup_data->channel, G_IO_IN,
1992- sock_get_address_info_async_cb, lookup_data);
1993- }
1994-
1995- return lookup_data;
1996-}
1997-
1998-static gint sock_get_address_info_async_cancel(SockLookupData *lookup_data)
1999-{
2000- if (lookup_data->io_tag > 0)
2001- g_source_remove(lookup_data->io_tag);
2002- if (lookup_data->channel) {
2003- g_io_channel_shutdown(lookup_data->channel, FALSE, NULL);
2004- g_io_channel_unref(lookup_data->channel);
2005- }
2006-
2007- if (lookup_data->child_pid > 0)
2008- sock_kill_process(lookup_data->child_pid);
2009-
2010- g_free(lookup_data->hostname);
2011- g_free(lookup_data);
2012-
2013- return 0;
2014-}
2015-#endif /* G_OS_UNIX */
2016-
2017-
2018-gint sock_printf(SockInfo *sock, const gchar *format, ...)
2019-{
2020- va_list args;
2021- gchar buf[BUFFSIZE];
2022-
2023- va_start(args, format);
2024- g_vsnprintf(buf, sizeof(buf), format, args);
2025- va_end(args);
2026-
2027- return sock_write_all(sock, buf, strlen(buf));
2028-}
2029-
2030-#ifdef G_OS_WIN32
2031-static void sock_set_errno_from_last_error(gint error)
2032-{
2033- switch (error) {
2034- case WSAEWOULDBLOCK:
2035- errno = EAGAIN;
2036- break;
2037- default:
2038- g_debug ("last error = %d\n", error);
2039- errno = 0;
2040- break;
2041- }
2042-}
2043-#endif
2044-
2045-gint sock_read(SockInfo *sock, gchar *buf, gint len)
2046-{
2047- g_return_val_if_fail(sock != NULL, -1);
2048-
2049- return fd_read(sock->sock, buf, len);
2050-}
2051-
2052-gint fd_read(gint fd, gchar *buf, gint len)
2053-{
2054-#ifdef G_OS_WIN32
2055- return fd_recv(fd, buf, len, 0);
2056-#else
2057- if (fd_check_io(fd, G_IO_IN) < 0)
2058- return -1;
2059-
2060- return read(fd, buf, len);
2061-#endif
2062-}
2063-
2064-gint sock_write(SockInfo *sock, const gchar *buf, gint len)
2065-{
2066- g_return_val_if_fail(sock != NULL, -1);
2067-
2068- return fd_write(sock->sock, buf, len);
2069-}
2070-
2071-gint fd_write(gint fd, const gchar *buf, gint len)
2072-{
2073-#ifdef G_OS_WIN32
2074- gint ret;
2075-#endif
2076- if (fd_check_io(fd, G_IO_OUT) < 0)
2077- return -1;
2078-
2079-#ifdef G_OS_WIN32
2080- ret = send(fd, buf, len, 0);
2081- if (ret == SOCKET_ERROR) {
2082- gint err;
2083- err = WSAGetLastError();
2084- sock_set_errno_from_last_error(err);
2085- if (err != WSAEWOULDBLOCK)
2086- g_warning("fd_write() failed with %d (errno = %d)\n",
2087- err, errno);
2088- }
2089- return ret;
2090-#else
2091- return write(fd, buf, len);
2092-#endif
2093-}
2094-
2095-gint sock_write_all(SockInfo *sock, const gchar *buf, gint len)
2096-{
2097- g_return_val_if_fail(sock != NULL, -1);
2098-
2099- return fd_write_all(sock->sock, buf, len);
2100-}
2101-
2102-gint fd_write_all(gint fd, const gchar *buf, gint len)
2103-{
2104- gint n, wrlen = 0;
2105-
2106- while (len) {
2107- n = fd_write(fd, buf, len);
2108- if (n <= 0)
2109- return -1;
2110- len -= n;
2111- wrlen += n;
2112- buf += n;
2113- }
2114-
2115- return wrlen;
2116-}
2117-
2118-gint fd_recv(gint fd, gchar *buf, gint len, gint flags)
2119-{
2120-#ifdef G_OS_WIN32
2121- gint ret;
2122-#endif
2123- if (fd_check_io(fd, G_IO_IN) < 0)
2124- return -1;
2125-
2126-#ifdef G_OS_WIN32
2127- ret = recv(fd, buf, len, flags);
2128- if (ret == SOCKET_ERROR) {
2129- gint err;
2130- err = WSAGetLastError();
2131- sock_set_errno_from_last_error(err);
2132- if (err != WSAEWOULDBLOCK)
2133- g_warning("fd_recv(): failed with %d (errno = %d)\n",
2134- err, errno);
2135- }
2136- return ret;
2137-#else
2138- return recv(fd, buf, len, flags);
2139-#endif
2140-}
2141-
2142-gint fd_gets(gint fd, gchar *buf, gint len)
2143-{
2144- gchar *newline, *bp = buf;
2145- gint n;
2146-
2147- if (--len < 1)
2148- return -1;
2149- do {
2150- if ((n = fd_recv(fd, bp, len, MSG_PEEK)) <= 0)
2151- return -1;
2152- if ((newline = memchr(bp, '\n', n)) != NULL)
2153- n = newline - bp + 1;
2154- if ((n = fd_read(fd, bp, n)) < 0)
2155- return -1;
2156- bp += n;
2157- len -= n;
2158- } while (!newline && len);
2159-
2160- *bp = '\0';
2161- return bp - buf;
2162-}
2163-
2164-gint sock_gets(SockInfo *sock, gchar *buf, gint len)
2165-{
2166- g_return_val_if_fail(sock != NULL, -1);
2167-
2168- return fd_gets(sock->sock, buf, len);
2169-}
2170-
2171-gint fd_getline(gint fd, gchar **line)
2172-{
2173- gchar buf[BUFFSIZE];
2174- gchar *str = NULL;
2175- gint len;
2176- gulong size = 0;
2177- gulong cur_offset = 0;
2178-
2179- while ((len = fd_gets(fd, buf, sizeof(buf))) > 0) {
2180- size += len;
2181- str = g_realloc(str, size + 1);
2182- memcpy(str + cur_offset, buf, len + 1);
2183- cur_offset += len;
2184- if (buf[len - 1] == '\n')
2185- break;
2186- }
2187-
2188- *line = str;
2189-
2190- if (!str)
2191- return -1;
2192- else
2193- return (gint)size;
2194-}
2195-
2196-gint sock_getline(SockInfo *sock, gchar **line)
2197-{
2198- g_return_val_if_fail(sock != NULL, -1);
2199- g_return_val_if_fail(line != NULL, -1);
2200-
2201- return fd_getline(sock->sock, line);
2202-}
2203-
2204-gint sock_puts(SockInfo *sock, const gchar *buf)
2205-{
2206- gint ret;
2207-
2208- if ((ret = sock_write_all(sock, buf, strlen(buf))) < 0)
2209- return ret;
2210- return sock_write_all(sock, "\r\n", 2);
2211-}
2212-
2213-/* peek at the socket data without actually reading it */
2214-gint sock_peek(SockInfo *sock, gchar *buf, gint len)
2215-{
2216- g_return_val_if_fail(sock != NULL, -1);
2217-
2218- return fd_recv(sock->sock, buf, len, MSG_PEEK);
2219-}
2220-
2221-gint sock_close(SockInfo *sock)
2222-{
2223- GList *cur;
2224-
2225- if (!sock)
2226- return 0;
2227-
2228- if (sock->sock_ch) {
2229- g_io_channel_shutdown(sock->sock_ch, FALSE, NULL);
2230- g_io_channel_unref(sock->sock_ch);
2231- }
2232-
2233- for (cur = sock_list; cur != NULL; cur = cur->next) {
2234- if ((SockInfo *)cur->data == sock) {
2235- sock_list = g_list_remove(sock_list, sock);
2236- break;
2237- }
2238- }
2239-
2240- g_free(sock->hostname);
2241- g_free(sock);
2242-
2243- return 0;
2244-}
2245-
2246-gint fd_close(gint fd)
2247-{
2248-#ifdef G_OS_WIN32
2249- return closesocket(fd);
2250-#else
2251- return close(fd);
2252-#endif
2253-}
2254-
2255-#endif
2256
2257=== removed file 'midori/socket.h'
2258--- midori/socket.h 2012-02-19 19:21:37 +0000
2259+++ midori/socket.h 1970-01-01 00:00:00 +0000
2260@@ -1,105 +0,0 @@
2261-/*
2262- Copyright 1999-2008 Hiroyuki Yamamoto
2263-
2264- This library is free software; you can redistribute it and/or
2265- modify it under the terms of the GNU Lesser General Public
2266- License as published by the Free Software Foundation; either
2267- version 2.1 of the License, or (at your option) any later version.
2268-
2269- See the file COPYING for the full license text.
2270-*/
2271-
2272-#ifndef __SYLPH_SOCKET_H__
2273-#define __SYLPH_SOCKET_H__
2274-
2275-#include <glib.h>
2276-#include "config.h"
2277-#if HAVE_NETDB_H
2278-# include <netdb.h>
2279-#endif
2280-
2281-typedef struct _SockInfo SockInfo;
2282-
2283-typedef enum
2284-{
2285- CONN_READY,
2286- CONN_LOOKUPSUCCESS,
2287- CONN_ESTABLISHED,
2288- CONN_LOOKUPFAILED,
2289- CONN_FAILED
2290-} ConnectionState;
2291-
2292-typedef gint (*SockConnectFunc) (SockInfo *sock,
2293- gpointer data);
2294-typedef gboolean (*SockFunc) (SockInfo *sock,
2295- GIOCondition condition,
2296- gpointer data);
2297-
2298-struct _SockInfo
2299-{
2300- gint sock;
2301- GIOChannel *sock_ch;
2302-
2303- gchar *hostname;
2304- gushort port;
2305- ConnectionState state;
2306- gboolean nonblock;
2307- gpointer data;
2308-
2309- SockFunc callback;
2310- GIOCondition condition;
2311-};
2312-
2313-void send_open_command (gint sock, const gchar *command,
2314- gchar **args);
2315-gint socket_init (const gchar *instance_name,
2316- const gchar *config_dir, gboolean *exists);
2317-
2318-gint sock_cleanup (void);
2319-
2320-gint sock_set_io_timeout (guint sec);
2321-
2322-gint sock_set_nonblocking_mode (SockInfo *sock, gboolean nonblock);
2323-gboolean sock_is_nonblocking_mode (SockInfo *sock);
2324-
2325-gboolean sock_has_read_data (SockInfo *sock);
2326-
2327-guint sock_add_watch (SockInfo *sock, GIOCondition condition,
2328- SockFunc func, gpointer data);
2329-
2330-struct hostent *my_gethostbyname (const gchar *hostname);
2331-
2332-SockInfo *sock_connect (const gchar *hostname, gushort port);
2333-#ifdef G_OS_UNIX
2334-gint sock_connect_async (const gchar *hostname, gushort port,
2335- SockConnectFunc func, gpointer data);
2336-gint sock_connect_async_cancel (gint id);
2337-#endif
2338-
2339-/* Basic I/O functions */
2340-gint sock_printf (SockInfo *sock, const gchar *format, ...)
2341- G_GNUC_PRINTF(2, 3);
2342-gint sock_read (SockInfo *sock, gchar *buf, gint len);
2343-gint sock_write (SockInfo *sock, const gchar *buf, gint len);
2344-gint sock_write_all (SockInfo *sock, const gchar *buf, gint len);
2345-gint sock_gets (SockInfo *sock, gchar *buf, gint len);
2346-gint sock_getline (SockInfo *sock, gchar **line);
2347-gint sock_puts (SockInfo *sock, const gchar *buf);
2348-gint sock_peek (SockInfo *sock, gchar *buf, gint len);
2349-gint sock_close (SockInfo *sock);
2350-
2351-/* Functions to directly work on FD. They are needed for pipes */
2352-gint fd_connect_inet (gushort port);
2353-gint fd_open_inet (gushort port);
2354-gint fd_connect_unix (const gchar *path);
2355-gint fd_open_unix (const gchar *path);
2356-gint fd_accept (gint sock);
2357-
2358-gint fd_read (gint sock, gchar *buf, gint len);
2359-gint fd_write (gint sock, const gchar *buf, gint len);
2360-gint fd_write_all (gint sock, const gchar *buf, gint len);
2361-gint fd_gets (gint sock, gchar *buf, gint len);
2362-gint fd_getline (gint sock, gchar **line);
2363-gint fd_close (gint sock);
2364-
2365-#endif /* __SYLPH_SOCKET_H__ */
2366
2367=== modified file 'po/POTFILES.in'
2368--- po/POTFILES.in 2013-08-02 18:32:18 +0000
2369+++ po/POTFILES.in 2013-09-01 12:49:57 +0000
2370@@ -69,7 +69,6 @@
2371 katze/gtk3-compat.c
2372 katze/katze-http-cookies-sqlite.c
2373 katze/katze-http-cookies.c
2374-midori/socket.c
2375 midori/midori-panedaction.vala
2376 midori/midori-privatedata.c
2377 midori/midori-dialog.vala
2378
2379=== modified file 'wscript'
2380--- wscript 2013-08-14 17:57:02 +0000
2381+++ wscript 2013-09-01 12:49:57 +0000
2382@@ -268,16 +268,6 @@
2383 conf.env['HAVE_GTK3'] = have_gtk3
2384 conf.env['HAVE_WEBKIT2'] = option_enabled ('webkit2')
2385
2386- if option_enabled ('unique'):
2387- if have_gtk3: unique_pkg = 'unique-3.0'
2388- else: unique_pkg = 'unique-1.0'
2389- if not check_pkg (unique_pkg, '0.9', mandatory=False):
2390- option_checkfatal ('unique', 'single instance')
2391- else:
2392- conf.define ('UNIQUE_VERSION', 'No')
2393- conf.check_message_custom ('unique', '', 'disabled')
2394- conf.define ('HAVE_UNIQUE', [0,1][conf.env['UNIQUE_VERSION'] != 'No'])
2395-
2396 check_pkg ('libsoup-gnome-2.4', '2.27.90', var='LIBSOUP')
2397 if check_version (conf.env['LIBSOUP_VERSION'], 2, 29, 91):
2398 conf.define ('HAVE_LIBSOUP_2_29_91', 1)
2399@@ -299,14 +289,6 @@
2400 if 'LINGUAS' in os.environ: conf.env['LINGUAS'] = os.environ['LINGUAS']
2401
2402 conf.check (header_name='unistd.h')
2403- if not conf.env['HAVE_UNIQUE']:
2404- if Options.platform == 'win32':
2405- conf.check (lib='ws2_32')
2406- conf.define ('HAVE_NETDB_H', [0,1][conf.check (header_name='netdb.h')])
2407- conf.check (header_name='sys/wait.h')
2408- conf.check (header_name='sys/select.h')
2409- conf.check (function_name='inet_aton', header_name='sys/types.h sys/socket.h netinet/in.h arpa/inet.h')
2410- conf.check (function_name='inet_addr', header_name='sys/types.h sys/socket.h netinet/in.h arpa/inet.h')
2411 conf.define ('HAVE_OSX', int(sys.platform == 'darwin'))
2412 if Options.platform == 'win32':
2413 conf.check (lib='ole32')
2414@@ -356,11 +338,6 @@
2415 '-Wmissing-format-attribute -Wnested-externs'.split ())
2416 conf.env.append_value ('CCFLAGS', '-Wno-unused-variable -Wno-comment'.split ())
2417
2418- if conf.env['UNIQUE_VERSION'] == '1.0.4':
2419- Utils.pprint ('RED', 'unique 1.0.4 found, this version is erroneous.')
2420- Utils.pprint ('RED', 'Please use an older or newer version.')
2421- sys.exit (1)
2422-
2423 def set_options (opt):
2424 def add_enable_option (option, desc, group=None, disable=False):
2425 if group == None:
2426@@ -600,7 +577,6 @@
2427
2428 # Avoid i18n-related false failures
2429 os.environ['LC_ALL'] = 'C'
2430- os.environ['UNIQUE_BACKEND'] = 'bacon'
2431 if is_mingw (Build.bld.env):
2432 os.environ['MIDORI_EXEC_PATH'] = Build.bld.env['PREFIX']
2433 test = UnitTest.unit_test ()

Subscribers

People subscribed via source and target branches

to all changes: