Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Philippe Auphelle 2012-02-27 15:47:56 +01:00
commit 7d535dfff7
6 changed files with 187 additions and 39 deletions

View File

@ -450,6 +450,17 @@ int _xf_error_handler(Display* d, XErrorEvent* ev)
return xf_error_handler(d, ev);
}
/**
* Callback given to freerdp_connect() to process the pre-connect operations.
* It will parse the command line parameters given to xfreerdp (using freerdp_parse_args())
* and fill the rdp_freerdp structure (instance) with the appropriate options to use for the connection.
*
* @param instance - pointer to the rdp_freerdp structure that contains the connection's parameters, and will
* be filled with the appropriate informations.
*
* @return true if successful. false otherwise.
* Can exit with error code XF_EXIT_PARSE_ARGUMENTS if there is an error in the parameters.
*/
boolean xf_pre_connect(freerdp* instance)
{
xfInfo* xfi;
@ -608,6 +619,11 @@ uint32 xf_detect_cpu()
return cpu_opt;
}
/**
* Callback given to freerdp_connect() to perform post-connection operations.
* It will be called only if the connection was initialized properly, and will continue the initialization based on the
* newly created connection.
*/
boolean xf_post_connect(freerdp* instance)
{
xfInfo* xfi;
@ -728,8 +744,22 @@ boolean xf_post_connect(freerdp* instance)
return true;
}
/** Callback set in the rdp_freerdp structure, and used to get the user's password,
* if required to establish the connection.
* This function is actually called in credssp_ntlmssp_client_init()
* @see rdp_server_accept_nego() and rdp_check_fds()
* @param instance - pointer to the rdp_freerdp structure that contains the connection settings
* @param username - unused
* @param password - on return: pointer to a character string that will be filled by the password entered by the user.
* Note that this character string will be allocated inside the function, and needs to be deallocated by the caller
* using xfree(), even in case this function fails.
* @param domain - unused
* @return true if a password was successfully entered. See freerdp_passphrase_read() for more details.
*/
boolean xf_authenticate(freerdp* instance, char** username, char** password, char** domain)
{
// FIXME: seems this callback may be called when 'username' is not known.
// But it doesn't do anything to fix it...
*password = xmalloc(password_size * sizeof(char));
if (freerdp_passphrase_read("Password: ", *password, password_size) == NULL)
@ -738,6 +768,16 @@ boolean xf_authenticate(freerdp* instance, char** username, char** password, cha
return true;
}
/** Callback set in the rdp_freerdp structure, and used to make a certificate validation
* when the connection requires it.
* This function will actually be called by tls_verify_certificate().
* @see rdp_client_connect() and tls_connect()
* @param instance - pointer to the rdp_freerdp structure that contains the connection settings
* @param subject
* @param issuer
* @param fingerprint
* @return true if the certificate is trusted. false otherwise.
*/
boolean xf_verify_certificate(freerdp* instance, char* subject, char* issuer, char* fingerprint)
{
char answer;
@ -769,6 +809,19 @@ boolean xf_verify_certificate(freerdp* instance, char* subject, char* issuer, ch
return false;
}
/** Used to parse xfreerdp-specific commandline parameters.
* This function is provided as a parameter to freerdp_parse_args(), that will call it
* each time a parameter is not recognized by the library.
* @see xf_pre_connect(), where freerdp_parse_args() is called.
*
* @param settings
* @param opt
* @param val
* @param user_data
* @return the number of parameters that where taken into account.
* 0 means no options recognized.
* freerdp_parse_args() will use this number to move forward in the parameters parsing.
*/
int xf_process_client_args(rdpSettings* settings, const char* opt, const char* val, void* user_data)
{
int argc = 0;
@ -825,13 +878,28 @@ int xf_process_client_args(rdpSettings* settings, const char* opt, const char* v
return argc;
}
/** Used to load plugins based on the commandline parameters.
* This function is provided as a parameter to freerdp_parse_args(), that will call it
* each time a plugin name is found on the command line.
* This function just calls freerdp_channels_load_plugin() for the given plugin, and always returns 1.
* @see xf_pre_connect(), where freerdp_parse_args() is called.
*
* @param settings
* @param name
* @param plugin_data
* @param user_data
* @return 1
*/
int xf_process_plugin_args(rdpSettings* settings, const char* name, RDP_PLUGIN_DATA* plugin_data, void* user_data)
{
rdpChannels* channels = (rdpChannels*) user_data;
printf("loading plugin %s\n", name);
freerdp_channels_load_plugin(channels, settings, name, plugin_data);
// FIXME we should check the return code for freerdp_channels_load_plugin()
// and report any error to the caller. freerdp_parse_args() actually expect to get
// an error code when there is a loading error.
// Is it as easy as "return freerdp_channels_load_plugin()" ?
return 1;
}
@ -940,6 +1008,13 @@ void xf_free(xfInfo* xfi)
xfree(xfi);
}
/** Main loop for the rdp connection.
* It will be run from the thread's entry point (thread_func()).
* It initiates the connection, and will continue to run until the session ends,
* processing events as they are received.
* @param instance - pointer to the rdp_freerdp structure that contains the session's settings
* @return A code from the enum XF_EXIT_CODE (0 if successfull)
*/
int xfreerdp_run(freerdp* instance)
{
int i;
@ -1061,6 +1136,10 @@ int xfreerdp_run(freerdp* instance)
return ret;
}
/** Entry point for the thread that will deal with the session.
* It just calls xfreerdp_run() using the given instance as parameter.
* @param - pointer to a thread_data structure that contains the initialized connection.
*/
void* thread_func(void* param)
{
struct thread_data* data;

View File

@ -74,9 +74,15 @@ struct rdp_context
uint32 paddingC[64 - 38]; /* 38 */
};
/** Defines the options for a given instance of RDP connection.
* This is built by the client and given to the FreeRDP library to create the connection
* with the expected options.
*/
struct rdp_freerdp
{
rdpContext* context; /* 0 */
rdpContext* context; /**< (offset 0)
Pointer to a rdpContext structure.
Can be initialized by a call to freerdp_context_new() */
uint32 paddingA[16 - 1]; /* 1 */
rdpInput* input; /* 16 */
@ -85,14 +91,34 @@ struct rdp_freerdp
uint32 paddingB[32 - 19]; /* 19 */
size_t context_size; /* 32 */
pContextNew ContextNew; /* 33 */
pContextFree ContextFree; /* 34 */
pContextNew ContextNew; /**< (offset 33)
Callback for context allocation
Can be set before calling freerdp_context_new() to have it executed after allocation and initialization.
Must be set to NULL if not needed. */
pContextFree ContextFree; /**< (offset 34)
Callback for context deallocation
Can be set before calling freerdp_context_free() to have it executed before deallocation.
Must be set to NULL if not needed. */
uint32 paddingC[48 - 35]; /* 35 */
pPreConnect PreConnect; /* 48 */
pPostConnect PostConnect; /* 49 */
pAuthenticate Authenticate; /* 50 */
pVerifyCertificate VerifyCertificate; /* 51 */
pPreConnect PreConnect; /**< (offset 48)
Callback for pre-connect operations.
Can be set before calling freerdp_connect() to have it executed before the actual connection happens.
Must be set to NULL if not needed. */
pPostConnect PostConnect; /**< (offset 49)
Callback for post-connect operations.
Can be set before calling freerdp_connect() to have it executed after the actual connection has succeeded.
Must be set to NULL if not needed. */
pAuthenticate Authenticate; /**< (offset 50)
Callback for authentication.
It is used to get the username/password when it was not provided at connection time. */
pVerifyCertificate VerifyCertificate; /**< (offset 51)
Callback for certificate validation.
Used to verify that an unknown certificate is trusted. */
uint32 paddingD[64 - 52]; /* 52 */
pSendChannelData SendChannelData; /* 64 */

View File

@ -1,4 +1,4 @@
/**
/*
* FreeRDP: A Remote Desktop Protocol Client
* Connection Sequence
*
@ -23,39 +23,40 @@
#include "connection.h"
/**
* Connection Sequence
* client server
* | |
* |-----------------------X.224 Connection Request PDU--------------------->|
* |<----------------------X.224 Connection Confirm PDU----------------------|
* |-------MCS Connect-Initial PDU with GCC Conference Create Request------->|
* |<-----MCS Connect-Response PDU with GCC Conference Create Response-------|
* |------------------------MCS Erect Domain Request PDU-------------------->|
* |------------------------MCS Attach User Request PDU--------------------->|
* |<-----------------------MCS Attach User Confirm PDU----------------------|
* |------------------------MCS Channel Join Request PDU-------------------->|
* |<-----------------------MCS Channel Join Confirm PDU---------------------|
* |----------------------------Security Exchange PDU----------------------->|
* |-------------------------------Client Info PDU-------------------------->|
* |<---------------------License Error PDU - Valid Client-------------------|
* |<-----------------------------Demand Active PDU--------------------------|
* |------------------------------Confirm Active PDU------------------------>|
* |-------------------------------Synchronize PDU-------------------------->|
* |---------------------------Control PDU - Cooperate---------------------->|
* |------------------------Control PDU - Request Control------------------->|
* |--------------------------Persistent Key List PDU(s)-------------------->|
* |--------------------------------Font List PDU--------------------------->|
* |<------------------------------Synchronize PDU---------------------------|
* |<--------------------------Control PDU - Cooperate-----------------------|
* |<-----------------------Control PDU - Granted Control--------------------|
* |<-------------------------------Font Map PDU-----------------------------|
* Connection Sequence\n
* client server\n
* | |\n
* |-----------------------X.224 Connection Request PDU--------------------->|\n
* |<----------------------X.224 Connection Confirm PDU----------------------|\n
* |-------MCS Connect-Initial PDU with GCC Conference Create Request------->|\n
* |<-----MCS Connect-Response PDU with GCC Conference Create Response-------|\n
* |------------------------MCS Erect Domain Request PDU-------------------->|\n
* |------------------------MCS Attach User Request PDU--------------------->|\n
* |<-----------------------MCS Attach User Confirm PDU----------------------|\n
* |------------------------MCS Channel Join Request PDU-------------------->|\n
* |<-----------------------MCS Channel Join Confirm PDU---------------------|\n
* |----------------------------Security Exchange PDU----------------------->|\n
* |-------------------------------Client Info PDU-------------------------->|\n
* |<---------------------License Error PDU - Valid Client-------------------|\n
* |<-----------------------------Demand Active PDU--------------------------|\n
* |------------------------------Confirm Active PDU------------------------>|\n
* |-------------------------------Synchronize PDU-------------------------->|\n
* |---------------------------Control PDU - Cooperate---------------------->|\n
* |------------------------Control PDU - Request Control------------------->|\n
* |--------------------------Persistent Key List PDU(s)-------------------->|\n
* |--------------------------------Font List PDU--------------------------->|\n
* |<------------------------------Synchronize PDU---------------------------|\n
* |<--------------------------Control PDU - Cooperate-----------------------|\n
* |<-----------------------Control PDU - Granted Control--------------------|\n
* |<-------------------------------Font Map PDU-----------------------------|\n
*
*/
/**
* Establish RDP Connection.\n
* Establish RDP Connection based on the settings given in the 'rdp' paremeter.
* @msdn{cc240452}
* @param rdp RDP module
* @return true if the connection succeeded. false otherwise.
*/
boolean rdp_client_connect(rdpRdp* rdp)

View File

@ -166,7 +166,10 @@ static int extension_uninit_plugins(rdpExtension* extension)
return 0;
}
/** Gets through all registered pre-connect hooks and executes them.
* @param extension - pointer to a rdpExtension structure
* @return 0 always
*/
int extension_pre_connect(rdpExtension* extension)
{
int i;
@ -177,6 +180,10 @@ int extension_pre_connect(rdpExtension* extension)
return 0;
}
/** Gets through all registered post-connect hooks and executes them.
* @param extension - pointer to a rdpExtension structure
* @return 0 always
*/
int extension_post_connect(rdpExtension* ext)
{
int i;

View File

@ -1,4 +1,4 @@
/**
/*
* FreeRDP: A Remote Desktop Protocol Client
* FreeRDP Core
*
@ -28,6 +28,17 @@
#include <freerdp/freerdp.h>
#include <freerdp/utils/memory.h>
/** Creates a new connection based on the settings found in the "instance" parameter
* It will use the callbacks registered on the structure to process the pre/post connect operations
* that the caller requires.
* @see struct rdp_freerdp in freerdp.h
*
* @param instance - pointer to a rdp_freerdp structure that contains base information to establish the connection.
* On return, this function will be initialized with the new connection's settings.
*
* @return true if successful. false otherwise.
*
*/
boolean freerdp_connect(freerdp* instance)
{
rdpRdp* rdp;
@ -160,11 +171,20 @@ void freerdp_get_version(int* major, int* minor, int* revision)
*revision = FREERDP_VERSION_REVISION;
}
/** Allocator function for a rdp context.
* The function will allocate a rdpRdp structure using rdp_new(), then copy
* its contents to the appropriate fields in the rdp_freerdp structure given in parameters.
* If the caller has set the ContextNew callback in the 'instance' parameter, it will be called at the end of the function.
*
* @param instance - Pointer to the rdp_freerdp structure that will be initialized with the new context.
*/
void freerdp_context_new(freerdp* instance)
{
rdpRdp* rdp;
rdp = rdp_new(instance);
// FIXME - we're not checking where rdp_new returns NULL, and have no way to report an error to the caller
instance->input = rdp->input;
instance->update = rdp->update;
instance->settings = rdp->settings;
@ -185,6 +205,14 @@ void freerdp_context_new(freerdp* instance)
IFCALL(instance->ContextNew, instance, instance->context);
}
/** Deallocator function for a rdp context.
* The function will deallocate the resources from the 'instance' parameter that were allocated from a call
* to freerdp_context_new().
* If the ContextFree callback is set in the 'instance' parameter, it will be called before deallocation occurs.
*
* @param instance - Pointer to the rdp_freerdp structure that was initialized by a call to freerdp_context_new().
* On return, the fields associated to the context are invalid.
*/
void freerdp_context_free(freerdp* instance)
{
if (instance->context == NULL)
@ -204,6 +232,9 @@ uint32 freerdp_error_info(freerdp* instance)
return instance->context->rdp->errorInfo;
}
/** Allocator function for the rdp_freerdp structure.
* @return an allocated structure filled with 0s. Need to be deallocated using freerdp_free()
*/
freerdp* freerdp_new()
{
freerdp* instance;
@ -219,6 +250,10 @@ freerdp* freerdp_new()
return instance;
}
/** Deallocator function for the rdp_freerdp structure.
* @param instance - pointer to the rdp_freerdp structure to deallocate.
* On return, this pointer is not valid anymore.
*/
void freerdp_free(freerdp* instance)
{
if (instance)

View File

@ -1,4 +1,4 @@
/**
/*
* FreeRDP: A Remote Desktop Protocol client.
* Arguments Parsing
*