Subversion Repositories SvarDOS

Rev

Rev 1185 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
207 mateuszvis 1
/*
2
 * pkgnet - pulls SvarDOS packages from the project's online repository
3
 *
4
 * PUBLISHED UNDER THE TERMS OF THE MIT LICENSE
5
 *
1185 mateusz.vi 6
 * COPYRIGHT (C) 2016-2023 MATEUSZ VISTE, ALL RIGHTS RESERVED.
207 mateuszvis 7
 *
8
 * Permission is hereby granted, free of charge, to any person obtaining a
9
 * copy of this software and associated documentation files (the "Software"),
10
 * to deal in the Software without restriction, including without limitation
11
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12
 * and/or sell copies of the Software, and to permit persons to whom the
13
 * Software is furnished to do so, subject to the following conditions:
14
 *
15
 * The above copyright notice and this permission notice shall be included in
16
 * all copies or substantial portions of the Software.
17
 *
18
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24
 * DEALINGS IN THE SOFTWARE.
25
 *
712 mateusz.vi 26
 * http://svardos.org
207 mateuszvis 27
 */
28
 
344 mateuszvis 29
#include <direct.h> /* opendir() and friends */
207 mateuszvis 30
#include <stdio.h>
209 mateuszvis 31
#include <stdlib.h>
207 mateuszvis 32
#include <string.h>
33
#include <time.h>
34
 
35
#include "net.h"
342 mateuszvis 36
#include "unchunk.h"
207 mateuszvis 37
 
712 mateusz.vi 38
#include "svarlang.lib\svarlang.h"
39
 
633 mateusz.vi 40
#include "../../pkg/trunk/lsm.h"
344 mateuszvis 41
 
42
 
1185 mateusz.vi 43
#define PVER "20230208"
44
#define PDATE "2021-2023"
209 mateuszvis 45
 
633 mateusz.vi 46
#define HOSTADDR "svardos.org"
207 mateuszvis 47
 
209 mateuszvis 48
 
712 mateusz.vi 49
/* convenience define that outputs nls strings to screen (followed by CR/LF) */
50
#define putsnls(x,y) puts(svarlang_strid((x << 8) | y))
51
 
52
 
338 mateuszvis 53
/* returns length of all http headers, or 0 if uncomplete yet */
54
static unsigned short detecthttpheadersend(const unsigned char *buff) {
55
  char lastbyteislf = 0;
56
  unsigned short i;
57
  for (i = 0; buff[i] != 0; i++) {
207 mateuszvis 58
    if (buff[i] == '\r') continue; /* ignore CR characters */
59
    if (buff[i] != '\n') {
60
      lastbyteislf = 0;
61
      continue;
62
    }
63
    /* cur byte is LF -> if last one was also LF then this is an empty line, meaning headers are over */
64
    if (lastbyteislf == 0) {
65
      lastbyteislf = 1;
66
      continue;
67
    }
338 mateuszvis 68
    /* end of headers! return length of headers */
69
    return(i + 1); /* add 1 to skip the current \n character */
207 mateuszvis 70
  }
71
  return(0);
72
}
73
 
74
 
209 mateuszvis 75
static void help(void) {
76
  puts("pkgnet ver " PVER " -- Copyright (C) " PDATE " Mateusz Viste");
77
  puts("");
712 mateusz.vi 78
  putsnls(1, 0);  /* "pkgnet is the SvarDOS package downloader" */
209 mateuszvis 79
  puts("");
712 mateusz.vi 80
  putsnls(1, 1);  /* "usage:  pkgnet search <term>" */
81
  putsnls(1, 2);  /* "        pkgnet pull <package>" */
82
  putsnls(1, 3);  /* "        pkgnet pull <package>-<version>" */
875 mateusz.vi 83
  putsnls(1, 4);  /* "        pkgnet pullsrc <package>" */
84
  putsnls(1, 5);  /* "        pkgnet pullsrc <package>-<version>" */
712 mateusz.vi 85
  putsnls(1, 6);  /* "        pkgnet checkup" */
209 mateuszvis 86
  puts("");
712 mateusz.vi 87
  putsnls(1, 7);  /* "actions:" */
209 mateuszvis 88
  puts("");
712 mateusz.vi 89
  putsnls(1, 8);  /* "search   - asks remote repository for the list of matching packages" */
90
  putsnls(1, 9);  /* "pull     - downloads package into current directory" */
900 bttr 91
  putsnls(1, 10); /* "pullsrc  - downloads source code archive for package" */
92
  putsnls(1, 11); /* "checkup  - lists updates available for your system" */
712 mateusz.vi 93
  puts("");
342 mateuszvis 94
  printf("Watt32 kernel: %s", net_engine());
95
  puts("");
209 mateuszvis 96
}
97
 
