~ubuntu-branches/ubuntu/raring/ncbi-tools6/raring

« back to all changes in this revision

Viewing changes to connect/test/test_ncbi_ftp_connector.c

  • Committer: Package Import Robot
  • Author(s): Aaron M. Ucko
  • Date: 2011-09-05 18:55:02 UTC
  • mfrom: (1.1.11 upstream)
  • Revision ID: package-import@ubuntu.com-20110905185502-iuvmoe65ytljhckn
Tags: 6.1.20110713-1
* New upstream release.
* debian/*.symbols: update accordingly.
* make/makeshlb.unx: link libcn3dOGL.so against -lm for sqrt.
* doc/man/*.1: update for new release.
* debian/rules:
  - (VIB): add asnmacro, as upstream takes care to publish binaries thereof.
  - Retire obsolete multiarch-unaware checks for libpthread.
  - Fully modernize Debhelper usage; in particular, transition to overrides.
* debian/compat: advance to 9 per rules modernization.
* debian/ncbi-tools-bin.install: add asnmacro.
* make/makenet.unx: link asnmacro only against libraries it directly needs.
* doc/man/asnmacro.1: give asnmacro a man page.
* doc/man/Psequin.1: list it in SEE ALSO.
* network/id1arch/idfetch.c: revert redundant change (from #295110).
* Convert to multiarch.
  - debian/rules: Install libraries (and ncbithr.o) to multiarch directories.
  - debian/lib*.install: match multiarch library paths.
  - debian/control:
    + Build-Depends: debhelper (>= 8.1.3~), implying a recent dpkg-dev.
    + Set Multi-Arch: as appropriate across the board, and specify
      Pre-Depends: ${misc:Pre-Depends} for runtime libraries.
* debian/*.lintian-overrides: drop leading slashes for Lintian 2.5.x.
* debian/control: Standards-Version: 3.9.2 (already compliant).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: test_ncbi_ftp_connector.c,v 1.26 2010/06/04 14:59:37 kazimird Exp $
 
1
/* $Id: test_ncbi_ftp_connector.c,v 1.30 2011/04/17 19:34:30 kazimird Exp $
2
2
 * ===========================================================================
3
3
 *
4
4
 *                            PUBLIC DOMAIN NOTICE
63
63
 
64
64
int main(int argc, char* argv[])
65
65
{
66
 
    static const char kChdir[] = "CWD /toolbox/ncbi_tools\n";
67
 
    static const char kFile[] = "RETR CURRENT/ncbi.tar.gz";
68
 
    int/*bool*/   aborting = 0, first;
69
 
    TFCDC_Flags   flag = 0;
 
66
    static const char kChdir[] = "CWD /toolbox/ncbi_tools++\n";
 
67
    static const char kFile[] = "DATA/Misc/test_ncbi_conn_stream.FTP.data";
 
68
    int/*bool*/   cancel = 0, first;
 
69
    TFTP_Flags    flag = 0;
70
70
    SConnNetInfo* net_info;
71
71
    char          buf[1024];
72
72
    CONNECTOR     connector;
73
73
    FILE*         data_file;
74
74
    size_t        size, n;
 
75
    double        elapsed;
75
76
    EIO_Status    status;
76
 
    double        elapse;
77
77
    CONN          conn;
78
78
 
79
79
    g_NCBI_ConnectRandomSeed = (int) time(0) ^ NCBI_CONNECT_SRAND_ADDEND;
88
88
 
89
89
    assert((net_info = ConnNetInfo_Create(0)) != 0);
90
90
    if (net_info->debug_printout == eDebugPrintout_Some)
91
 
        flag |= fFCDC_LogControl;
 
91
        flag |= fFTP_LogControl;
92
92
    else if (net_info->debug_printout == eDebugPrintout_Data) {
93
93
        char val[32];
94
94
        ConnNetInfo_GetValue(0, REG_CONN_DEBUG_PRINTOUT, val, sizeof(val),
95
95
                             DEF_CONN_DEBUG_PRINTOUT);
96
 
        flag |= strcasecmp(val, "all") == 0 ? fFCDC_LogAll : fFCDC_LogData;
 
96
        flag |= strcasecmp(val, "all") == 0 ? fFTP_LogAll : fFTP_LogData;
97
97
    }
98
 
    flag |= fFCDC_UseFeatures;
 
98
    flag |= fFTP_UseFeatures;
99
99
 
