home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Misc / FTPMOUNT.LZX / FTPMount-0.7 / Source / ftpinfo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-09-06  |  2.6 KB  |  159 lines

  1. /*
  2.  * This source file is Copyright 1995 by Evan Scott.
  3.  * All rights reserved.
  4.  * Permission is granted to distribute this file provided no
  5.  * fees beyond distribution costs are levied.
  6.  */
  7.  
  8. #include <exec/types.h>
  9. #include <exec/memory.h>
  10. #include <exec/alerts.h>
  11.  
  12. #include <devices/timer.h>
  13.  
  14. #include <dos/dos.h>
  15. #include <dos/dosextens.h>
  16. #include <dos/dostags.h>
  17.  
  18. #include <proto/exec.h>
  19.  
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <string.h>
  23.  
  24. #include "evtypes.h"
  25. #include "verify.h"
  26. #include "tcp.h"
  27.  
  28. #include "site.h"
  29. #include "ftp.h"
  30. #include "split.h"
  31. #include "ftpinfo.h"
  32. #include "connect.h"
  33.  
  34. #include "globals.h"
  35.  
  36. /*
  37.  * ftpinfo routines
  38.  */
  39.  
  40. void add_ftpinfo(struct info_header *ih, b8 *name, struct DateStamp ds, b32 size, b32 blocks, b32 flags)
  41. {
  42.     ftpinfo *fi;
  43.     int len;
  44.     
  45.     verify(ih, V_info_header);
  46.     
  47.     len = strlen(name);
  48.     
  49.     fi = allocate(sizeof(*fi) + len + 1, V_ftpinfo);
  50.     if (!fi) return;
  51.     
  52.     ensure(fi, V_ftpinfo);
  53.     
  54.     strcpy(fi->name, name);
  55.  
  56.     fi->modified = ds;
  57.     fi->size = size;
  58.     fi->blocks = blocks;
  59.     fi->flags = flags;
  60.     
  61.     fi->next = ih->infos;
  62.     ih->infos = fi;
  63.  
  64.     return;
  65. }
  66.  
  67. void free_info_header(struct info_header *ih)
  68. {
  69.     ftpinfo *fi, *fin;
  70.     
  71.     verify(ih, V_info_header);
  72.     
  73.     fi = ih->infos;
  74.     while (fi) {
  75.         verify(fi, V_ftpinfo);
  76.         fin = fi->next;
  77.         
  78.         deallocate(fi, V_ftpinfo);
  79.         fi = fin;
  80.     }
  81.     
  82.     if (ih->next)
  83.         ih->next->prev = ih->prev;
  84.  
  85.     *(ih->prev) = ih->next;
  86.     
  87.     deallocate(ih, V_info_header);
  88.     
  89.     return;
  90. }
  91.  
  92. struct info_header *new_info_header(site *sp, b8 *name)
  93. {
  94.     struct info_header *ih;
  95.     
  96.     verify(sp, V_site);
  97.     
  98.     ih = (struct info_header *)allocate(sizeof(*ih) + strlen(name) + 1, V_info_header);
  99.     if (!ih) return nil;
  100.     
  101.     ensure(ih, V_info_header);
  102.     
  103.     ih->infos = nil;
  104.     
  105.     ih->next = sp->infos;
  106.     if (sp->infos) sp->infos->prev = &(ih->next);
  107.     sp->infos = ih;
  108.     ih->prev = &(sp->infos);
  109.     
  110.     strcpy(ih->name, name);
  111.     
  112.     ih->case_sensitive = sp->case_sensitive;
  113.     
  114.     return ih;
  115. }
  116.  
  117. struct info_header *find_info_header(site *sp, b8 *name)
  118. {
  119.     struct info_header *ih;
  120.  
  121.     verify(sp, V_site);
  122.  
  123.     ih = sp->infos;    
  124.  
  125.     if (sp->case_sensitive) {
  126.         while (ih) {
  127.             if (strcmp(ih->name, name) == 0) return ih;
  128.             ih = ih->next;
  129.         }
  130.     } else {
  131.         while (ih) {
  132.             if (stricmp(ih->name, name) == 0) return ih;
  133.             ih = ih->next;
  134.         }
  135.     }
  136.  
  137.     return nil;
  138. }
  139.  
  140. ftpinfo *find_info(struct info_header *ih, b8 *name)
  141. {
  142.     ftpinfo *fi;
  143.     
  144.     fi = ih->infos;
  145.     if (ih->case_sensitive) {
  146.         while (fi) {
  147.             if (strcmp(fi->name, name) == 0 && !(fi->flags & MYFLAG_DELETED) ) return fi;
  148.             fi = fi->next;
  149.         }
  150.     } else {
  151.         while (fi) {
  152.             if (stricmp(fi->name, name) == 0 && !(fi->flags & MYFLAG_DELETED) ) return fi;
  153.             fi = fi->next;
  154.         }
  155.     }
  156.  
  157.     return nil;
  158. }
  159.