comparison plugins/icq/filesession.c @ 1977:7b3f1eb1ef7d

[gaim-migrate @ 1987] updated icqlib. fixed import dialog (watch debug window for errors). adam's (not mid's) patch for oscar. committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Sat, 09 Jun 2001 14:46:51 +0000
parents 8ed70631ed15
children 0be1e533036c
comparison
equal deleted inserted replaced
1976:24aed1c31342 1977:7b3f1eb1ef7d
1 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 2
3 /* 3 /*
4 * $Id: filesession.c 1987 2001-06-09 14:46:51Z warmenhoven $
5 *
4 * Copyright (C) 1998-2001, Denis V. Dmitrienko <denis@null.net> and 6 * Copyright (C) 1998-2001, Denis V. Dmitrienko <denis@null.net> and
5 * Bill Soudan <soudan@kde.org> 7 * Bill Soudan <soudan@kde.org>
6 * 8 *
7 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by 10 * it under the terms of the GNU General Public License as published by
73 if(p->files) { 75 if(p->files) {
74 char **p2=p->files; 76 char **p2=p->files;
75 while(*p2) 77 while(*p2)
76 free(*(p2++)); 78 free(*(p2++));
77 free(p->files); 79 free(p->files);
80 p->files=NULL;
78 } 81 }
79 82
80 if (p->current_fd > -1 ) { 83 if (p->current_fd > -1 ) {
81 close(p->current_fd); 84 close(p->current_fd);
82 p->current_fd=-1; 85 p->current_fd=-1;
123 strncpy(p->remote_handle, handle, 64); 126 strncpy(p->remote_handle, handle, 64);
124 } 127 }
125 128
126 void icq_FileSessionSetCurrentFile(icq_FileSession *p, const char *filename) 129 void icq_FileSessionSetCurrentFile(icq_FileSession *p, const char *filename)
127 { 130 {
131 #ifdef _WIN32
132 struct _stat file_status;
133 #else
128 struct stat file_status; 134 struct stat file_status;
135 #endif
129 char file[1024]; 136 char file[1024];
130 137
131 strcpy(file, p->working_dir); 138 strcpy(file, p->working_dir);
132 strcat(file, filename); 139 strcat(file, filename);
133 140
138 145
139 strncpy(p->current_file, file, 64); 146 strncpy(p->current_file, file, 64);
140 p->current_file_progress=0; 147 p->current_file_progress=0;
141 148
142 /* does the file already exist? */ 149 /* does the file already exist? */
150 #ifdef _WIN32
151 if (_stat(file, &file_status)==0) {
152 #else
143 if (stat(file, &file_status)==0) { 153 if (stat(file, &file_status)==0) {
154 #endif
144 p->current_file_progress=file_status.st_size; 155 p->current_file_progress=file_status.st_size;
145 p->total_transferred_bytes+=file_status.st_size; 156 p->total_transferred_bytes+=file_status.st_size;
157 #ifdef _WIN32
158 p->current_fd=open(file, _O_WRONLY | _O_APPEND | _O_BINARY);
159 #else
146 p->current_fd=open(file, O_WRONLY | O_APPEND); 160 p->current_fd=open(file, O_WRONLY | O_APPEND);
161 #endif
147 } else { 162 } else {
148 #ifdef _WIN32 163 #ifdef _WIN32
149 p->current_fd=open(file, O_WRONLY | O_CREAT); 164 p->current_fd=open(file, _O_WRONLY | _O_CREAT | _O_BINARY,
165 _S_IREAD|_S_IWRITE);
150 #else 166 #else
151 p->current_fd=open(file, O_WRONLY | O_CREAT, S_IRWXU); 167 p->current_fd=open(file, O_WRONLY | O_CREAT, S_IRWXU);
152 #endif 168 #endif
153 } 169 }
154 170
172 else 188 else
173 files++; 189 files++;
174 } 190 }
175 191
176 if(*files) { 192 if(*files) {
193 #ifdef _WIN32
194 struct _stat file_status;
195 #else
177 struct stat file_status; 196 struct stat file_status;
197 #endif
178 198
179 if (p->current_fd>-1) { 199 if (p->current_fd>-1) {
180 close(p->current_fd); 200 close(p->current_fd);
181 p->current_fd=-1; 201 p->current_fd=-1;
182 } 202 }
183 203
204 #ifdef _WIN32
205 if (_stat(*files, &file_status)==0) {
206 char *basename=*files;
207 char *pos=strrchr(basename, '\\');
208 #else
184 if (stat(*files, &file_status)==0) { 209 if (stat(*files, &file_status)==0) {
185 char *basename=*files; 210 char *basename=*files;
186 char *pos=strrchr(basename, '/'); 211 char *pos=strrchr(basename, '/');
212 #endif
187 if(pos) basename=pos+1; 213 if(pos) basename=pos+1;
188 strncpy(p->current_file, basename, 64); 214 strncpy(p->current_file, basename, 64);
189 p->current_file_progress=0; 215 p->current_file_progress=0;
190 p->current_file_size=file_status.st_size; 216 p->current_file_size=file_status.st_size;
217 #ifdef _WIN32
218 p->current_fd=open(*files, O_RDONLY | _O_BINARY);
219 #else
191 p->current_fd=open(*files, O_RDONLY); 220 p->current_fd=open(*files, O_RDONLY);
221 #endif
192 } 222 }
193 223
194 /* make sure we have a valid filehandle */ 224 /* make sure we have a valid filehandle */
195 if (p->current_fd == -1) 225 if (p->current_fd == -1)
196 perror("couldn't open file: "); 226 perror("couldn't open file: ");
242 { 272 {
243 plink->session=0L; 273 plink->session=0L;
244 icq_TCPLinkClose(plink); 274 icq_TCPLinkClose(plink);
245 } 275 }
246 276
277 icq_ListRemove(p->icqlink->d->icq_FileSessions, p);
247 icq_FileSessionDelete(p); 278 icq_FileSessionDelete(p);
248
249 icq_ListRemove(p->icqlink->d->icq_FileSessions, p);
250 } 279 }
251 280
252 void icq_FileSessionSetWorkingDir(icq_FileSession *p, const char *dir) 281 void icq_FileSessionSetWorkingDir(icq_FileSession *p, const char *dir)
253 { 282 {
254 strncpy(p->working_dir, dir, 512); 283 int length = sizeof(p->working_dir);
284 strncpy(p->working_dir, dir, length);
285 p->working_dir[length-1]='\0';
255 } 286 }
256 287
257 void icq_FileSessionSetFiles(icq_FileSession *p, char **files) 288 void icq_FileSessionSetFiles(icq_FileSession *p, char **files)
258 { 289 {
259 p->files=files; 290 p->files=files;