Example #1
0
static void
start_registration(struct register_data *rd)
{
	LmConnection  *lmconn;
	GError *error = NULL;

	lmconn = lm_connection_new(NULL);
	if (rd->use_ssl) {
		if (!set_ssl(lmconn, &error, NULL, FALSE))
			goto err;
	} else {
		if (!set_ssl(lmconn, &error, NULL, TRUE))
			goto err;
	}
	if (settings_get_bool("xmpp_use_proxy") && !set_proxy(lmconn, &error))
		goto err;
	if (rd->port <= 0)
		rd->port = rd->use_ssl ? LM_CONNECTION_DEFAULT_PORT_SSL
		    : LM_CONNECTION_DEFAULT_PORT;
	lm_connection_set_server(lmconn, rd->address);
	lm_connection_set_port(lmconn, rd->port);
	lm_connection_set_jid(lmconn, NULL);
	rd->id = NULL;
	rd->lmconn = lmconn;
	rd->handler = NULL;
	register_data = g_slist_prepend(register_data, rd);
	lm_connection_set_disconnect_function(lmconn, register_lm_close_cb,
	    rd, NULL);
	if (!lm_connection_open(lmconn, register_lm_open_cb, rd, NULL,
	    &error)) {
		rd_cleanup(rd);
		signal_emit("xmpp register error", 3, rd->username, rd->domain,
		    error != NULL ? error->message : NULL);
		if (error != NULL)
			g_error_free(error);
	}
	return;

err:
	signal_emit("xmpp register error", 3, rd->username, rd->domain,
	    error != NULL ? error->message : NULL);
	if (error != NULL)
		g_error_free(error);
	lm_connection_unref(lmconn);
}
Example #2
0
void
xmpp_server_connect(XMPP_SERVER_REC *server)
{
	GError *error;
	const char *err_msg;

	if (!IS_XMPP_SERVER(server))
		return;
	error = NULL;
	err_msg = NULL;
	if (server->connrec->use_ssl) {
		if (!set_ssl(server->lmconn, &error, server, FALSE)) {
			err_msg = "Cannot init ssl";
			goto err;
		}
	} else
		set_ssl(server->lmconn, &error, server, TRUE);
	if (settings_get_bool("xmpp_use_proxy")
	    && !set_proxy(server->lmconn, &error)) {
		err_msg = "Cannot set proxy";
		goto err;
	}
	lm_connection_set_disconnect_function(server->lmconn,
	    lm_close_cb, server, NULL);
	lookup_servers = g_slist_append(lookup_servers, server);
	signal_emit("server looking", 1, server);
	server->timeout_tag = g_timeout_add(
	    settings_get_time("server_connect_timeout"),
	    (GSourceFunc)check_connection_timeout, server);
	if (!lm_connection_open(server->lmconn,  lm_open_cb, server,
	    NULL, &error)) {
		err_msg = "Connection failed";
		goto err;
	}
	return;

err:
	server->connection_lost = TRUE;
	if (error != NULL) {
		server_connect_failed(SERVER(server), error->message);
		g_error_free(error);
	} else
		server_connect_failed(SERVER(server), err_msg);
}
Example #3
0
 std::auto_ptr<document> dom_parser::parse_url(const std::string& url, const std::string& proxy)
 {
     set_global_variables global_variables;
     // Create a libxml2 parser context for parsing the xml string.
     if (url.empty())
     {
         throw dom_error("fail to parse remote xml: URL is null");
     }
     // Set the HTTP proxy URL.
     set_nano_http_proxy set_proxy(proxy);
     // Create a libxml2 parser context for parsing the URL.
     dom_parser_context_wrapper context( xmlCreateURLParserCtxt(url.c_str(), 0) );
     if (context.get() == 0)
     {
         throw dom_error("Fail to parse remote xml: unable to create libxml2 parser context");
     }
     // Parse remote xml under the constructed parser context.
     xmlDoc* px = parse_in_context(context.get());
     assert(px != 0);
     return std::auto_ptr<document>(new document(px));
 }
