~paulliu/ubuntu/precise/freerdp/fixext

« back to all changes in this revision

Viewing changes to channels/drdynvc/dvcman.c

  • Committer: Package Import Robot
  • Author(s): Otavio Salvador
  • Date: 2012-02-11 10:34:05 UTC
  • mfrom: (1.2.2)
  • mto: This revision was merged to the branch mainline in revision 13.
  • Revision ID: package-import@ubuntu.com-20120211103405-x2wgdb6x8plb7cdk
Tags: upstream-1.0.1
ImportĀ upstreamĀ versionĀ 1.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
80
80
        STREAM* dvc_data;
81
81
};
82
82
 
83
 
static int dvcman_get_configuration(IWTSListener* pListener,
84
 
        void** ppPropertyBag)
 
83
static int dvcman_get_configuration(IWTSListener* pListener, void** ppPropertyBag)
85
84
{
86
85
        *ppPropertyBag = NULL;
87
86
        return 1;
88
87
}
89
88
 
90
89
static int dvcman_create_listener(IWTSVirtualChannelManager* pChannelMgr,
91
 
        const char* pszChannelName,
92
 
        uint32 ulFlags,
93
 
        IWTSListenerCallback* pListenerCallback,
94
 
        IWTSListener** ppListener)
 
90
        const char* pszChannelName, uint32 ulFlags,
 
91
        IWTSListenerCallback* pListenerCallback, IWTSListener** ppListener)
95
92
{
96
93
        DVCMAN* dvcman = (DVCMAN*)pChannelMgr;
97
94
        DVCMAN_LISTENER* listener;
118
115
        }
119
116
}
120
117
 
121
 
static int dvcman_push_event(IWTSVirtualChannelManager* pChannelMgr,
122
 
        RDP_EVENT* pEvent)
 
118
static int dvcman_push_event(IWTSVirtualChannelManager* pChannelMgr, RDP_EVENT* pEvent)
123
119
{
124
 
        DVCMAN* dvcman = (DVCMAN*)pChannelMgr;
125
120
        int error;
 
121
        DVCMAN* dvcman = (DVCMAN*) pChannelMgr;
126
122
 
127
123
        error = drdynvc_push_event(dvcman->drdynvc, pEvent);
 
124
 
128
125
        if (error == 0)
129
126
        {
130
127
                DEBUG_DVC("event_type %d pushed.", pEvent->event_type);
133
130
        {
134
131
                DEBUG_WARN("event_type %d push failed.", pEvent->event_type);
135
132
        }
 
133
 
136
134
        return error;
137
135
}
138
136
 
139
 
static int dvcman_register_plugin(IDRDYNVC_ENTRY_POINTS* pEntryPoints,
140
 
        const char* name, IWTSPlugin* pPlugin)
 
137
static int dvcman_register_plugin(IDRDYNVC_ENTRY_POINTS* pEntryPoints, const char* name, IWTSPlugin* pPlugin)
141
138
{
142
 
        DVCMAN* dvcman = ((DVCMAN_ENTRY_POINTS*)pEntryPoints)->dvcman;
 
139
        DVCMAN* dvcman = ((DVCMAN_ENTRY_POINTS*) pEntryPoints)->dvcman;
143
140
 
144
141
        if (dvcman->num_plugins < MAX_PLUGINS)
145
142
        {
155
152
        }
156
153
}
157
154
 
158
 
IWTSPlugin* dvcman_get_plugin(IDRDYNVC_ENTRY_POINTS* pEntryPoints,
159
 
        const char* name)
 
155
IWTSPlugin* dvcman_get_plugin(IDRDYNVC_ENTRY_POINTS* pEntryPoints, const char* name)
160
156
{
161
 
        DVCMAN* dvcman = ((DVCMAN_ENTRY_POINTS*)pEntryPoints)->dvcman;
162
157
        int i;
 
158
        DVCMAN* dvcman = ((DVCMAN_ENTRY_POINTS*) pEntryPoints)->dvcman;
163
159
 
164
160
        for (i = 0; i < dvcman->num_plugins; i++)
165
161
        {
169
165
                        return dvcman->plugins[i];
170
166
                }
171
167
        }
 
168
 
172
169
        return NULL;
173
170
}
174
171
 