100
100
    if (TEST_PORT) {
101
101
        sprintf(buf, ":%hu", TEST_PORT);
109
109
                                            TEST_USER, TEST_PASS,
110
110
                                            TEST_PATH, flag);
111
111
 
112
 
    if (CONN_Create(connector, &conn) != eIO_Success)
 
112
    if (CONN_CreateEx(connector,
 
113
                      fCONN_Supplement | fCONN_Untie, &conn) != eIO_Success) {
113
114
        CORE_LOG(eLOG_Fatal, "Cannot create FTP download connection");
 
115
    }
114
116
 
115
117
    assert(CONN_SetTimeout(conn, eIO_Open,      net_info->timeout)
116
118
           == eIO_Success);
133
135
        CORE_LOG(eLOG_Fatal, "Test failed to reject multiple commands");
134
136
    CORE_LOG(eLOG_Note, "Multiple commands correctly rejected");
135
137
 
136
 
    status = CONN_Write(conn, "SIZE 1GB\n", 9, &n, eIO_WritePersist);
 
138
    status = CONN_Write(conn, "SIZE 1GB", 9, &n, eIO_WritePlain);
137
139
    if (status == eIO_Success) {
138
140
        char buf[128];
139
141
        CONN_ReadLine(conn, buf, sizeof(buf) - 1, &n);
180
182
        fflush(stdout);
181
183
    }
182
184
 
183
 
    if (CONN_Write(conn, "SIZE ", 5, &n, eIO_WritePlain) != eIO_Success)
 
185
    if (CONN_Write(conn, "SIZE ", 5, &n, eIO_WritePersist) != eIO_Success)
184
186
        CORE_LOG(eLOG_Fatal, "Cannot write SIZE directory command");
185
187
    size = strlen(kChdir + 4);
186
 
    if (CONN_Write(conn, kChdir + 4, size, &n, eIO_WritePersist)==eIO_Success){
187
 
        char buf[128];
 
188
    if (CONN_Write(conn, kChdir + 4, size, &n, eIO_WritePlain) == eIO_Success){
188
189
        CONN_ReadLine(conn, buf, sizeof(buf) - 1, &n);
189
190
        CORE_LOGF(eLOG_Note, ("SIZE directory returned: %.*s", (int) n, buf));
190
191
    } else {
197
198
        CORE_LOGF(eLOG_Fatal, ("Cannot execute %.*s",
198
199
                               (int) sizeof(kChdir) - 2, kChdir));
199
200
    }
200
 
 
201
 
    size = strlen(kFile + 5);
202
 
    if ((status = CONN_Write(conn, "MDTM ", 5, &n, eIO_WritePlain))
203
 
        == eIO_Success  &&
204
 
        (status = CONN_Write(conn, kFile + 5, size, &n, eIO_WritePersist))
205
 
        == eIO_Success) {
 
201
    if (CONN_Write(conn, "PWD\n", 4, &n, eIO_WritePlain) == eIO_Success) {
 
202
        CONN_ReadLine(conn, buf, sizeof(buf) - 1, &n);
 
203
        CORE_LOGF(eLOG_Note, ("PWD returned: %.*s", (int) n, buf));
 
204
    } else
 
205
        CORE_LOG(eLOG_Fatal, "Cannot execute PWD");
 
206
 
 
207
    if (CONN_Write(conn, "CDUP\n", 5, &n, eIO_WritePlain) != eIO_Success)
 
208
        CORE_LOG(eLOG_Fatal, "Cannot execute CDUP"); 
 
209
    if (CONN_Write(conn, "XCUP\n", 5, &n, eIO_WritePlain) != eIO_Success)
 
210
        CORE_LOG(eLOG_Fatal, "Cannot execute XCUP");
 
211
 
 
212
    if (CONN_Write(conn, kChdir, sizeof(kChdir) - 1, &n, eIO_WritePlain)
 
213
        != eIO_Success) {
 
214
        CORE_LOGF(eLOG_Fatal, ("Cannot re-execute %.*s",
 
215
                               (int) sizeof(kChdir) - 2, kChdir));
 
216
    }
 
217
 
 
218
    size = sizeof(kFile) - 1;
 
219
    if ((status = CONN_Write(conn, "MDTM ", 5, &n, eIO_WritePersist))
 
220
        == eIO_Success  &&  n == 5  &&
 
221
        (status = CONN_Write(conn, kFile, size, &n, eIO_WritePlain))
 
222
        == eIO_Success  &&  n == size) {
206
223
        unsigned long val;
207
224
        char buf[128];
208
225
        CONN_ReadLine(conn, buf, sizeof(buf) - 1, &n);
218
235
                              IO_StatusStr(status)));
219
236
    }