Example #4
0
static void parse_args(int argc, char **argv)
{
    static const struct option opts[] = {
	{ "version", no_argument, NULL, 'V' },
	{ "help", no_argument, NULL, 'h' },
	{ "proxy", required_argument, NULL, 'p' },
	{ "tolerant", no_argument, NULL, 't' },
	{ "rcfile", required_argument, NULL, 'r' },
	{ 0, 0, 0, 0 }
    };
    int optc;
    while ((optc = getopt_long(argc, argv, "ehtp:r:V", opts, NULL)) != -1) {
	switch (optc) {
	case 'h': usage(); exit(-1);
	case 'V': execute_about(); exit(-1);
	case 'p': set_proxy(optarg); break;
	case 't': tolerant = 1; break;
	case 'r': rcfile = strdup(optarg); break;
	case '?': 
	default:
	    printf(_("Try `%s --help' for more information.\n"), progname);
	    exit(-1);
	}
    }
    if (optind == (argc-1)) {
	open_connection(argv[optind]);
#ifdef HAVE_ADD_HISTORY
	{ 
	    char *run_cmd;
	    run_cmd = ne_concat("open ", argv[optind], NULL);
	    add_history(run_cmd);
	    free(run_cmd);
	}
#endif
    } else if (optind < argc) {
	usage();
	exit(-1);
    }
}
Example #5
0
errr report_score(void)
{
#ifdef MACINTOSH
	OSStatus err;
#else
	errr err = 0;
#endif

#ifdef WINDOWS
	WSADATA wsaData;
	WORD wVersionRequested =(WORD) (( 1) |  ( 1 << 8));
#endif

	BUF *score;
	int sd;
	char seikakutmp[128];

	score = buf_new();

	sprintf(seikakutmp, "%s ", ap_ptr->title);

	buf_sprintf(score, "name: %s\n", player_name);
	buf_sprintf(score, "version: Hengband %d.%d.%d\n",
		    FAKE_VER_MAJOR-10, FAKE_VER_MINOR, FAKE_VER_PATCH);
	buf_sprintf(score, "score: %d\n", total_points());
	buf_sprintf(score, "level: %d\n", p_ptr->lev);
	buf_sprintf(score, "depth: %d\n", dun_level);
	buf_sprintf(score, "maxlv: %d\n", p_ptr->max_plv);
	buf_sprintf(score, "maxdp: %d\n", max_dlv[DUNGEON_ANGBAND]);
	buf_sprintf(score, "au: %d\n", p_ptr->au);
	buf_sprintf(score, "turns: %d\n", turn_real(turn));
	buf_sprintf(score, "sex: %d\n", p_ptr->psex);
	buf_sprintf(score, "race: %s\n", rp_ptr->title);
	buf_sprintf(score, "class: %s\n", cp_ptr->title);
	buf_sprintf(score, "seikaku: %s\n", seikakutmp);
	buf_sprintf(score, "realm1: %s\n", realm_names[p_ptr->realm1]);
	buf_sprintf(score, "realm2: %s\n", realm_names[p_ptr->realm2]);
	buf_sprintf(score, "killer: %s\n", p_ptr->died_from);
	buf_sprintf(score, "-----charcter dump-----\n");

	make_dump(score);

	if (screen_dump)
	{
		buf_sprintf(score, "-----screen shot-----\n");
		buf_append(score, screen_dump, strlen(screen_dump));
	}
	
#ifdef WINDOWS
	if (WSAStartup(wVersionRequested, &wsaData))
	{
		msg_print("Report: WSAStartup failed.");
		goto report_end;
	}
#endif

#ifdef MACINTOSH
#if TARGET_API_MAC_CARBON
	err = InitOpenTransportInContext(kInitOTForApplicationMask, NULL);
#else
	err = InitOpenTransport();
#endif
	if (err != noErr)
	{
		msg_print("Report: OpenTransport failed.");
		return 1;
	}
#endif

	Term_clear();

	while (1)
	{
		char buff[160];
		prt("connecting...", 0, 0);
		Term_fresh();
		
		/* プロキシを設定する */
		set_proxy(HTTP_PROXY, HTTP_PROXY_PORT);

		/* Connect to the score server */
		sd = connect_server(HTTP_TIMEOUT, SCORE_SERVER, SCORE_PORT);


		if (!(sd < 0)) break;
		sprintf(buff, "Failed to connect to the score server.(%s)", soc_err());
		prt(buff, 0, 0);
		(void)inkey();
		
		if (!get_check_strict("Try again? ", CHECK_NO_HISTORY))
		{
			err = 1;
			goto report_end;
		}
	}
	prt("Sending the score...", 0, 0);
	Term_fresh();
	http_post(sd, SCORE_PATH, score);

	disconnect_server(sd);
 report_end:
#ifdef WINDOWS
	WSACleanup();
#endif

#ifdef MACINTOSH
#if TARGET_API_MAC_CARBON
	CloseOpenTransportInContext(NULL);
#else
	CloseOpenTransport();
#endif
#endif

	return err;
}
Example #6
0
static void *worker_thread(void *ptr) {
  net_io_request_t *request = (net_io_request_t*)ptr;
  
  g_message("thread: running");

  //  sleep(2);  // useful for debugging

  CURL *curl = curl_easy_init();
  if(curl) {
    g_message("thread: prepare curl");
    /* prepare target memory */
    request->result.data.ptr = NULL;
    request->result.data.len = 0;

    /* In case Curl is causing stack fault on long jumps. */
    curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);

    curl_easy_setopt(curl, CURLOPT_URL, request->url);
      
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, &request->result.data);
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, mem_write);

    /* g_message("thread: set proxy"); */
    set_proxy(curl, request->proxy);

    /* set user name and password for the authentication */
    g_message("thread: set username if any");
    if(request->user)
      curl_easy_setopt(curl, CURLOPT_USERPWD, request->user);
    
    /* setup progress notification */
    curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
    curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, curl_progress_func);
    curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, request);
    
    curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, request->buffer);
    
    curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1l);
    
    /* play nice and report some user agent */
    curl_easy_setopt(curl, CURLOPT_USERAGENT, PACKAGE "-libcurl/" VERSION); 
    
    g_message("thread: perform request");
    request->res = curl_easy_perform(curl);
    g_message("thread: curl perform returned with %d\n", request->res);
    
    curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &request->response);

    /* always cleanup */
    curl_easy_cleanup(curl);
  } else
    g_message("thread: unable to init curl");
  
  g_message("thread: io done");

  if(request->cb)
    g_idle_add(net_io_idle_cb, request);

  request_free(request);
  
  g_message("thread: terminating");
  return NULL;
}
Example #7
0
int main(int argc, char *argv[])
{
	char *env;
	int i, n, timeout = 250;
	struct connection *conn;

	method = "HEAD";

	while ((i = getopt(argc, argv, "hp:t:vT:")) != -1)
		switch ((char)i) {
		case 'h':
			usage(0);
		case 'p':
			set_proxy(optarg);
			break;
		case 't':
			thread_limit = strtol(optarg, NULL, 0);
			break;
		case 'v':
			verbose++;
			break;
		case 'T':
			read_timeout = strtol(optarg, NULL, 0);
			break;
		default:
			usage(1);
		}

	if (optind < argc)
		while (optind < argc)
			read_link_file(argv[optind++]);
	else
		read_urls(stdin);

	/* set_proxy will not use this if proxy already set */
	env = getenv("COMICS_PROXY");
	if (env)
		set_proxy(env);

	if (thread_limit == 0) {
		printf("You must allow at least one thread\n");
		exit(1);
	}

	if (thread_limit > n_comics)
		thread_limit = n_comics;

#ifdef _WIN32
	win32_init();
#else
	signal(SIGTERM, dump_outstanding);
	signal(SIGHUP, dump_outstanding);
#endif

	npoll = thread_limit + 1; /* add one for stdin */
	ufds = must_calloc(npoll, sizeof(struct pollfd));
	for (i = 0; i < npoll; ++i)
		ufds[i].fd = -1;

	while (head || outstanding) {

		start_next_comic();

		n = poll(ufds, npoll, timeout);
		if (n < 0) {
			my_perror("poll");
			continue;
		}

		if (n == 0) {
			timeout_connections();
			if (!start_next_comic())
				/* Once we have all the comics
				 * started, increase the timeout
				 * period. */
				timeout = 1000;
			continue;
		}

		for (conn = comics; conn; conn = conn->next)
			if (!conn->poll)
				continue;
			else if (conn->poll->revents & POLLOUT) {
				if (!conn->connected)
					check_connect(conn);
				else {
					time(&conn->access);
					write_request(conn);
				}
			} else if (conn->poll->revents & POLLIN) {
				/* This check is needed for openssl */
				if (!conn->connected)
					check_connect(conn);
				else
					read_conn(conn);
			}
	}

	out_results(comics, 0);

	return n_comics != gotit;
}
Example #8
0
int main(int argc, char *argv[])
{
	char *env;
	int i, verify = 0, clean = 0;

	while ((i = getopt(argc, argv, "cd:hi:kl:p:t:vCT:V")) != -1)
		switch ((char)i) {
		case 'c':
			clean = 1;
			break;
		case 'd':
			comics_dir = must_strdup(optarg);
			break;
		case 'h':
			usage(0);
		case 'i':
			add_index_dir(optarg);
			break;
		case 'k':
			unlink_index = 0;
			break;
		case 'l':
			links_only = fopen(optarg, "w");
			if (!links_only) {
				my_perror(optarg);
				exit(1);
			}
			break;
		case 'p':
			set_proxy(optarg);
			break;
		case 't':
			thread_limit = strtol(optarg, NULL, 0);
			threads_set = 1;
			break;
		case 'v':
			verbose++;
			break;
		case 'C':
#ifdef WANT_SSL
			openssl_list_ciphers();
#else
			puts("-C not supported.");
#endif
			exit(0);

		case 'T':
			read_timeout = strtol(optarg, NULL, 0);
			break;
		case 'V':
			verify = 1;
			break;
		default:
			usage(1);
		}

	if (optind < argc)
		while (optind < argc) {
			if (read_config(argv[optind])) {
				printf("Fatal error in config file\n");
				exit(1);
			}
			++optind;
		}
	else if (read_config(NULL)) {
		printf("Fatal error in config file\n");
		exit(1);
	}

	if (verify) {
		printf("Comics: %u Skipped today: %u\n", n_comics + skipped, skipped);
		if (verbose)
			dump_outstanding(0);
		return 0;
	}

	/* set_proxy will not use this if proxy already set */
	env = getenv("COMICS_PROXY");
	if (env)
		set_proxy(env);

	if (thread_limit == 0) {
		printf("You must allow at least one thread\n");
		exit(1);
	}

	if (thread_limit > n_comics)
		thread_limit = n_comics;

	cd_comics_dir(clean);

#ifdef _WIN32
	win32_init();
#else
	signal(SIGTERM, dump_outstanding);
	signal(SIGHUP, dump_outstanding);
	signal(SIGPIPE, sigpipe);
#endif

	if (links_only)
		fclose(links_only);

	want_extensions = 1;
	main_loop();

	out_results(comics, skipped);
#ifdef WIN32
	printf("Hit return to exit");
	getchar();
#endif

	free_cache(); /* for valgrind */
	free_comics(); /* for valgrind */
	if (debug_fp)
		fclose(debug_fp);
	return 0;
}
bool Scrobble::submit()
{
    if (entries.empty())
    {
        add_log(LOG_ERROR, tr("Nothing to submit!"));
        emit submission_finished(false);
        return false;
    }

    // May already have been called, but better to be safe.
    cleanup_tracks();

    if (check_age())
    {
        add_log(LOG_ERROR, tr("One or more tracks are too old.  Correct this and try again."));
        emit submission_finished(false);
        return false;
    }

    set_proxy();

    Submit::submit_context conn;

    conn.entries = &entries;
    conn.have_mb = have_mb;

    submissions.clear();
    num_submissions = 0;
    for (int i = 0; i < CONFIG_NUM_SITES; i++)
    {
        if (conf->sites[i].enabled
            && !conf->sites[i].username.isEmpty()
            && !conf->sites[i].password_hash.isEmpty()
            && !conf->sites[i].handshake_host.isEmpty()
            && !conf->sites[i].conf_name.isEmpty())
        {
            num_submissions++;
            conn.username = conf->sites[i].username;
            conn.password_hash = conf->sites[i].password_hash;
            conn.host = conf->sites[i].handshake_host;
            conn.site_index = i;
            conn.mutex = mutex;

            Submit *sub = new Submit(i);
            submissions.insert(i, sub);

            submissions[i]->init(conn);

            connect(submissions[i],
                    SIGNAL(finished(bool, QString)),
                    this, SLOT(submit_finished(bool, QString)));
            connect(submissions[i],
                    SIGNAL(add_log(LOG_LEVEL,QString)),
                    this, SLOT(add_log(LOG_LEVEL, QString)));

            //if something while submitting fails, then notify the scrobbler which will also break the progress(-dialog) if necessary
            connect(submissions[i],
                    SIGNAL(signalHandshakeFailure(QString)),
                    this,
                    SLOT(slotCancelProgress())/*, Qt::DirectConnection*/); //the real stuff: submission -> scrobbler -> progress

            submissions[i]->do_submit();
        }
    }