98
 
99
/* parses command line arguments and fills outfname and url accordingly
100
 * returns 0 on success, non-zero otherwise */
342 mateuszvis 101
static int parseargv(int argc, char * const *argv, char *outfname, char *url, int *ispost) {
725 mateusz.vi 102
  const char *lang = getenv("LANG");
103
  if (lang == NULL) lang = "";
211 mateuszvis 104
  *outfname = 0;
209 mateuszvis 105
  *url = 0;
342 mateuszvis 106
  *ispost = 0;
209 mateuszvis 107
  if ((argc == 3) && (strcasecmp(argv[1], "search") == 0)) {
725 mateusz.vi 108
    sprintf(url, "/repo/?a=search&p=%s&lang=%s", argv[2], lang);
875 mateusz.vi 109
  } else if ((argc == 3) && ((strcasecmp(argv[1], "pull") == 0) || (strcasecmp(argv[1], "pullsrc") == 0))) {
558 mateuszvis 110
    unsigned short i;
111
    /* copy argv[2] into outfname, but stop at first '-' or null terminator
112
     * this trims any '-version' part in filename to respect 8+3 */
113
    for (i = 0; (argv[2][i] != 0) && (argv[2][i] != '-') && (i < 8); i++) {
114
      outfname[i] = argv[2][i];
211 mateuszvis 115
    }
875 mateusz.vi 116
    /* add the extension (svp or zip) to filename and compute url */
117
    if (strcasecmp(argv[1], "pull") == 0) {
118
      sprintf(url, "/repo/?a=pull&p=%s&lang=%s", argv[2], lang);
119
      strcpy(outfname + i, ".svp");
120
    } else {
121
      sprintf(url, "/repo/?a=pullsrc&p=%s&lang=%s", argv[2], lang);
122
      strcpy(outfname + i, ".zip");
123
    }
209 mateuszvis 124
  } else if ((argc == 2) && (strcasecmp(argv[1], "checkup") == 0)) {
725 mateusz.vi 125
    sprintf(url, "/repo/?a=checkup&lang=%s", lang);
342 mateuszvis 126
    *ispost = 1;
209 mateuszvis 127
  } else {
128
    help();
129
    return(-1);
130
  }
131
  return(0);
132
}
133
 
134
 
342 mateuszvis 135
static int htget_headers(unsigned char *buffer, size_t buffersz, struct net_tcpsocket *sock, int *httpcode, int *ischunked)  {
338 mateuszvis 136
  unsigned char *buffptr = buffer;
137
  unsigned short bufflen = 0;
138
  int byteread;
139
  time_t starttime = time(NULL);
140
  for (;;) {
141
    byteread = net_recv(sock, buffptr, buffersz - (bufflen + 1)); /* -1 because I will append a NULL terminator */
142
 
143
    if (byteread > 0) { /* got data */
144
      int hdlen;
145
      bufflen += byteread;
146
      buffptr += byteread;
147
      buffer[bufflen] = 0;
148
      hdlen = detecthttpheadersend(buffer);
149
      if (hdlen > 0) { /* full headers - parse http code and continue processing */
342 mateuszvis 150
        int i;
151
        buffer[hdlen - 1] = 0;
338 mateuszvis 152
        /* find the first space (HTTP/1.1 200 OK) */
342 mateuszvis 153
        for (i = 0; i < 16; i++) {
154
          if ((buffer[i] == ' ') || (buffer[i] == 0)) break;
338 mateuszvis 155
        }
342 mateuszvis 156
        if (buffer[i] != ' ') return(-1);
157
        *httpcode = atoi((char *)(buffer + i + 1));
158
        /* switch all headers to low-case so it is easier to parse them */
159
        for (i = 0; i < hdlen; i++) if ((buffer[i] >= 'A') && (buffer[i] <= 'Z')) buffer[i] += ('a' - 'A');
160
        /* look out for chunked transfer encoding */
161
        {
162
        char *lineptr = strstr((char *)buffer, "\ntransfer-encoding:");
163
        if (lineptr != NULL) {
164
          lineptr += 19;
165
          /* replace nearest \r, \n or 0 by 0 */
166
          for (i = 0; ; i++) {
167
            if ((lineptr[i] == '\r') || (lineptr[i] == '\n') || (lineptr[i] == 0)) {
168
              lineptr[i] = 0;
169
              break;
170
            }
171
          }
172
          /* do I see the 'chunked' word? */
173
          if (strstr((char *)lineptr, "chunked") != NULL) *ischunked = 1;
174
        }
175
        }
338 mateuszvis 176
        /* rewind the buffer */
177
        bufflen -= hdlen;
178
        memmove(buffer, buffer + hdlen, bufflen);
179
        return(bufflen); /* move to body processing now */
180
      }
181
 
182
    } else if (byteread < 0) { /* abort on error */
183
      return(-2); /* unexpected end of connection (while waiting for all http headers) */
184
 
185
    } else { /* else no data received - look for timeout and release a cpu cycle */
186
      if (time(NULL) - starttime > 20) return(-3); /* TIMEOUT! */
187
      _asm int 28h; /* release a CPU cycle */
188
    }
189
  }
190
}
191
 
