Re: question about libsoup dependency



On Wed, 10 Feb 2010 14:07:04 -0800, n179911 <n179911 gmail com> wrote:
> HI,
> 
> From LibSoup webpage, it said 'It uses GObjects and the glib main
> loop, to integrate well with GNOME applications,'
> 
> can you please tell me if I can run LibSoup without calling
'gtk_main()'?
> If yes, how can I create a main loop which LibSoup needs?
> 
> Thank you.

here is one of my experimental test programs you can look at... (I've been
using this webmail client that has been screwing up all my posts, we'll
see
what happens...)

#include <stdio.h>
#include <libsoup/soup.h>

void index_callback(SoupServer *server_context, SoupMessage *message,
                    const char *path, GHashTable *query,
                    SoupClientContext *client, gpointer opaq)
{
 const char *mime_type;
 GByteArray *body;

 if(message->method != SOUP_METHOD_GET)
 {
  soup_message_set_status (message, SOUP_STATUS_NOT_IMPLEMENTED);
  return;
 }

 body = g_byte_array_new();
 g_byte_array_append(body, "<h1>hello world</h1>", 20);

 soup_message_set_status(message, SOUP_STATUS_OK);
 soup_message_set_response(message, mime_type, SOUP_MEMORY_TAKE,
                           body->data, body->len);
}


int main(int argc, char **argv)
{
 SoupAddress *server_address;
 SoupServer *server_context;
 GMainLoop *main_loop;
 struct sockaddr_in ipv4;

 ipv4.sin_family = AF_INET;
 ipv4.sin_port = htons(4000);
 if(inet_pton(AF_INET, "127.0.0.1", &(ipv4.sin_addr)) < 1)
 {
  printf("inet_pton() failed\n");
  return 1;
 }

 g_type_init();
 g_thread_init(NULL);

 main_loop = g_main_loop_new(NULL, FALSE);
/*
 if((server_address = soup_address_new("localhost", 4000)) == NULL)
 {
  printf("soup_addres_new() failed\n");
  return 1;
 }
*/

 if((server_address = soup_address_new_from_sockaddr((struct sockaddr *)
&ipv4,
                                                     sizeof(struct
sockaddr_in))) == NULL)
 {
  printf("soup_address_new_from_sockaddr() failed\n");
  return 1;
 }

 if((server_context = soup_server_new(SOUP_SERVER_INTERFACE,
server_address,
                                      NULL)) == NULL)
 {
  printf("soup_server_new() failed\n");
  return 1;
 }

 soup_server_add_handler(server_context, "/", 
                         index_callback, NULL, NULL);

 soup_server_run_async(server_context);
                                      
 g_main_loop_run(main_loop); 

 return 0;
}

-- 
www.thomasstover.com



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]