add libvncserver
[presencevnc] / libvnc / libvncserver / tightvnc-filetransfer / filelistinfo.c
1 /*
2  * Copyright (c) 2005 Novell, Inc.
3  * All Rights Reserved.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of version 2 of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, contact Novell, Inc.
16  *
17  * To contact Novell about this file by physical or electronic mail,
18  * you may find current contact information at www.novell.com 
19  *
20  * Author               : Rohit Kumar
21  * Email ID     : rokumar@novell.com
22  * Date         : 14th July 2005
23  */
24  
25
26 #include <stdio.h>
27 #include "rfb/rfb.h"
28 #include "filelistinfo.h"
29
30
31 /* This method is used for debugging purpose */
32 void
33 DisplayFileList(FileListInfo fli)
34 {
35     int i = 0;
36     if((fli.pEntries == NULL) || (fli.numEntries == 0)) return;
37     
38     rfbLog("DISPLAYING FILE NAMES IN THE LIST ...START\n\n");
39     rfbLog("Numer of entries:: %d\n", fli.numEntries);
40     for(i = 0; i < fli.numEntries; i++)
41                 rfbLog("file[%d]\t<%s>\n", i, fli.pEntries[i].name);
42     rfbLog("DISPLAYING FILE NAMES IN THE LIST ...END\n\n");
43 }
44
45 #ifndef __GNUC__
46 #define __FUNCTION__ "unknown"
47 #endif
48
49 int 
50 AddFileListItemInfo(FileListInfoPtr fileListInfoPtr, char* name, 
51                                         unsigned int size, unsigned int data)
52 {
53         FileListItemInfoPtr fileListItemInfoPtr = (FileListItemInfoPtr) 
54                                                                                                 calloc((fileListInfoPtr->numEntries + 1), 
55                                                                                                                 sizeof(FileListItemInfo));
56         if(fileListItemInfoPtr == NULL) {
57             rfbLog("File [%s]: Method [%s]: fileListItemInfoPtr is NULL\n",
58                         __FILE__, __FUNCTION__);
59                 return FAILURE;
60         }    
61
62         if(fileListInfoPtr->numEntries != 0) {
63             memcpy(fileListItemInfoPtr, fileListInfoPtr->pEntries, 
64                         fileListInfoPtr->numEntries * sizeof(FileListItemInfo));
65         }
66
67         strcpy(fileListItemInfoPtr[fileListInfoPtr->numEntries].name, name);
68         fileListItemInfoPtr[fileListInfoPtr->numEntries].size = size;
69         fileListItemInfoPtr[fileListInfoPtr->numEntries].data = data;
70
71         if(fileListInfoPtr->pEntries != NULL) {
72             free(fileListInfoPtr->pEntries);
73             fileListInfoPtr->pEntries = NULL;   
74         }
75
76         fileListInfoPtr->pEntries = fileListItemInfoPtr;
77         fileListItemInfoPtr = NULL;
78         fileListInfoPtr->numEntries++;
79
80         return SUCCESS;
81 }
82
83
84 char* 
85 GetFileNameAt(FileListInfo fileListInfo, int number)
86 {
87         char* name = NULL;
88         if(number >= 0 && number < fileListInfo.numEntries)
89                 name = fileListInfo.pEntries[number].name;
90         return name;
91 }
92
93
94 unsigned int 
95 GetFileSizeAt(FileListInfo fileListInfo, int number)
96 {
97         unsigned int size = 0;
98         if(number >= 0 && number < fileListInfo.numEntries)
99                 size = fileListInfo.pEntries[number].size;
100         return size;
101 }
102
103
104 unsigned int 
105 GetFileDataAt(FileListInfo fileListInfo, int number)
106 {
107         unsigned int data = 0;
108         if(number >= 0 && number < fileListInfo.numEntries)
109                 data = fileListInfo.pEntries[number].data;
110         return data;
111 }
112
113
114 unsigned int 
115 GetSumOfFileNamesLength(FileListInfo fileListInfo)
116 {
117         int i = 0, sumLen = 0;
118         for(i = 0; i < fileListInfo.numEntries; i++)
119                 sumLen += strlen(fileListInfo.pEntries[i].name);
120         return sumLen;
121 }
122
123
124 void
125 FreeFileListInfo(FileListInfo fileListInfo)
126 {
127         if(fileListInfo.pEntries != NULL) {
128                 free(fileListInfo.pEntries);
129                 fileListInfo.pEntries = NULL;
130         }
131         fileListInfo.numEntries = 0;
132 }
133