home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1999 March B / SCO_CASTOR4RRT.iso / nsfast / root.9 / usr / ns-home / nsapi / include / base / cinfo.h / cinfo
Text File  |  1998-08-19  |  4KB  |  146 lines

  1. /*
  2.  * Copyright (c) 1994, 1995.  Netscape Communications Corporation.  All
  3.  * rights reserved.
  4.  * 
  5.  * Use of this software is governed by the terms of the license agreement for
  6.  * the Netscape FastTrack or Netscape Enterprise Server between the
  7.  * parties.
  8.  */
  9.  
  10.  
  11. /* ------------------------------------------------------------------------ */
  12.  
  13.  
  14. /*
  15.  * cinfo.h: Content Information for a file, i.e. its type, etc.
  16.  * 
  17.  * See cinfo.c for dependency information. 
  18.  * 
  19.  * Rob McCool
  20.  */
  21.  
  22.  
  23.  
  24. #ifndef CINFO_H
  25. #define CINFO_H
  26.  
  27. #include "../netsite.h"
  28.  
  29.  
  30. /* ------------------------------ Constants ------------------------------- */
  31.  
  32.  
  33. /*
  34.  * This will be the first string in the file, followed by x.x version
  35.  * where x is an integer.
  36.  *
  37.  * Updated due to trendy name change
  38.  */
  39.  
  40. #define MCC_MT_MAGIC "#--Mosaic Communications Corporation MIME Information"
  41. #define MCC_MT_MAGIC_LEN 53
  42. #define NCC_MT_MAGIC "#--Netscape Communications Corporation MIME Information"
  43. #define NCC_MT_MAGIC_LEN 55
  44.  
  45. /* The character which separates extensions with cinfo_find */
  46.  
  47. #define CINFO_SEPARATOR '.'
  48.  
  49. /* The maximum length of a line in this file */
  50.  
  51. #define CINFO_MAX_LEN 1024
  52.  
  53. /* The hash function for the database. Hashed on extension. */
  54. #include <ctype.h>
  55. #define CINFO_HASH(s) (isalpha(s[0]) ? tolower(s[0]) - 'a' : 26)
  56.  
  57. /* The hash table size for that function */
  58. #define CINFO_HASHSIZE 27
  59.  
  60.  
  61. /* ------------------------------ Structures ------------------------------ */
  62.  
  63.  
  64. /*
  65.  * The ContentInfo structure.
  66.  * 
  67.  * Currently, we support the following attributes:
  68.  * 
  69.  * 1. Type: This identifies what kind of data is in the file.
  70.  * 2. Encoding: Identifies any compression or otherwise content-independent
  71.  *    transformation which has been applied to the file (uuencode, etc.)
  72.  * 3. Language: Identifies the language a text document is in.
  73.  * 4. Description: A text string describing the file.
  74.  * 5. Viewer: The program to use to view the file.
  75.  *
  76.  * Multiple items are separated with a comma, e.g. 
  77.  * encoding="x-gzip, x-uuencode"
  78.  */
  79.  
  80. typedef struct {
  81.     char *type;
  82.     char *encoding;
  83.     char *language;
  84. } cinfo;
  85.  
  86.  
  87. /* ------------------------------ Prototypes ------------------------------ */
  88.  
  89.  
  90. /*
  91.  * cinfo_init initializes the content info system. Call this before 
  92.  * cinfo_merge.
  93.  */
  94.  
  95. NSAPI_PUBLIC void cinfo_init(void);
  96.  
  97. /*
  98.  * cinfo_terminate frees the database for shutdown.
  99.  */
  100.  
  101. NSAPI_PUBLIC void cinfo_terminate(void);
  102.  
  103. /*
  104.  * cinfo_merge merges the contents of the given filename with the current 
  105.  * cinfo database. It returns NULL upon success and a string (which you
  106.  * must deallocate) upon error.
  107.  */
  108.  
  109. NSAPI_PUBLIC char *cinfo_merge(char *fn);
  110.  
  111.  
  112. /*
  113.  * cinfo_find finds any content information for the given uri. The file name
  114.  * is the string following the last / in the uri. Multiple extensions are
  115.  * separated by CINFO_SEPARATOR. You may pass in a filename instead of uri.
  116.  *
  117.  * Returns a newly allocated cinfo structure with the information it
  118.  * finds. The elements of this structure are coming right out of the types 
  119.  * database and so if you change it or want to keep it around for long you
  120.  * should strdup it. You should free only the structure itself when finished
  121.  * with it.
  122.  *
  123.  * If there is no information for any one of the extensions it
  124.  * finds, it will ignore that extension. If it cannot find information for
  125.  * any of the extensions, it will return NULL.
  126.  */
  127.  
  128. NSAPI_PUBLIC cinfo *cinfo_find(char *uri);
  129.  
  130. /*
  131.  * cinfo_lookup finds the information about the given content-type, and 
  132.  * returns a cinfo structure so you can look up description and icon.
  133.  */
  134.  
  135. NSAPI_PUBLIC cinfo *cinfo_lookup(char *type);
  136.  
  137. /*
  138.  * cinfo_dump_database dumps the current database to the given file desc.
  139.  */
  140.  
  141. #include <stdio.h>
  142. NSAPI_PUBLIC void cinfo_dump_database(FILE *dump);
  143.  
  144.  
  145. #endif
  146.