static gboolean fire_port_mapping_failure_cb(gpointer data) { UPnPMappingAddRemove *ar = data; ar->tima = 0; do_port_mapping_cb(FALSE, data); return FALSE; }
UPnPMappingAddRemove * purple_upnp_set_port_mapping(unsigned short portmap, const gchar* protocol, PurpleUPnPCallback cb, gpointer cb_data) { UPnPMappingAddRemove *ar; ar = g_new0(UPnPMappingAddRemove, 1); ar->cb = cb; ar->cb_data = cb_data; ar->add = TRUE; ar->portmap = portmap; strncpy(ar->protocol, protocol, sizeof(ar->protocol)); /* If we're waiting for a discovery, add to the callbacks list */ if(control_info.status == PURPLE_UPNP_STATUS_DISCOVERING) { /* TODO: This will fail because when this cb is triggered, * the internal IP lookup won't be complete */ discovery_callbacks = g_slist_append( discovery_callbacks, do_port_mapping_cb); discovery_callbacks = g_slist_append( discovery_callbacks, ar); return ar; } /* If we haven't had a successful UPnP discovery, check if 5 minutes has * elapsed since the last try, try again */ if(control_info.status == PURPLE_UPNP_STATUS_UNDISCOVERED || (control_info.status == PURPLE_UPNP_STATUS_UNABLE_TO_DISCOVER && (time(NULL) - control_info.lookup_time) > 300)) { purple_upnp_discover(do_port_mapping_cb, ar); return ar; } else if(control_info.status == PURPLE_UPNP_STATUS_UNABLE_TO_DISCOVER) { if (cb) { /* Asynchronously trigger a failed response */ ar->tima = purple_timeout_add(10, fire_port_mapping_failure_cb, ar); } else { /* No need to do anything if nobody expects a response*/ g_free(ar); ar = NULL; } return ar; } do_port_mapping_cb(TRUE, ar); return ar; }
static gboolean fire_port_mapping_failure_cb(gpointer data) { do_port_mapping_cb(FALSE, data); return FALSE; }