192
 
342 mateuszvis 193
/* provides body data of the POST query for checkup actions
194
   fills buff with data and returns data length.
195
   must be called repeateadly until zero-lengh is returned */
196
static unsigned short checkupdata(char *buff) {
344 mateuszvis 197
  static char *dosdir = NULL;
198
  static DIR *dp;
199
  static struct dirent *ep;
200
 
201
  /* make sure I know %DOSDIR% */
202
  if (dosdir == NULL) {
203
    dosdir = getenv("DOSDIR");
204
    if ((dosdir == NULL) || (dosdir[0] == 0)) {
712 mateusz.vi 205
      putsnls(9, 0); /* "ERROR: %DOSDIR% not set" */
344 mateuszvis 206
      return(0);
207
    }
208
  }
209
 
210
  /* if first call, open the package directory */
211
  if (dp == NULL) {
212
    sprintf(buff, "%s\\packages", dosdir);
213
    dp = opendir(buff);
214
    if (dp == NULL) {
712 mateusz.vi 215
      putsnls(9, 1); /* "ERROR: Could not access %DOSDIR%\\packages directory" */
344 mateuszvis 216
      return(0);
217
    }
218
  }
219
 
220
  for (;;) {
221
    int tlen;
347 mateuszvis 222
    char ver[20];
344 mateuszvis 223
    ep = readdir(dp);   /* readdir() result must never be freed (statically allocated) */
224
    if (ep == NULL) {   /* no more entries */
225
      closedir(dp);
226
      return(0);
227
    }
228
 
229
    tlen = strlen(ep->d_name);
230
    if (tlen < 4) continue; /* files must be at least 5 bytes long ("x.lst") */
231
    if (strcasecmp(ep->d_name + tlen - 4, ".lst") != 0) continue;  /* if not an .lst file, skip it silently */
232
    ep->d_name[tlen - 4] = 0; /* trim out the ".lst" suffix */
233
 
234
    /* load the metadata from %DOSDIR\APPINFO\*.lsm */
235
    sprintf(buff, "%s\\appinfo\\%s.lsm", dosdir, ep->d_name);
236
    readlsm(buff, ver, sizeof(ver));
237
 
346 mateuszvis 238
    return(sprintf(buff, "%s\t%s\n", ep->d_name, ver));
344 mateuszvis 239
  }
342 mateuszvis 240
}
241
 
242
 
211 mateuszvis 243
/* fetch http data from ipaddr using url
244
 * write result to file outfname if not null, or print to stdout otherwise
245
 * fills bsum with the BSD sum of the data
342 mateuszvis 246
 * is ispost is non-zero, then the request is a POST and its body data is
247
 * obtained through repeated calls to checkupdata()
211 mateuszvis 248
 * returns the length of data obtained, or neg value on error */
