home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Amiga Shareware Floppies / ma64.dms / ma64.adf / FTPMount-1.0 / Source / ftpinfo.c < prev    next >
C/C++ Source or Header  |  1995-12-10  |  3KB  |  184 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.     /* instead of adding to front, and getting reversed lists, add to end */
  65.     *(ih->last_info_p) = fi;
  66.     ih->last_info_p = &(fi->next);
  67.     fi->next = nil;
  68.  
  69.     return;
  70. }
  71.  
  72. void free_info_header(struct info_header *ih)
  73. {
  74.     ftpinfo *fi, *fin;
  75.     
  76.     verify(ih, V_info_header);
  77.     
  78.     fi = ih->infos;
  79.     while (fi) {
  80.         verify(fi, V_ftpinfo);
  81.         fin = fi->next;
  82.         
  83.         deallocate(fi, V_ftpinfo);
  84.         fi = fin;
  85.     }
  86.     
  87.     if (ih->next)
  88.         ih->next->prev = ih->prev;
  89.  
  90.     *(ih->prev) = ih->next;
  91.     
  92.     deallocate(ih, V_info_header);
  93.     
  94.     return;
  95. }
  96.  
  97. struct info_header *new_info_header(site *sp, b8 *name)
  98. {
  99.     struct info_header *ih;
  100.     
  101.     verify(sp, V_site);
  102.     
  103.     ih = (struct info_header *)allocate(sizeof(*ih) + strlen(name) + 1, V_info_header);
  104.     if (!ih) return nil;
  105.     
  106.     ensure(ih, V_info_header);
  107.     
  108.     ih->infos = nil;
  109.     ih->last_info_p = &(ih->infos);
  110.     
  111.     ih->next = sp->infos;
  112.     if (sp->infos) sp->infos->prev = &(ih->next);
  113.     sp->infos = ih;
  114.     ih->prev = &(sp->infos);
  115.     
  116.     strcpy(ih->name, name);
  117.     
  118.     ih->case_sensitive = sp->case_sensitive;
  119.     
  120.     return ih;
  121. }
  122.  
  123. struct info_header *find_info_header(site *sp, b8 *name)
  124. {
  125.     struct info_header *ih;
  126.  
  127.     verify(sp, V_site);
  128.  
  129.     ih = sp->infos;    
  130.  
  131.     if (sp->case_sensitive) {
  132.         while (ih) {
  133.             if (strcmp(ih->name, name) == 0) return ih;
  134.             ih = ih->next;
  135.         }
  136.     } else {
  137.         while (ih) {
  138.             if (stricmp(ih->name, name) == 0) return ih;
  139.             ih = ih->next;
  140.         }
  141.     }
  142.  
  143.     return nil;
  144. }
  145.  
  146. ftpinfo *find_info(struct info_header *ih, b8 *name)
  147. {
  148.     ftpinfo *fi, *found;
  149.     
  150.     found = nil;
  151.     fi = ih->infos;
  152.  
  153.     if (ih->case_sensitive) {
  154.         while (fi) {
  155.             if (strcmp(fi->name, name) == 0 && !(fi->flags & MYFLAG_DELETED) ) 
  156.             {
  157.                 found = fi;
  158.                 break;
  159.             }
  160.             fi = fi->next;
  161.         }
  162.     } else {
  163.         found = nil;
  164.  
  165.         while (fi) {
  166.             if (!(fi->flags & MYFLAG_DELETED))
  167.             {    
  168.                 if (stricmp(fi->name, name) == 0)
  169.                 {
  170.                     found = fi;
  171.                     
  172.                     if (strcmp(fi->name, name) == 0)
  173.                     {
  174.                         break;  
  175.                     }
  176.                 }
  177.             }
  178.             fi = fi->next;
  179.         }
  180.     }
  181.  
  182.     return found;
  183. }
  184.