예제 #1
0
static void
hbn_cb(GObject *sender, GAsyncResult *res, gpointer data) {
	StunHBNListenData *ld = NULL;
	GError *error = NULL;

	ld = g_new0(StunHBNListenData, 1);

	ld->addresses = g_resolver_lookup_by_name_finish(G_RESOLVER(sender),
			res, &error);
	if(error != NULL) {
		nattype.status = PURPLE_STUN_STATUS_UNDISCOVERED;
		nattype.lookup_time = time(NULL);

		do_callbacks();

		return;
	}

	ld->port = GPOINTER_TO_INT(data);
	if (!purple_network_listen_range(12108, 12208, AF_UNSPEC, SOCK_DGRAM, TRUE, hbn_listen_cb, ld)) {
		nattype.status = PURPLE_STUN_STATUS_UNKNOWN;
		nattype.lookup_time = time(NULL);

		do_callbacks();

		return;
	}
}
예제 #2
0
static void
hbn_listen_cb(int fd, gpointer data) {
	StunHBNListenData *ld = (StunHBNListenData *)data;
	GInetAddress *address = NULL;
	GSocketAddress *socket_address = NULL;
	struct stun_conn *sc;
	static struct stun_header hdr_data;

	if(fd < 0) {
		nattype.status = PURPLE_STUN_STATUS_UNKNOWN;
		nattype.lookup_time = time(NULL);
		do_callbacks();
		return;
	}

	sc = g_new0(struct stun_conn, 1);
	sc->fd = fd;

	sc->addr.sin_family = AF_INET;
	sc->addr.sin_port = htons(purple_network_get_port_from_fd(fd));
	sc->addr.sin_addr.s_addr = INADDR_ANY;

	sc->incb = purple_input_add(fd, PURPLE_INPUT_READ, reply_cb, sc);

	address = G_INET_ADDRESS(ld->addresses->data);
	socket_address = g_inet_socket_address_new(address, ld->port);

	g_socket_address_to_native(socket_address, &(sc->addr), g_socket_address_get_native_size(socket_address), NULL);

	g_object_unref(G_OBJECT(address));
	g_object_unref(G_OBJECT(socket_address));
	g_resolver_free_addresses(ld->addresses);
	g_free(ld);

	hdr_data.type = htons(MSGTYPE_BINDINGREQUEST);
	hdr_data.len = 0;
	hdr_data.transid[0] = rand();
	hdr_data.transid[1] = ntohl(((int)'g' << 24) + ((int)'a' << 16) + ((int)'i' << 8) + (int)'m');
	hdr_data.transid[2] = rand();
	hdr_data.transid[3] = rand();

	if(sendto(sc->fd, &hdr_data, sizeof(struct stun_header), 0,
			(struct sockaddr *)&(sc->addr),
			sizeof(struct sockaddr_in)) < (gssize)sizeof(struct stun_header)) {
		nattype.status = PURPLE_STUN_STATUS_UNKNOWN;
		nattype.lookup_time = time(NULL);
		do_callbacks();
		close_stun_conn(sc);
		return;
	}
	sc->test = 1;
	sc->packet = &hdr_data;
	sc->packetsize = sizeof(struct stun_header);
	sc->timeout = purple_timeout_add(500, (GSourceFunc) timeoutfunc, sc);
}
예제 #3
0
파일: stun.c 프로젝트: CkNoSFeRaTU/pidgin
static void hbn_listen_cb(int fd, gpointer data) {
	GSList *hosts = data;
	struct stun_conn *sc;
	static struct stun_header hdr_data;

	if(fd < 0) {
		nattype.status = PURPLE_STUN_STATUS_UNKNOWN;
		nattype.lookup_time = time(NULL);
		do_callbacks();
		return;
	}

	sc = g_new0(struct stun_conn, 1);
	sc->fd = fd;

	sc->addr.sin_family = AF_INET;
	sc->addr.sin_port = htons(purple_network_get_port_from_fd(fd));
	sc->addr.sin_addr.s_addr = INADDR_ANY;

	sc->incb = purple_input_add(fd, PURPLE_INPUT_READ, reply_cb, sc);

	hosts = g_slist_delete_link(hosts, hosts);
	memcpy(&(sc->addr), hosts->data, sizeof(struct sockaddr_in));
	g_free(hosts->data);
	hosts = g_slist_delete_link(hosts, hosts);
	while (hosts) {
		hosts = g_slist_delete_link(hosts, hosts);
		g_free(hosts->data);
		hosts = g_slist_delete_link(hosts, hosts);
	}

	hdr_data.type = htons(MSGTYPE_BINDINGREQUEST);
	hdr_data.len = 0;
	hdr_data.transid[0] = rand();
	hdr_data.transid[1] = ntohl(((int)'g' << 24) + ((int)'a' << 16) + ((int)'i' << 8) + (int)'m');
	hdr_data.transid[2] = rand();
	hdr_data.transid[3] = rand();

	if(sendto(sc->fd, &hdr_data, sizeof(struct stun_header), 0,
			(struct sockaddr *)&(sc->addr),
			sizeof(struct sockaddr_in)) < (gssize)sizeof(struct stun_header)) {
		nattype.status = PURPLE_STUN_STATUS_UNKNOWN;
		nattype.lookup_time = time(NULL);
		do_callbacks();
		close_stun_conn(sc);
		return;
	}
	sc->test = 1;
	sc->packet = &hdr_data;
	sc->packetsize = sizeof(struct stun_header);
	sc->timeout = purple_timeout_add(500, (GSourceFunc) timeoutfunc, sc);
}
예제 #4
0
void    GLUI_Spinner::do_click( void )
{
  int    direction = 0;
  float  incr;
  float  modifier_factor;

  if ( state == GLUI_SPINNER_STATE_UP )
    direction = +1;
  else if ( state == GLUI_SPINNER_STATE_DOWN )
    direction = -1;

  increase_growth();

  modifier_factor = 1.0;
  if ( glui ) {
    if ( glui->curr_modifiers & GLUT_ACTIVE_SHIFT ) 
      modifier_factor = 100.0f;
    else if ( glui->curr_modifiers & GLUT_ACTIVE_CTRL ) 
      modifier_factor = .01f;
  }

  if ( this->data_type == GLUI_SPINNER_FLOAT OR 1) {
    incr = growth * direction * modifier_factor * user_speed;
    edittext->set_float_val( edittext->float_val + incr );
    /** Remember, edittext mirrors the float and int values ***/
  }

  /*** Now update live variable and do callback.  We don't want
    to do the callback on each iteration of this function, just on every 
    i^th iteration, where i is given by GLUI_SPINNER_CALLBACK_INTERVAL ****/
  callback_count++;
  //  if ( (callback_count % GLUI_SPINNER_CALLBACK_INTERVAL ) == 0 )
    do_callbacks();
}
예제 #5
0
파일: prefs.c 프로젝트: psunkari/spicebird
void
purple_prefs_set_path_list(const char *name, GList *value)
{
	struct purple_pref *pref = find_pref(name);
	if(pref) {
		GList *tmp;

		if(pref->type != PURPLE_PREF_PATH_LIST) {
			purple_debug_error("prefs",
					"purple_prefs_set_path_list: %s not a path list pref\n",
					name);
			return;
		}

		g_list_foreach(pref->value.stringlist, (GFunc)g_free, NULL);
		g_list_free(pref->value.stringlist);
		pref->value.stringlist = NULL;

		for(tmp = value; tmp; tmp = tmp->next)
			pref->value.stringlist = g_list_prepend(pref->value.stringlist,
					g_strdup(tmp->data));
		pref->value.stringlist = g_list_reverse(pref->value.stringlist);

		do_callbacks(name, pref);

	} else {
		purple_prefs_add_path_list(name, value);
	}
}
예제 #6
0
locale
ios_base::imbue(const locale& loc)
{
    locale result = *loc_;
#ifndef _EWL_NO_EXCEPTIONS
    try
    {
#endif  // _EWL_NO_EXCEPTIONS
        locale* newloc = new locale(loc);
#ifdef _EWL_NO_EXCEPTIONS
        if (newloc == 0)
            __ewl_error("ios_base::imbue out of memory");
#endif  // _EWL_NO_EXCEPTIONS
        delete loc_;
        loc_ = newloc;
#ifndef _EWL_TINY_IO
        do_callbacks(imbue_event);
#endif
#ifndef _EWL_NO_EXCEPTIONS
    }
    catch (...)
    {
        setstate(badbit);
    }
#endif  // _EWL_NO_EXCEPTIONS
    return result;
}
예제 #7
0
파일: prefs.c 프로젝트: psunkari/spicebird
void
purple_prefs_set_string_list(const char *name, GList *value)
{
	struct purple_pref *pref = find_pref(name);
	if(pref) {
		GList *tmp;

		if(pref->type != PURPLE_PREF_STRING_LIST) {
			purple_debug_error("prefs",
					"purple_prefs_set_string_list: %s not a string list pref\n",
					name);
			return;
		}

		g_list_foreach(pref->value.stringlist, (GFunc)g_free, NULL);
		g_list_free(pref->value.stringlist);
		pref->value.stringlist = NULL;

		for(tmp = value; tmp; tmp = tmp->next) {
			if(tmp->data != NULL && !g_utf8_validate(tmp->data, -1, NULL)) {
				purple_debug_error("prefs", "purple_prefs_set_string_list: Skipping invalid UTF8 for string list pref %s\n", name);
				continue;
			}
			pref->value.stringlist = g_list_prepend(pref->value.stringlist,
					g_strdup(tmp->data));
		}
		pref->value.stringlist = g_list_reverse(pref->value.stringlist);

		do_callbacks(name, pref);

	} else {
		purple_prefs_add_string_list(name, value);
	}
}
예제 #8
0
파일: prefs.c 프로젝트: psunkari/spicebird
void
purple_prefs_set_string(const char *name, const char *value)
{
	struct purple_pref *pref = find_pref(name);

	if(value != NULL && !g_utf8_validate(value, -1, NULL)) {
		purple_debug_error("prefs", "purple_prefs_set_string: Cannot store invalid UTF8 for string pref %s\n", name);
		return;
	}

	if(pref) {
		if(pref->type != PURPLE_PREF_STRING && pref->type != PURPLE_PREF_PATH) {
			purple_debug_error("prefs",
					"purple_prefs_set_string: %s not a string pref\n", name);
			return;
		}

		if (!purple_strequal(pref->value.string, value)) {
			g_free(pref->value.string);
			pref->value.string = g_strdup(value);
			do_callbacks(name, pref);
		}
	} else {
		purple_prefs_add_string(name, value);
	}
}
예제 #9
0
파일: stun.c 프로젝트: CkNoSFeRaTU/pidgin
static gboolean timeoutfunc(gpointer data) {
	struct stun_conn *sc = data;
	if(sc->retry >= 2) {
		purple_debug_warning("stun", "request timed out, giving up.\n");
		if(sc->test == 2)
			nattype.type = PURPLE_STUN_NAT_TYPE_SYMMETRIC;

		/* set unknown */
		nattype.status = PURPLE_STUN_STATUS_UNKNOWN;

		nattype.lookup_time = time(NULL);

		/* callbacks */
		do_callbacks();

		/* we don't need to remove the timeout (returning FALSE) */
		sc->timeout = 0;
		close_stun_conn(sc);

		return FALSE;
	}
	purple_debug_info("stun", "request timed out, retrying.\n");
	sc->retry++;
	if (sendto(sc->fd, sc->packet, sc->packetsize, 0,
		(struct sockaddr *)&(sc->addr), sizeof(struct sockaddr_in)) !=
		(gssize)sc->packetsize)
	{
		purple_debug_warning("stun", "sendto failed\n");
		return FALSE;
	}
	return TRUE;
}
예제 #10
0
void    GLUI_Spinner::do_drag( int x, int y )
{
  int   delta_y;
  float incr, modifier_factor;
  /* int delta_x;              */

  modifier_factor = 1.0f;
  if ( glui ) {
    if ( glui->curr_modifiers & GLUT_ACTIVE_SHIFT ) 
      modifier_factor = 100.0f;
    else if ( glui->curr_modifiers & GLUT_ACTIVE_CTRL ) 
      modifier_factor = .01f;
  }

  /*  delta_x = x - last_x;              */
  delta_y = -(y - last_y);
 
  if ( this->data_type == GLUI_SPINNER_FLOAT OR 1 ) {
    incr = growth * delta_y * modifier_factor * user_speed;
    edittext->set_float_val( edittext->float_val + incr );
    /** Remember, edittext mirrors the float and int values ***/
  }

  last_x = x;
  last_y = y;

  /*** Now update live variable and do callback.  We don't want
    to do the callback on each iteration of this function, just on every 
    i^th iteration, where i is given by GLUI_SPINNER_CALLBACK_INTERVAL ****/

  callback_count++;
  if ( (callback_count % GLUI_SPINNER_CALLBACK_INTERVAL ) == 0 )
    do_callbacks();
}
예제 #11
0
ios_base::~ios_base()
{
#ifndef _EWL_TINY_IO
    do_callbacks(erase_event);
#ifndef _EWL_NO_LOCALE
    delete loc_;
#endif
    free(parray_);
    free(iarray_);
    free(cb_vec_);
#endif  // _EWL_TINY_IO
}
예제 #12
0
파일: prefs.c 프로젝트: psunkari/spicebird
void
purple_prefs_trigger_callback(const char *name)
{
	struct purple_pref *pref = find_pref(name);

	if(!pref) {
		purple_debug_error("prefs",
				"purple_prefs_trigger_callback: Unknown pref %s\n", name);
		return;
	}

	do_callbacks(name, pref);
}
예제 #13
0
파일: prefs.c 프로젝트: psunkari/spicebird
void
purple_prefs_set_generic(const char *name, gpointer value)
{
	struct purple_pref *pref = find_pref(name);

	if(!pref) {
		purple_debug_error("prefs",
				"purple_prefs_set_generic: Unknown pref %s\n", name);
		return;
	}

	pref->value.generic = value;
	do_callbacks(name, pref);
}
예제 #14
0
파일: stun.c 프로젝트: CkNoSFeRaTU/pidgin
static void hbn_cb(GSList *hosts, gpointer data, const char *error_message) {

	if(!hosts || !hosts->data) {
		nattype.status = PURPLE_STUN_STATUS_UNDISCOVERED;
		nattype.lookup_time = time(NULL);
		do_callbacks();
		return;
	}

	if (!purple_network_listen_range(12108, 12208, SOCK_DGRAM, hbn_listen_cb, hosts)) {
		while (hosts) {
			hosts = g_slist_delete_link(hosts, hosts);
			g_free(hosts->data);
			hosts = g_slist_delete_link(hosts, hosts);
		}

		nattype.status = PURPLE_STUN_STATUS_UNKNOWN;
		nattype.lookup_time = time(NULL);
		do_callbacks();
		return;
	}


}
예제 #15
0
int    GLUI_Scrollbar::mouse_down_handler( int local_x, int local_y )
{
  last_update_time=GLUI_Time()-1.0;
  this->state = find_arrow( local_x, local_y );
  GLUI_Master.glui_setIdleFuncIfNecessary();

  /*  printf( "spinner: mouse down  : %d/%d   arrow:%d\n", local_x, local_y,
      find_arrow( local_x, local_y ));
      */

  if ( state != GLUI_SCROLL_STATE_UP AND state != GLUI_SCROLL_STATE_DOWN)
    return true;

  reset_growth();

  /*** ints and floats behave a bit differently.  When you click on
    an int spinner, you expect the value to immediately go up by 1, whereas
    for a float it'll go up only by a fractional amount.  Therefore, we
    go ahead and increment by one for int spinners ***/
#if 1
  if ( data_type == GLUI_SCROLL_INT ) {
    // Allow for possibility of reversed limits
    int lo = std::min(int_min,int_max);
    int hi = std::max(int_min,int_max);
    int increase = int_min < int_max ? 1 : -1;
    int new_val = int_val;
    if ( state == GLUI_SCROLL_STATE_UP ) {
      new_val += increase;
    } else if ( state == GLUI_SCROLL_STATE_DOWN ) {
      new_val -= increase;
    }
    if (new_val >= lo && new_val <= hi && new_val!=int_val) {
      set_int_val(new_val);
      do_callbacks();
    }
  }
#endif
  do_click();
  redraw();

  return false;
}
예제 #16
0
파일: prefs.c 프로젝트: psunkari/spicebird
void
purple_prefs_set_bool(const char *name, gboolean value)
{
	struct purple_pref *pref = find_pref(name);

	if(pref) {
		if(pref->type != PURPLE_PREF_BOOLEAN) {
			purple_debug_error("prefs",
					"purple_prefs_set_bool: %s not a boolean pref\n", name);
			return;
		}

		if(pref->value.boolean != value) {
			pref->value.boolean = value;
			do_callbacks(name, pref);
		}
	} else {
		purple_prefs_add_bool(name, value);
	}
}
예제 #17
0
파일: prefs.c 프로젝트: psunkari/spicebird
void
purple_prefs_set_int(const char *name, int value)
{
	struct purple_pref *pref = find_pref(name);

	if(pref) {
		if(pref->type != PURPLE_PREF_INT) {
			purple_debug_error("prefs",
					"purple_prefs_set_int: %s not an integer pref\n", name);
			return;
		}

		if(pref->value.integer != value) {
			pref->value.integer = value;
			do_callbacks(name, pref);
		}
	} else {
		purple_prefs_add_int(name, value);
	}
}
예제 #18
0
파일: prefs.c 프로젝트: psunkari/spicebird
void
purple_prefs_set_path(const char *name, const char *value)
{
	struct purple_pref *pref = find_pref(name);

	if(pref) {
		if(pref->type != PURPLE_PREF_PATH) {
			purple_debug_error("prefs",
					"purple_prefs_set_path: %s not a path pref\n", name);
			return;
		}

		if (!purple_strequal(pref->value.string, value)) {
			g_free(pref->value.string);
			pref->value.string = g_strdup(value);
			do_callbacks(name, pref);
		}
	} else {
		purple_prefs_add_path(name, value);
	}
}
예제 #19
0
파일: stun.c 프로젝트: CkNoSFeRaTU/pidgin
static void reply_cb(gpointer data, gint source, PurpleInputCondition cond) {
	struct stun_conn *sc = data;
	char buffer[65536];
	char *tmp;
	gssize len;
	struct in_addr in;
	struct stun_attrib *attrib;
	struct stun_header *hdr;
	struct ifconf ifc;
	struct ifreq *ifr;
	struct sockaddr_in *sinptr;

	memset(&in, 0, sizeof(in));

	len = recv(source, buffer, sizeof(buffer) - 1, 0);
	if (len < 0) {
		purple_debug_warning("stun", "unable to read stun response\n");
		return;
	}
	buffer[len] = '\0';

	if ((gsize)len < sizeof(struct stun_header)) {
		purple_debug_warning("stun", "got invalid response\n");
		return;
	}

	hdr = (struct stun_header*) buffer;
	if ((gsize)len != (ntohs(hdr->len) + sizeof(struct stun_header))) {
		purple_debug_warning("stun", "got incomplete response\n");
		return;
	}

	/* wrong transaction */
	if(hdr->transid[0] != sc->packet->transid[0]
			|| hdr->transid[1] != sc->packet->transid[1]
			|| hdr->transid[2] != sc->packet->transid[2]
			|| hdr->transid[3] != sc->packet->transid[3]) {
		purple_debug_warning("stun", "got wrong transid\n");
		return;
	}

	if(sc->test==1) {
		if (hdr->type != MSGTYPE_BINDINGRESPONSE) {
			purple_debug_warning("stun",
				"Expected Binding Response, got %d\n",
				hdr->type);
			return;
		}

		tmp = buffer + sizeof(struct stun_header);
		while((buffer + len) > (tmp + sizeof(struct stun_attrib))) {
			attrib = (struct stun_attrib*) tmp;
			tmp += sizeof(struct stun_attrib);

			if (!((buffer + len) > (tmp + ntohs(attrib->len))))
				break;

			if(attrib->type == htons(ATTRIB_MAPPEDADDRESS)
					&& ntohs(attrib->len) == 8) {
				char *ip;
				/* Skip the first unused byte,
				 * the family(1 byte), and the port(2 bytes);
				 * then read the 4 byte IPv4 address */
				memcpy(&in.s_addr, tmp + 4, 4);
				ip = inet_ntoa(in);
				if(ip)
					g_strlcpy(nattype.publicip, ip, sizeof(nattype.publicip));
			}

			tmp += ntohs(attrib->len);
		}
		purple_debug_info("stun", "got public ip %s\n", nattype.publicip);
		nattype.status = PURPLE_STUN_STATUS_DISCOVERED;
		nattype.type = PURPLE_STUN_NAT_TYPE_UNKNOWN_NAT;
		nattype.lookup_time = time(NULL);

		/* is it a NAT? */

		ifc.ifc_len = sizeof(buffer);
		ifc.ifc_req = (struct ifreq *) buffer;
		ioctl(source, SIOCGIFCONF, &ifc);

		tmp = buffer;
		while(tmp < buffer + ifc.ifc_len) {
			ifr = (struct ifreq *) tmp;

			tmp += sizeof(struct ifreq);

			if(ifr->ifr_addr.sa_family == AF_INET) {
				/* we only care about ipv4 interfaces */
				sinptr = (struct sockaddr_in *) &ifr->ifr_addr;
				if(sinptr->sin_addr.s_addr == in.s_addr) {
					/* no NAT */
					purple_debug_info("stun", "no nat\n");
					nattype.type = PURPLE_STUN_NAT_TYPE_PUBLIC_IP;
				}
			}
		}

#ifndef NOTYET
		close_stun_conn(sc);
		do_callbacks();
#else
		purple_timeout_remove(sc->timeout);
		sc->timeout = 0;

		do_test2(sc);
	} else if(sc->test == 2) {
		close_stun_conn(sc);
		nattype.type = PURPLE_STUN_NAT_TYPE_FULL_CONE;
		do_callbacks();
#endif
	}
}