comparison src/protocols/simple/simple.c @ 12730:d5b8f4dc1622

[gaim-migrate @ 15074] Update gaim_network_listen*() to have the socket type specified. This allows us to use the same functionality to listen on UDP sockets too. There are probably a couple things that should be updated to use this. I also updated SIMPLE to allow the connect port to be specified in the account options. committer: Tailor Script <tailor@pidgin.im>
author Daniel Atallah <daniel.atallah@gmail.com>
date Thu, 05 Jan 2006 05:04:07 +0000
parents e893563d965d
children 2b61e6ed85c3
comparison
equal deleted inserted replaced
12729:d3232d64fafd 12730:d5b8f4dc1622
1196 1196
1197 static void srvresolved(GaimSrvResponse *resp, int results, gpointer data) { 1197 static void srvresolved(GaimSrvResponse *resp, int results, gpointer data) {
1198 struct simple_account_data *sip = (struct simple_account_data*) data; 1198 struct simple_account_data *sip = (struct simple_account_data*) data;
1199 1199
1200 gchar *hostname; 1200 gchar *hostname;
1201 int port = 5060; 1201 int port = gaim_account_get_int(sip->account, "port", 0);
1202 1202
1203 int error = 0; 1203 int error = 0;
1204 struct sockaddr_in addr;
1205 struct hostent *h; 1204 struct hostent *h;
1206 1205
1207 /* find the host to connect to */ 1206 /* find the host to connect to */
1208 if(results) { 1207 if(results) {
1209 hostname = g_strdup(resp->hostname); 1208 hostname = g_strdup(resp->hostname);
1209 /* TODO: Should this work more like Jabber where the SRV value will be ignored
1210 * if there is one manually specified? */
1210 port = resp->port; 1211 port = resp->port;
1211 g_free(resp); 1212 g_free(resp);
1212 } else { 1213 } else {
1213 if(!gaim_account_get_bool(sip->account, "useproxy", FALSE)) { 1214 if(!gaim_account_get_bool(sip->account, "useproxy", FALSE)) {
1214 hostname = g_strdup(sip->servername); 1215 hostname = g_strdup(sip->servername);
1220 sip->realhostname = hostname; 1221 sip->realhostname = hostname;
1221 sip->realport = port; 1222 sip->realport = port;
1222 /* TCP case */ 1223 /* TCP case */
1223 if(! sip->udp) { 1224 if(! sip->udp) {
1224 /* create socket for incoming connections */ 1225 /* create socket for incoming connections */
1225 sip->listenfd = gaim_network_listen_range(5060, 5160); 1226 sip->listenfd = gaim_network_listen_range(5060, 5160, SOCK_STREAM);
1226 if(sip->listenfd == -1) { 1227 if(sip->listenfd == -1) {
1227 gaim_connection_error(sip->gc, _("Could not create listen socket")); 1228 gaim_connection_error(sip->gc, _("Could not create listen socket"));
1228 return; 1229 return;
1229 } 1230 }
1230 gaim_debug_info("simple", "listenfd: %d\n", sip->listenfd); 1231 gaim_debug_info("simple", "listenfd: %d\n", sip->listenfd);
1244 if (!(h = gethostbyname(hostname))) { 1245 if (!(h = gethostbyname(hostname))) {
1245 gaim_connection_error(sip->gc, _("Couldn't resolve host")); 1246 gaim_connection_error(sip->gc, _("Couldn't resolve host"));
1246 return; 1247 return;
1247 } 1248 }
1248 1249
1249 sip->fd = socket(AF_INET, SOCK_DGRAM, 0); 1250 /* create socket for incoming connections */
1250 1251 sip->fd = gaim_network_listen_range(5060, 5160, SOCK_DGRAM);
1251 addr.sin_family = AF_INET; 1252
1252 addr.sin_port = htons(5060); 1253 if(sip->fd == -1) {
1253 addr.sin_addr.s_addr = INADDR_ANY; 1254 gaim_connection_error(sip->gc, _("Could not create listen socket"));
1254 while((bind(sip->fd, (struct sockaddr*)&addr, sizeof(struct sockaddr_in)) <0) && ntohs(addr.sin_port)<5160) { 1255 return;
1255 addr.sin_port = htons(ntohs(addr.sin_port)+1); 1256 }
1256 } 1257
1257 sip->listenport = ntohs(addr.sin_port);
1258 sip->listenfd = sip->fd; 1258 sip->listenfd = sip->fd;
1259 1259
1260 sip->listenpa = gaim_input_add(sip->fd, GAIM_INPUT_READ, simple_udp_process, sip->gc); 1260 sip->listenpa = gaim_input_add(sip->fd, GAIM_INPUT_READ, simple_udp_process, sip->gc);
1261 sip->serveraddr.sin_family = AF_INET; 1261 sip->serveraddr.sin_family = AF_INET;
1262 sip->serveraddr.sin_port = htons(port); 1262 sip->serveraddr.sin_port = htons(port);
1459 prpl_info.user_splits = g_list_append(prpl_info.user_splits, split); 1459 prpl_info.user_splits = g_list_append(prpl_info.user_splits, split);
1460 1460
1461 option = gaim_account_option_bool_new(_("Publish status (note: everyone may watch you)"), "dopublish", TRUE); 1461 option = gaim_account_option_bool_new(_("Publish status (note: everyone may watch you)"), "dopublish", TRUE);
1462 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); 1462 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
1463 1463
1464 option = gaim_account_option_int_new(_("Connect port"), "port", 5060);
1465 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
1466
1467
1464 option = gaim_account_option_bool_new(_("Use UDP"), "udp", FALSE); 1468 option = gaim_account_option_bool_new(_("Use UDP"), "udp", FALSE);
1465 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); 1469 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
1466 option = gaim_account_option_bool_new(_("Use proxy"), "useproxy", FALSE); 1470 option = gaim_account_option_bool_new(_("Use proxy"), "useproxy", FALSE);
1467 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); 1471 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
1468 option = gaim_account_option_string_new(_("Proxy"), "proxy", ""); 1472 option = gaim_account_option_string_new(_("Proxy"), "proxy", "");