175
172
RDP_PLUGIN_DATA* dvcman_get_plugin_data(IDRDYNVC_ENTRY_POINTS* pEntryPoints)
176
173
{
177
 
        return ((DVCMAN_ENTRY_POINTS*)pEntryPoints)->plugin_data;
 
174
        return ((DVCMAN_ENTRY_POINTS*) pEntryPoints)->plugin_data;
178
175
}
179
176
 
180
177
IWTSVirtualChannelManager* dvcman_new(drdynvcPlugin* plugin)
187
184
        dvcman->drdynvc = plugin;
188
185
        dvcman->channels = list_new();
189
186
 
190
 
        return (IWTSVirtualChannelManager*)dvcman;
 
187
        return (IWTSVirtualChannelManager*) dvcman;
191
188
}
192
189
 
193
190
int dvcman_load_plugin(IWTSVirtualChannelManager* pChannelMgr, RDP_PLUGIN_DATA* data)
197
194
 
198
195
        while (data && data->size > 0)
199
196
        {
200
 
                pDVCPluginEntry = freerdp_load_plugin((char*)data->data[0], "DVCPluginEntry");
 
197
                pDVCPluginEntry = freerdp_load_plugin((char*) data->data[0], "DVCPluginEntry");
201
198
 
202
199
                if (pDVCPluginEntry != NULL)
203
200
                {
204
201
                        entryPoints.iface.RegisterPlugin = dvcman_register_plugin;
205
202
                        entryPoints.iface.GetPlugin = dvcman_get_plugin;
206
203
                        entryPoints.iface.GetPluginData = dvcman_get_plugin_data;
207
 
                        entryPoints.dvcman = (DVCMAN*)pChannelMgr;
 
204
                        entryPoints.dvcman = (DVCMAN*) pChannelMgr;
208
205
                        entryPoints.plugin_data = data;
209
 
                        pDVCPluginEntry((IDRDYNVC_ENTRY_POINTS*)&entryPoints);
 
206
                        pDVCPluginEntry((IDRDYNVC_ENTRY_POINTS*) &entryPoints);
210
207
                }
211
208
                
212
 
                data = (RDP_PLUGIN_DATA*)(((void*)data) + data->size);
 
209
                data = (RDP_PLUGIN_DATA*)(((void*) data) + data->size);
213
210
        }
214
211
 
215
212
        return 0;
219
216
{
220
217
        if (channel->channel_callback)
221
218
                channel->channel_callback->OnClose(channel->channel_callback);
 
219
 
222
220
        xfree(channel);
223
221
}
224
222
 
225
223
void dvcman_free(IWTSVirtualChannelManager* pChannelMgr)
226
224
{
227
 
        DVCMAN* dvcman = (DVCMAN*)pChannelMgr;
228
225
        int i;
229
226
        IWTSPlugin* pPlugin;
230
227
        DVCMAN_LISTENER* listener;
231
228
        DVCMAN_CHANNEL* channel;
 
229
        DVCMAN* dvcman = (DVCMAN*) pChannelMgr;
232
230
 
233
 
        while ((channel = (DVCMAN_CHANNEL*)list_dequeue(dvcman->channels)) != NULL)
 
231
        while ((channel = (DVCMAN_CHANNEL*) list_dequeue(dvcman->channels)) != NULL)
234
232
                dvcman_channel_free(channel);
 
233
 
235
234
        list_free(dvcman->channels);
 
235
 
236
236
        for (i = 0; i < dvcman->num_listeners; i++)
237
237
        {
238
 
                listener = (DVCMAN_LISTENER*)dvcman->listeners[i];
 
238
                listener = (DVCMAN_LISTENER*) dvcman->listeners[i];
239
239
                xfree(listener->channel_name);
240
240
                xfree(listener);
241
241
        }
 
242
 
242
243
        for (i = 0; i < dvcman->num_plugins; i++)
243
244
        {
244
245
                pPlugin = dvcman->plugins[i];
 
246
 
245
247
                if (pPlugin->Terminated)
246
248
                        pPlugin->Terminated(pPlugin);
247
249
        }
 
250
 
248
251
        xfree(dvcman);
249
252
}
250
253
 