1132 mateusz.vi 249
static long htget(const char *ipaddr, const char *url, const char *outfname, unsigned short *bsum, int ispost, unsigned char *buffer, size_t buffersz, unsigned short tcpbuflen) {
211 mateuszvis 250
  struct net_tcpsocket *sock;
327 mateuszvis 251
  time_t lastactivity, lastprogressoutput = 0;
342 mateuszvis 252
  int httpcode = -1, ischunked = 0;
338 mateuszvis 253
  int byteread;
332 mateuszvis 254
  long flen = 0, lastflen = 0;
209 mateuszvis 255
  FILE *fd = NULL;
207 mateuszvis 256
 
342 mateuszvis 257
  /* unchunk state variable is using a little part of the supplied buffer */
258
  struct unchunk_state *unchstate = (void *)buffer;
259
  buffer += sizeof(*unchstate);
260
  buffersz -= sizeof(*unchstate);
261
  memset(unchstate, 0, sizeof(*unchstate));
262
 
1132 mateusz.vi 263
  sock = net_connect(ipaddr, 80, tcpbuflen);
207 mateuszvis 264
  if (sock == NULL) {
712 mateusz.vi 265
    printf(svarlang_strid(0x0902), HOSTADDR); /* "ERROR: failed to connect to " HOSTADDR */
266
    puts("");
207 mateuszvis 267
    goto SHITQUIT;
268
  }
269
 
270
  /* wait for net_connect() to actually connect */
271
  for (;;) {
329 mateuszvis 272
    int connstate = net_isconnected(sock);
207 mateuszvis 273
    if (connstate > 0) break;
274
    if (connstate < 0) {
712 mateusz.vi 275
      printf(svarlang_strid(0x0902), HOSTADDR); /* "ERROR: failed to connect to " HOSTADDR */
276
      puts("");
207 mateuszvis 277
      goto SHITQUIT;
278
    }
211 mateuszvis 279
    _asm int 28h;  /* DOS idle */
207 mateuszvis 280
  }
281
 
330 mateuszvis 282
  /* socket is connected - send the http request (MUST be HTTP/1.0 because I do not support chunked transfers!) */
342 mateuszvis 283
  if (ispost) {
284
    snprintf((char *)buffer, buffersz, "POST %s HTTP/1.1\r\nHOST: " HOSTADDR "\r\nUSER-AGENT: pkgnet/" PVER "\r\nTransfer-Encoding: chunked\r\nConnection: close\r\n\r\n", url);
285
  } else {
286
    snprintf((char *)buffer, buffersz, "GET %s HTTP/1.1\r\nHOST: " HOSTADDR "\r\nUSER-AGENT: pkgnet/" PVER "\r\nConnection: close\r\n\r\n", url);
287
  }
207 mateuszvis 288
 
329 mateuszvis 289
  if (net_send(sock, buffer, strlen((char *)buffer)) != (int)strlen((char *)buffer)) {
712 mateusz.vi 290
    putsnls(9, 3); /* "ERROR: failed to send a HTTP query to remote server" */
207 mateuszvis 291
    goto SHITQUIT;
292
  }
293
 
342 mateuszvis 294
  /* send chunked data for POST queries */
295
  if (ispost) {
296
    unsigned short blen;
297
    int hlen;
298
    char *hbuf = (char *)buffer + buffersz - 16;
344 mateuszvis 299
    do {
342 mateuszvis 300
      blen = checkupdata((char *)buffer);
301
      if (blen == 0) { /* last item contains the message trailer */
344 mateuszvis 302
        hlen = sprintf(hbuf, "0\r\n");
342 mateuszvis 303
      } else {
304
        hlen = sprintf(hbuf, "%X\r\n", blen);
305
      }
306
      if (net_send(sock, hbuf, hlen) != hlen) {
712 mateusz.vi 307
        putsnls(9, 4); /* "ERROR: failed to send POST data to remote server" */
342 mateuszvis 308
        goto SHITQUIT;
309
      }
344 mateuszvis 310
      /* add trailing CR/LF to buffer as required by chunked mode */
311
      buffer[blen++] = '\r';
312
      buffer[blen++] = '\n';
342 mateuszvis 313
      if (net_send(sock, buffer, blen) != blen) {
712 mateusz.vi 314
        putsnls(9, 4); /* "ERROR: failed to send POST data to remote server" */
342 mateuszvis 315
        goto SHITQUIT;
316
      }
344 mateuszvis 317
    } while (blen != 2);
342 mateuszvis 318
  }
319
 
338 mateuszvis 320
  /* receive and process HTTP headers */
342 mateuszvis 321
  byteread = htget_headers(buffer, buffersz, sock, &httpcode, &ischunked);
207 mateuszvis 322
 
338 mateuszvis 323
  /* transmission error? */
324
  if (byteread < 0) {
712 mateusz.vi 325
    printf(svarlang_strid(0x0905), byteread); /* "ERROR: TCP communication error #%d" */
338 mateuszvis 326
    puts("");
327
    goto SHITQUIT;
328
  }
207 mateuszvis 329
 
338 mateuszvis 330
  /* open destination file if required and if no server-side error occured */
342 mateuszvis 331
  if ((httpcode >= 200) && (httpcode <= 299) && (*outfname != 0)) {
338 mateuszvis 332
    fd = fopen(outfname, "wb");
333
    if (fd == NULL) {
712 mateusz.vi 334
      printf(svarlang_strid(0x0906), outfname); /* "ERROR: failed to create file %s" */
338 mateuszvis 335
      puts("");
336
      goto SHITQUIT;
207 mateuszvis 337
    }
338 mateuszvis 338
  }
207 mateuszvis 339
 
342 mateuszvis 340
  /* read body of the answer (and chunk-decode it if needed) */
338 mateuszvis 341
  lastactivity = time(NULL);
342 mateuszvis 342
  for (;; byteread = net_recv(sock, buffer, buffersz - 1)) { /* read 1 byte less because I need to append a NULL terminator when printf'ing the content */
338 mateuszvis 343
 
344
    if (byteread > 0) { /* got data */
207 mateuszvis 345
      lastactivity = time(NULL);
342 mateuszvis 346
 
347
      /* unpack data if server transmits in chunked mode */
348
      if (ischunked) byteread = unchunk(buffer, byteread, unchstate);
349
 
207 mateuszvis 350
      /* if downloading to file, write stuff to disk */
209 mateuszvis 351
      if (fd != NULL) {
352
        int i;
353
        if (fwrite(buffer, 1, byteread, fd) != byteread) {
712 mateusz.vi 354
          printf(svarlang_strid(0x0907), outfname, flen); /* "ERROR: failed to write data to file %s after %ld bytes" */
209 mateuszvis 355
          puts("");
356
          break;
357
        }
358
        flen += byteread;
327 mateuszvis 359
        /* update progress once a sec */
360
        if (lastprogressoutput != lastactivity) {
361
          lastprogressoutput = lastactivity;
333 mateuszvis 362
          printf("%ld KiB (%ld KiB/s)     \r", flen >> 10, (flen >> 10) - (lastflen >> 10)); /* trailing spaces are meant to avoid leaving garbage on screen if speed goes from, say, 1000 KiB/s to 9 KiB/s */
332 mateuszvis 363
          lastflen = flen;
364
          fflush(stdout); /* avoid console buffering */
327 mateuszvis 365
        }
209 mateuszvis 366
        /* update the bsd sum */
367
        for (i = 0; i < byteread; i++) {
368
          /* rotr16 */
211 mateuszvis 369
          unsigned short bsumlsb = *bsum & 1;
370
          *bsum >>= 1;
371
          *bsum |= (bsumlsb << 15);
372
          *bsum += buffer[i];
209 mateuszvis 373
        }
374
      } else { /* otherwise dump to screen */
342 mateuszvis 375
        buffer[byteread] = 0;
209 mateuszvis 376
        printf("%s", buffer);
377
      }
338 mateuszvis 378
 
379
    } else if (byteread < 0) { /* end of connection */
380
      break;
381
 
382
    } else { /* check for timeout (byteread == 0) */
383
      if (time(NULL) - lastactivity > 20) { /* TIMEOUT! */
712 mateusz.vi 384
        putsnls(9, 8); /* "ERROR: Timeout while waiting for data" */
338 mateuszvis 385
        goto SHITQUIT;
386
      }
387
      /* waiting for packets - release a CPU cycle in the meantime */
388
      _asm int 28h;
207 mateuszvis 389
    }
390
  }
391
 
338 mateuszvis 392
  goto ALLGOOD;
393
 
211 mateuszvis 394
  SHITQUIT:
338 mateuszvis 395
  flen = -1;
396
 
397
  ALLGOOD:
398
  if (fd != NULL) fclose(fd);
333 mateuszvis 399
  net_close(sock);
338 mateuszvis 400
  return(flen);
211 mateuszvis 401
}
402
 
