Changeset 1349:9582e89c7130 in roaraudio for libroar/vio_proto.c


Ignore:
Timestamp:
03/23/09 18:13:26 (15 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

changed a lot, got gopher working :), need cleanup

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libroar/vio_proto.c

    r1347 r1349  
    3535#include "libroar.h" 
    3636 
     37int roar_vio_proto_init_def  (struct roar_vio_defaults * def, char * dstr, int proto, struct roar_vio_defaults * odef) { 
     38 int                        port = 0; 
     39 int                        ret; 
     40 char                     * ed; 
     41 
     42 if ( def == NULL ) 
     43  return -1; 
     44 
     45 switch (proto) { 
     46  case ROAR_VIO_PROTO_P_HTTP:    port = 80; break; 
     47  case ROAR_VIO_PROTO_P_GOPHER:  port = 70; break; 
     48  default: 
     49    return -1; 
     50 } 
     51 
     52 if ( roar_vio_dstr_init_defaults(def, ROAR_VIO_DEF_TYPE_SOCKET, O_RDWR, 0644) == -1 ) 
     53  return -1; 
     54 
     55 if ( roar_vio_socket_init_tcp4_def(def, "localhost", port) == -1 ) 
     56  return -1; 
     57 
     58 if ( !strncmp(dstr, "//", 2) ) 
     59  dstr += 2; 
     60 
     61 if ( (ed = strstr(dstr, "/")) != NULL ) 
     62  *ed = 0; 
     63 
     64 ret = roar_vio_socket_init_dstr_def(def, dstr, -1, SOCK_STREAM, def); 
     65 
     66 if ( ed != NULL ) 
     67  *ed = '/'; 
     68 
     69 return ret; 
     70} 
     71 
     72int roar_vio_open_proto      (struct roar_vio_calls * calls, struct roar_vio_calls * dst, 
     73                              char * dstr, int proto, struct roar_vio_defaults * odef) { 
     74 char * host; 
     75 char * tmp; 
     76 
     77 ROAR_WARN("roar_vio_open_proto(calls=%p, dst=%p, dstr='%s', proto=%i, odef=%p) = ?", calls, dst, dstr, proto, odef); 
     78 
     79 if ( calls == NULL || dst == NULL || dstr == NULL ) 
     80  return -1; 
     81 
     82 ROAR_DBG("roar_vio_open_proto(*) = ?"); 
     83 
     84 if ( roar_vio_open_pass(calls, dst) == -1 ) 
     85  return -1; 
     86 
     87 dstr += 2; 
     88 host  = dstr; 
     89 
     90 if ( (tmp = strstr(dstr, "/")) == NULL ) 
     91  return -1; 
     92 
     93 *tmp++ = 0; 
     94 dstr   = tmp; 
     95 
     96 if ( (tmp = strstr(dstr, "#")) != NULL ) 
     97  *tmp = 0; 
     98 
     99 ROAR_DBG("roar_vio_open_proto(*) = ?"); 
     100 
     101 switch (proto) { 
     102  case ROAR_VIO_PROTO_P_HTTP: 
     103    return roar_vio_open_proto_http(calls, dst, host, dstr); 
     104   break; 
     105  case ROAR_VIO_PROTO_P_GOPHER: 
     106    return roar_vio_open_proto_gopher(calls, dst, host, dstr); 
     107   break; 
     108 } 
     109 
     110 return -1; 
     111} 
     112 
     113int roar_vio_open_proto_http   (struct roar_vio_calls * calls, struct roar_vio_calls * dst, char * host, char * file) { 
     114 return -1; 
     115} 
     116 
     117int roar_vio_open_proto_gopher (struct roar_vio_calls * calls, struct roar_vio_calls * dst, char * host, char * file) { 
     118 int len; 
     119 
     120 if ( calls == NULL || dst == NULL || host == NULL || file == NULL ) 
     121  return -1; 
     122 
     123 ROAR_DBG("roar_vio_open_proto_gopher(calls=%p, dst=%p, host='%s', file='%s') = ?", calls, dst, host, file); 
     124 
     125 len = strlen(file); 
     126 
     127 if ( roar_vio_write(dst, file, len) != len ) 
     128  return -1; 
     129 
     130 if ( roar_vio_write(dst, "\n", 1) != 1 ) 
     131  return -1; 
     132 
     133 roar_vio_sync(dst); // for encryption/compression layers 
     134 
     135 return 0; 
     136} 
     137 
    37138//ll 
Note: See TracChangeset for help on using the changeset viewer.