251
254
int dvcman_init(IWTSVirtualChannelManager* pChannelMgr)
252
255
{
253
 
        DVCMAN* dvcman = (DVCMAN*)pChannelMgr;
254
256
        int i;
255
257
        IWTSPlugin* pPlugin;
 
258
        DVCMAN* dvcman = (DVCMAN*) pChannelMgr;
256
259
 
257
260
        for (i = 0; i < dvcman->num_plugins; i++)
258
261
        {
259
262
                pPlugin = dvcman->plugins[i];
 
263
 
260
264
                if (pPlugin->Initialize)
261
265
                        pPlugin->Initialize(pPlugin, pChannelMgr);
262
266
        }
 
267
 
263
268
        return 0;
264
269
}
265
270
 
266
 
static int dvcman_write_channel(IWTSVirtualChannel* pChannel,
267
 
        uint32 cbSize,
268
 
        uint8* pBuffer,
269
 
        void* pReserved)
 
271
static int dvcman_write_channel(IWTSVirtualChannel* pChannel, uint32 cbSize, uint8* pBuffer, void* pReserved)
270
272
{
271
 
        DVCMAN_CHANNEL* channel = (DVCMAN_CHANNEL*)pChannel;
 
273
        DVCMAN_CHANNEL* channel = (DVCMAN_CHANNEL*) pChannel;
272
274
 
273
275
        return drdynvc_write_data(channel->dvcman->drdynvc, channel->channel_id, pBuffer, cbSize);
274
276
}
275
277
 
276
278
static int dvcman_close_channel_iface(IWTSVirtualChannel* pChannel)
277
279
{
278
 
        DVCMAN_CHANNEL* channel = (DVCMAN_CHANNEL*)pChannel;
 
280
        DVCMAN_CHANNEL* channel = (DVCMAN_CHANNEL*) pChannel;
279
281
        DVCMAN* dvcman = channel->dvcman;
280
282
 
281
283
        DEBUG_DVC("id=%d", channel->channel_id);
282
284
 
283
285
        if (list_remove(dvcman->channels, channel) == NULL)
284
286
                DEBUG_WARN("channel not found");
 
287
 
285
288
        dvcman_channel_free(channel);
286
289
 
287
290
        return 1;
289
292
 
290
293
int dvcman_create_channel(IWTSVirtualChannelManager* pChannelMgr, uint32 ChannelId, const char* ChannelName)
291
294
{
292
 
        DVCMAN* dvcman = (DVCMAN*)pChannelMgr;
293
295
        int i;
294
 
        DVCMAN_LISTENER* listener;
295
 
        DVCMAN_CHANNEL* channel;
296
296
        int bAccept;
 
297
        DVCMAN_LISTENER* listener;
 
298
        DVCMAN_CHANNEL* channel;
297
299
        IWTSVirtualChannelCallback* pCallback;
 
300
        DVCMAN* dvcman = (DVCMAN*) pChannelMgr;
298
301
 
299
302
        for (i = 0; i < dvcman->num_listeners; i++)
300
303
        {
301
304
                listener = (DVCMAN_LISTENER*)dvcman->listeners[i];
 
305
 
302
306
                if (strcmp(listener->channel_name, ChannelName) == 0)
303
307
                {
304
308
                        channel = xnew(DVCMAN_CHANNEL);
309
313
 
310
314
                        bAccept = 1;
311
315
                        pCallback = NULL;
 
316
 
312
317
                        if (listener->listener_callback->OnNewChannelConnection(listener->listener_callback,
313
 
                                (IWTSVirtualChannel*)channel, NULL, &bAccept, &pCallback) == 0 && bAccept == 1)
 
318
                                (IWTSVirtualChannel*) channel, NULL, &bAccept, &pCallback) == 0 && bAccept == 1)
314
319
                        {
315
320
                                DEBUG_DVC("listener %s created new channel %d",
316
321
                                          listener->channel_name, channel->channel_id);
317
322
                                channel->channel_callback = pCallback;
318
323
                                list_add(dvcman->channels, channel);
 
324
 
319
325
                                return 0;
320
326
                        }
321
327
                        else
326
332
                        }
327
333
                }
