Implement SVC remove. Rely on terminate for SVC cleanup.

This commit is contained in:
Michael Jumper 2014-03-02 11:24:06 -08:00
parent 2d885fdec2
commit 38e4c9afba
4 changed files with 46 additions and 14 deletions

View File

@ -68,8 +68,6 @@ int __guac_rdp_send_keysym(guac_client* client, int keysym, int pressed);
int rdp_guac_client_free_handler(guac_client* client) { int rdp_guac_client_free_handler(guac_client* client) {
guac_common_list_element* current;
rdp_guac_client_data* guac_client_data = rdp_guac_client_data* guac_client_data =
(rdp_guac_client_data*) client->data; (rdp_guac_client_data*) client->data;
@ -88,18 +86,7 @@ int rdp_guac_client_free_handler(guac_client* client) {
if (guac_client_data->filesystem != NULL) if (guac_client_data->filesystem != NULL)
guac_rdp_fs_free(guac_client_data->filesystem); guac_rdp_fs_free(guac_client_data->filesystem);
/* Free any allocated SVCs */ /* Free SVC list */
current = guac_client_data->available_svc->head;
while (current != NULL) {
guac_common_list_element* next = current->next;
guac_rdp_free_svc((guac_rdp_svc*) current->data);
guac_common_list_remove(guac_client_data->available_svc, current);
current = next;
}
guac_common_list_free(guac_client_data->available_svc); guac_common_list_free(guac_client_data->available_svc);
/* Free client data */ /* Free client data */

View File

@ -106,7 +106,18 @@ void guac_svc_process_connect(rdpSvcPlugin* plugin) {
} }
void guac_svc_process_terminate(rdpSvcPlugin* plugin) { void guac_svc_process_terminate(rdpSvcPlugin* plugin) {
/* Get corresponding guac_rdp_svc */
guac_svcPlugin* svc_plugin = (guac_svcPlugin*) plugin;
guac_rdp_svc* svc = svc_plugin->svc;
/* Remove and free SVC */
guac_client_log_info(svc->client, "Closing channel \"%s\"...", svc->name);
guac_rdp_remove_svc(svc->client, svc->name);
free(svc);
free(plugin); free(plugin);
} }
void guac_svc_process_event(rdpSvcPlugin* plugin, wMessage* event) { void guac_svc_process_event(rdpSvcPlugin* plugin, wMessage* event) {

View File

@ -90,3 +90,32 @@ guac_rdp_svc* guac_rdp_get_svc(guac_client* client, const char* name) {
} }
guac_rdp_svc* guac_rdp_remove_svc(guac_client* client, const char* name) {
rdp_guac_client_data* client_data = (rdp_guac_client_data*) client->data;
guac_common_list_element* current;
guac_rdp_svc* found = NULL;
/* For each available SVC */
guac_common_list_lock(client_data->available_svc);
current = client_data->available_svc->head;
while (current != NULL) {
/* If name matches, remove entry */
guac_rdp_svc* current_svc = (guac_rdp_svc*) current->data;
if (strcmp(current_svc->name, name) == 0) {
guac_common_list_remove(client_data->available_svc, current);
found = current_svc;
break;
}
current = current->next;
}
guac_common_list_unlock(client_data->available_svc);
/* Return removed entry, if any */
return found;
}

View File

@ -84,5 +84,10 @@ void guac_rdp_add_svc(guac_client* client, guac_rdp_svc* svc);
*/ */
guac_rdp_svc* guac_rdp_get_svc(guac_client* client, const char* name); guac_rdp_svc* guac_rdp_get_svc(guac_client* client, const char* name);
/**
* Remove the SVC with the given name from the list stored in the client.
*/
guac_rdp_svc* guac_rdp_remove_svc(guac_client* client, const char* name);
#endif #endif