403
 
404
/* checks if file exists, returns 0 if not, non-zero otherwise */
405
static int fexists(const char *fname) {
406
  FILE *fd = fopen(fname, "rb");
407
  if (fd == NULL) return(0);
408
  fclose(fd);
409
  return(1);
410
}
411
 
412
 
413
int main(int argc, char **argv) {
414
  unsigned short bsum = 0;
415
  long flen;
1132 mateusz.vi 416
  unsigned short tcpbufsz = (16 * 1024);
342 mateuszvis 417
  int ispost; /* is the request a POST? */
211 mateuszvis 418
 
342 mateuszvis 419
  struct {
1132 mateusz.vi 420
    unsigned char buffer[5000];
342 mateuszvis 421
    char ipaddr[64];
422
    char url[64];
423
    char outfname[16];
424
  } *mem;
425
 
712 mateusz.vi 426
  svarlang_autoload("PKGNET");
427
 
1131 mateusz.vi 428
  /* look for PKGNETBUFSZ env var to size up the buffer (default=5000 bytes) */
429
  {
430
    const char *ptr = getenv("PKGNETBUFSZ");
431
    if (ptr != NULL) {
432
      long newsz = atol(ptr);
1132 mateusz.vi 433
      if ((newsz >= 0) && (newsz < 65500)) {
434
        tcpbufsz = newsz;
435
        printf("WILL USE CUSTOM TCP BUFF SIZE = %u\r\n", tcpbufsz);
1131 mateusz.vi 436
      }
437
    }
438
  }
439
 
342 mateuszvis 440
  /* allocate memory */
1132 mateusz.vi 441
  mem = malloc(sizeof(*mem));
342 mateuszvis 442
  if (mem == NULL) {
712 mateusz.vi 443
    putsnls(9, 9); /* "ERROR: out of memory" */
342 mateuszvis 444
    return(1);
445
  }
446
 
211 mateuszvis 447
  /* parse command line arguments */
342 mateuszvis 448
  if (parseargv(argc, argv, mem->outfname, mem->url, &ispost) != 0) return(1);
211 mateuszvis 449
 
450
  /* if outfname requested, make sure that file does not exist yet */
342 mateuszvis 451
  if ((mem->outfname[0] != 0) && (fexists(mem->outfname))) {
712 mateusz.vi 452
    printf(svarlang_strid(0x090A), mem->outfname); /* "ERROR: file %s already exists" */
211 mateuszvis 453
    puts("");
454
    return(1);
455
  }
456
 
457
  /* init network stack */
458
  if (net_init() != 0) {
712 mateusz.vi 459
    putsnls(9, 11); /* "ERROR: Network subsystem initialization failed" */
211 mateuszvis 460
    return(1);
461
  }
462
 
463
  puts(""); /* required because watt-32 likes to print out garbage sometimes ("configuring through DHCP...") */
464
 
885 mateusz.vi 465
  if (net_dnsresolve(mem->ipaddr, HOSTADDR, 2) != 0) {
712 mateusz.vi 466
    putsnls(9, 12); /* "ERROR: DNS resolution failed" */
211 mateuszvis 467
    return(1);
468
  }
469
 
1132 mateusz.vi 470
  flen = htget(mem->ipaddr, mem->url, mem->outfname, &bsum, ispost, mem->buffer, sizeof(mem->buffer), tcpbufsz);
211 mateuszvis 471
  if (flen < 1) return(1);
472
 
342 mateuszvis 473
  if (mem->outfname[0] != 0) {
209 mateuszvis 474
    /* print bsum, size, filename */
712 mateusz.vi 475
    printf(svarlang_strid(0x0200), flen >> 10, mem->outfname, bsum); /* Downloaded %ld KiB into %s (BSUM: %04X) */
209 mateuszvis 476
    puts("");
477
  }
478
 
207 mateuszvis 479
  return(0);
480
}