220
237
 
221
 
    if (CONN_Write(conn, kFile, sizeof(kFile) - 1, &n, eIO_WritePersist)
222
 
        != eIO_Success) {
223
 
        CORE_LOGF(eLOG_Fatal, ("Cannot write %s", kFile));
 
238
    if ((status = CONN_Write(conn, "RETR ", 5, &n, eIO_WritePersist))
 
239
        != eIO_Success  ||  n != 5  ||
 
240
        (status = CONN_Write(conn, kFile, size, &n, eIO_WritePersist))
 
241
        != eIO_Success  ||  n != size) {
 
242
        CORE_LOGF(eLOG_Fatal, ("Cannot write 'RETR %s': %s",
 
243
                               kFile, IO_StatusStr(status)));
224
244
    }
225
245
 
226
246
    size = 0;
227
 
    elapse = s_GetTime();
 
247
    elapsed = s_GetTime();
228
248
    do {
229
249
        status = CONN_Read(conn, buf, sizeof(buf), &n, eIO_ReadPlain);
230
250
        if (n != 0) {
232
252
            fflush(data_file);
233
253
            size += n;
234
254
            rand();
235
 
            if (argc > 1  &&  rand() % 100 == 0) {
236
 
                aborting = 1;
 
255
            if (argc > 1  &&  rand() % 100000 == 55555) {
 
256
                cancel = 1;
237
257
                break;
238
258
            }
239
259
        } else {
242
262
                CORE_LOGF(eLOG_Error, ("Read error: %s",IO_StatusStr(status)));
243
263
        }
244
264
    } while (status == eIO_Success);
245
 
    elapse = s_GetTime() - elapse;
 
265
    if (status != eIO_Success)
 
266
        cancel = 0;
 
267
    elapsed = s_GetTime() - elapsed;
246
268
 
247
 
    if (!aborting  ||  (rand() & 1) == 0) {
 
269
    if (!cancel  ||  !(rand() & 1)) {
 
270
        if (cancel)
 
271
            CORE_LOG(eLOG_Note, "Cancelling download by a command");
248
272
        if (CONN_Write(conn, "NLST blah*", 10, &n, eIO_WritePlain)
249
273
            != eIO_Success) {
250
274
            CORE_LOG(eLOG_Fatal, "Cannot write garbled NLST command");
251
275
        }
252
276
 
253
 
        CORE_LOG(eLOG_Note, "Garbled NLST command output (should be empty):");
 
277
        CORE_LOG(eLOG_Note, "Garbled NLST command output (expected empty):");
254
278
        first = 1/*true*/;
255
279
        do {
256
280
            status = CONN_Read(conn, buf, sizeof(buf), &n, eIO_ReadPlain);
264
288
            printf("<EOF>\n");
265
289
            fflush(stdout);
266
290
        }
267
 
    }
 
291
    } else if (cancel)
 
292
        CORE_LOG(eLOG_Note, "Closing with download still in progress");
268
293
 
269
 
    if (CONN_Close(conn) != eIO_Success) {
270
 
        CORE_LOGF(eLOG_Fatal, ("Error %s FTP connection",
271
 
                               aborting ? "aborting" : "closing"));
272
 
    }
 
294
    if (CONN_Close(conn) != eIO_Success)
 
295
        CORE_LOG(eLOG_Fatal, "Error in closing FTP connection");
273
296
 
274
297
    /* Cleanup and exit */
275
298
    fclose(data_file);
276
 
    if (!aborting) {
 
299
    if (!cancel) {
277
300
        CORE_LOGF(size ? eLOG_Note : eLOG_Fatal,
278
301
                  ("%lu byte(s) downloaded in %.2f second(s) @ %.2fKB/s",
279
 
                   (unsigned long) size, elapse,
280
 
                   (unsigned long) size / (1024 * (elapse ? elapse : 1.0))));
 
302
                   (unsigned long) size, elapsed,
 
303
                   (unsigned long) size / (1024 * (elapsed ? elapsed : 1.0))));
281
304
    } else
282
305
        remove("test_ncbi_ftp_connector.dat");
283
306
    ConnNetInfo_Destroy(net_info);