328
334
        }
 
335
 
329
336
        return 1;
330
337
}
331
338
 
332
339
static DVCMAN_CHANNEL* dvcman_find_channel_by_id(IWTSVirtualChannelManager* pChannelMgr, uint32 ChannelId)
333
340
{
334
 
        DVCMAN* dvcman = (DVCMAN*)pChannelMgr;
335
341
        LIST_ITEM* curr;
 
342
        DVCMAN* dvcman = (DVCMAN*) pChannelMgr;
336
343
 
337
344
        for (curr = dvcman->channels->head; curr; curr = curr->next)
338
345
        {
339
 
                if (((DVCMAN_CHANNEL*)curr->data)->channel_id == ChannelId)
 
346
                if (((DVCMAN_CHANNEL*) curr->data)->channel_id == ChannelId)
340
347
                {
341
348
                        return (DVCMAN_CHANNEL*)curr->data;
342
349
                }
343
350
        }
 
351
 
344
352
        return NULL;
345
353
}
346
354
 
350
358
        IWTSVirtualChannel* ichannel;
351
359
 
352
360
        channel = dvcman_find_channel_by_id(pChannelMgr, ChannelId);
 
361
 
353
362
        if (channel == NULL)
354
363
        {
355
364
                DEBUG_WARN("ChannelId %d not found!", ChannelId);
356
365
                return 1;
357
366
        }
 
367
 
358
368
        if (channel->dvc_data)
359
369
        {
360
370
                stream_free(channel->dvc_data);
361
371
                channel->dvc_data = NULL;
362
372
        }
 
373
 
363
374
        DEBUG_DVC("dvcman_close_channel: channel %d closed", ChannelId);
364
375
        ichannel = (IWTSVirtualChannel*)channel;
365
376
        ichannel->Close(ichannel);
 
377
 
366
378
        return 0;
367
379
}
368
380
 
371
383
        DVCMAN_CHANNEL* channel;
372
384
 
373
385
        channel = dvcman_find_channel_by_id(pChannelMgr, ChannelId);
 
386
 
374
387
        if (channel == NULL)
375
388
        {
376
389
                DEBUG_WARN("ChannelId %d not found!", ChannelId);
377
390
                return 1;
378
391
        }
 
392
 
379
393
        if (channel->dvc_data)
380
394
                stream_free(channel->dvc_data);
 
395
 
381
396
        channel->dvc_data = stream_new(length);
382
397
 
383
398
        return 0;
385
400
 
386
401
int dvcman_receive_channel_data(IWTSVirtualChannelManager* pChannelMgr, uint32 ChannelId, uint8* data, uint32 data_size)
387
402
{
388
 
        DVCMAN_CHANNEL* channel;
389
403
        int error = 0;
 
404
        DVCMAN_CHANNEL* channel;
390
405
 
391
406
        channel = dvcman_find_channel_by_id(pChannelMgr, ChannelId);
 
407
 
392
408
        if (channel == NULL)
393
409
        {
394
410
                DEBUG_WARN("ChannelId %d not found!", ChannelId);
405
421
                        channel->dvc_data = NULL;
406
422
                        return 1;
407
423
                }
 
424
 
408
425
                stream_write(channel->dvc_data, data, data_size);
 
426
 
409
427
                if (stream_get_length(channel->dvc_data) >= stream_get_size(channel->dvc_data))
410
428
                {
411
429
                        error = channel->channel_callback->OnDataReceived(channel->channel_callback,
416
434
        }
417
435
        else
418
436
        {
419
 
                error = channel->channel_callback->OnDataReceived(channel->channel_callback,
420
 
                        data_size, data);
 
437
                error = channel->channel_callback->OnDataReceived(channel->channel_callback, data_size, data);
421
438
        }
422
439
 
423
440
        return error;