Home | History | Annotate | Download | only in common
      1 /*
      2  *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
      3  *
      4  *  Use of this source code is governed by a BSD-style license
      5  *  that can be found in the LICENSE file in the root of the source
      6  *  tree. An additional intellectual property rights grant can be found
      7  *  in the file PATENTS.  All contributing project authors may
      8  *  be found in the AUTHORS file in the root of the source tree.
      9  */
     10 
     11 
     12 #ifndef _duck_io_h
     13 #define _duck_io_h
     14 
     15 #if defined(__cplusplus)
     16 extern "C" {
     17 #endif
     18 
     19 #if defined (_WIN32)
     20     typedef __int64 int64_t;
     21 #elif defined(__MWERKS__)
     22     typedef long long int64_t;
     23 #elif defined(__APPLE__) || defined(__POWERPC)
     24 #include <ppc/types.h>
     25 #else
     26     typedef long long int64_t;
     27 #endif
     28 
     29     typedef struct
     30     {
     31         int64_t  offset;     // offset to start from
     32         int    blocking;    // non-zero for blocking
     33     } re_open_t;
     34 
     35 
     36     typedef enum
     37     {
     38         SAL_ERR_MAX                 = -10,
     39         SAL_ERROR                   = -11, // Default error
     40         SAL_ERR_WSASTARTUP          = -12,
     41         SAL_ERR_SOCKET_CREATE       = -13,
     42         SAL_ERR_RESOLVING_HOSTNAME  = -14,
     43         SAL_ERR_SERVER_CONNECTION   = -15,
     44         SAL_ERR_SENDING_DATA        = -16,
     45         SAL_ERR_RECEIVING_DATA      = -17,
     46         SAL_ERR_404_FILE_NOT_FOUND  = -18,
     47         SAL_ERR_PARSING_HTTP_HEADER = -19,
     48         SAL_ERR_PARSING_CONTENT_LEN = -20,
     49         SAL_ERR_CONNECTION_TIMEOUT  = -21,
     50         SAL_ERR_FILE_OPEN_FAILED    = -22,
     51         SAL_ERR_MIN                 = -23
     52     } SAL_ERR; /* EMH 1-15-03 */
     53 
     54 
     55     typedef struct sal_err_map_temp
     56     {
     57         SAL_ERR code;
     58         const char *decode;
     59 
     60     } sal_err_map_t;
     61 
     62 
     63     static char *sal_err_text(SAL_ERR e)
     64     {
     65         int t;
     66         const sal_err_map_t g_sal_err_map[] =
     67         {
     68             {   SAL_ERR_WSASTARTUP,             "Error with WSAStartup"         },
     69             {   SAL_ERR_SOCKET_CREATE,          "Error creating socket"         },
     70             {   SAL_ERR_RESOLVING_HOSTNAME,     "Error resolving hostname"      },
     71             {   SAL_ERR_SERVER_CONNECTION,      "Error connecting to server"    },
     72             {   SAL_ERR_SENDING_DATA,           "Error sending data"            },
     73             {   SAL_ERR_RECEIVING_DATA,         "Error receiving data"          },
     74             {   SAL_ERR_404_FILE_NOT_FOUND,     "Error file not found "         },
     75             {   SAL_ERR_PARSING_HTTP_HEADER,    "Error parsing http header"     },
     76             {   SAL_ERR_PARSING_CONTENT_LEN,    "Error parsing content length"  },
     77             {   SAL_ERR_CONNECTION_TIMEOUT,     "Error Connection timed out"    },
     78             {   SAL_ERR_FILE_OPEN_FAILED,       "Error opening file"            }
     79         };
     80 
     81         for (t = 0; t < sizeof(g_sal_err_map) / sizeof(sal_err_map_t); t++)
     82         {
     83             if (e == g_sal_err_map[t].code)
     84                 return (char *) g_sal_err_map[t].decode;
     85         }
     86 
     87         return 0;
     88     }
     89 
     90 
     91 
     92 
     93 
     94 
     95 
     96     int duck_open(const char *fname, unsigned long user_data);
     97 
     98     void duck_close(int ghndl);
     99 
    100     int duck_read(int ghndl, unsigned char *buf, int nbytes);
    101 
    102     int64_t duck_seek(int g_hndl, int64_t offs, int origin);
    103 
    104     int duck_read_finished(int han, int flag); /* FWG 7-9-99 */
    105 
    106     int duck_name(int handle, char name[], size_t max_len); /* EMH 9-23-03 */
    107 
    108     int duck_read_blocking(int handle, unsigned char *buffer, int bytes); /* EMH 9-23-03 */
    109 
    110     int64_t duck_available_data(int handle); /* EMH 10-23-03 */
    111 
    112 #if defined(__cplusplus)
    113 }
    114 #endif
    115 
    116 #endif
    117