Changeset 1349:9582e89c7130 in roaraudio


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

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • include/libroar/vio_dstr.h

    r1333 r1349  
    8989#define ROAR_VIO_DSTR_OBJT_HTTP           ROAR_VIO_DSTR_OBJT_HTTP11 
    9090#define ROAR_VIO_DSTR_OBJT_GOPHER         (0x21|ROAR_VIO_DSTR_OBJGT_PROTO) 
     91#define ROAR_VIO_DSTR_OBJT_GOPHER_PLUS    (0x22|ROAR_VIO_DSTR_OBJGT_PROTO) 
    9192 
    9293/* 
  • include/libroar/vio_proto.h

    r1347 r1349  
    3838#include "libroar.h" 
    3939 
     40struct roar_vio_defaults; 
     41 
     42#define ROAR_VIO_PROTO_P_NONE      0 
     43#define ROAR_VIO_PROTO_P_HTTP      1 
     44#define ROAR_VIO_PROTO_P_GOPHER    2 
     45 
     46int roar_vio_proto_init_def  (struct roar_vio_defaults * def, char * dstr, int proto, struct roar_vio_defaults * odef); 
     47 
     48int roar_vio_open_proto      (struct roar_vio_calls * calls, struct roar_vio_calls * dst, 
     49                              char * dstr, int proto, struct roar_vio_defaults * odef); 
     50 
     51int roar_vio_open_proto_http   (struct roar_vio_calls * calls, struct roar_vio_calls * dst, char * host, char * file); 
     52int roar_vio_open_proto_gopher (struct roar_vio_calls * calls, struct roar_vio_calls * dst, char * host, char * file); 
    4053#endif 
    4154 
  • libroar/vio_dstr.c

    r1337 r1349  
    9696 {ROAR_VIO_DSTR_OBJT_GOPHER,     "gopher", 
    9797      {ROAR_VIO_DEF_TYPE_EOL}}, 
     98 {ROAR_VIO_DSTR_OBJT_GOPHER_PLUS,"gopher+", 
     99      {ROAR_VIO_DEF_TYPE_EOL}}, 
    98100 
    99101 {ROAR_VIO_DSTR_OBJT_GZIP,       "gzip", 
     
    496498    break; 
    497499#endif 
     500   case ROAR_VIO_DSTR_OBJT_HTTP09: 
     501   case ROAR_VIO_DSTR_OBJT_HTTP10: 
     502   case ROAR_VIO_DSTR_OBJT_HTTP11: 
     503     c->need_vio = 1; 
     504     next->def = &(next->store_def); 
     505 
     506     if ( roar_vio_proto_init_def(next->def, c->dst, ROAR_VIO_PROTO_P_HTTP, c->def) == -1 ) 
     507      return -1; 
     508    break; 
     509   case ROAR_VIO_DSTR_OBJT_GOPHER: 
     510   case ROAR_VIO_DSTR_OBJT_GOPHER_PLUS: 
     511     c->need_vio = 1; 
     512     next->def = &(next->store_def); 
     513 
     514     if ( roar_vio_proto_init_def(next->def, c->dst, ROAR_VIO_PROTO_P_GOPHER, c->def) == -1 ) 
     515      return -1; 
     516    break; 
    498517   default: 
    499518    return -1; 
     
    501520 
    502521  if ( next != NULL ) { 
    503    ROAR_DBG("roar_vio_dstr_set_defaults(*): i=%i, c->type=0x%.4x(%s): next->def=%p, next->def->type=%i", i, 
     522   ROAR_WARN("roar_vio_dstr_set_defaults(*): i=%i, c->type=0x%.4x(%s): next->def=%p, next->def->type=%i", i, 
    504523                    c->type & 0xFFFF, roar_vio_dstr_get_name(c->type), 
    505524                    next->def, next->def == NULL ? -1 : next->def->type); 
     525   if ( next->def != NULL ) { 
     526    ROAR_WARN("roar_vio_dstr_set_defaults(*): i=%i, c->type=0x%.4x(%s): next->def->o_flags=%i", i, 
     527                     c->type & 0xFFFF, roar_vio_dstr_get_name(c->type), 
     528                     next->def->o_flags); 
     529   } 
    506530  } else { 
    507    ROAR_DBG("roar_vio_dstr_set_defaults(*): i=%i, c->type=0x%.4x(%s): next=NULL", i, 
     531   ROAR_WARN("roar_vio_dstr_set_defaults(*): i=%i, c->type=0x%.4x(%s): next=NULL", i, 
    508532                    c->type & 0xFFFF, roar_vio_dstr_get_name(c->type)); 
    509533  } 
     
    558582 
    559583 for (i = 0; (c = &chain[i])->type != ROAR_VIO_DSTR_OBJT_EOL; i++) { 
     584  ROAR_WARN("roar_vio_dstr_build_chain(*): i=%i, c->type=0x%.4x(%s): need_vio=%i", i, 
     585                   c->type & 0xFFFF, roar_vio_dstr_get_name(c->type), c->need_vio); 
     586 
    560587  if ( c->need_vio ) { 
    561588   if ( (tc = malloc(sizeof(struct roar_vio_calls))) == NULL ) { 
     
    572599   } 
    573600 
     601 
    574602   switch (c->type) { 
    575603    case ROAR_VIO_DSTR_OBJT_PASS: 
     
    591619    case ROAR_VIO_DSTR_OBJT_PGP: 
    592620      if ( roar_vio_open_pgp_decrypt(tc, prev, NULL) == -1 ) { 
     621       _ret(-1); 
     622      } 
     623     break; 
     624    case ROAR_VIO_DSTR_OBJT_HTTP09: 
     625    case ROAR_VIO_DSTR_OBJT_HTTP10: 
     626    case ROAR_VIO_DSTR_OBJT_HTTP11: 
     627      ROAR_WARN("roar_vio_dstr_build_chain(*): HTTP*"); 
     628      if ( roar_vio_open_proto(tc, prev, c->dst, ROAR_VIO_PROTO_P_HTTP, i == 0 ? NULL : chain[i-1].def) == -1 ) { 
     629       _ret(-1); 
     630      } 
     631     break; 
     632    case ROAR_VIO_DSTR_OBJT_GOPHER: 
     633    case ROAR_VIO_DSTR_OBJT_GOPHER_PLUS: 
     634      ROAR_WARN("roar_vio_dstr_build_chain(*): GOPHER*"); 
     635      if ( roar_vio_open_proto(tc, prev, c->dst, ROAR_VIO_PROTO_P_GOPHER, i == 0 ? NULL : chain[i-1].def) == -1 ) { 
    593636       _ret(-1); 
    594637      } 
  • 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 
  • libroar/vio_socket.c

    r1348 r1349  
    200200 if ( hint == -1 && odef != NULL ) { // if we still don't know what this is we try 
    201201                                     // to use the parent objects request 
     202  ROAR_WARN("roar_vio_socket_init_dstr_def(*): hint=-1 && odef!=NULL"); 
    202203  if ( odef->type == ROAR_VIO_DEF_TYPE_SOCKET ) { 
     204   ROAR_WARN("roar_vio_socket_init_dstr_def(*): hint=-1 && odef!=NULL, using hint from odef"); 
    203205   hint = odef->d.socket.domain; 
    204206  } 
     
    411413int     roar_vio_socket_init_inet4host_def(struct roar_vio_defaults * def) { 
    412414 struct hostent     * he; 
     415 char               * ed; 
    413416 
    414417 if ( def == NULL ) 
     
    417420 if ( def->d.socket.host == NULL ) 
    418421  return -1; 
     422 
     423 if ( (ed = strstr(def->d.socket.host, "/")) != NULL ) 
     424  *ed = 0; 
    419425 
    420426 if ( (he = gethostbyname(def->d.socket.host)) == NULL ) { 
    421427  ROAR_ERR("roar_vio_socket_init_inet4host_def(*): Can\'t resolve host name '%s'", 
    422428                    def->d.socket.host); 
    423   return -1; 
    424  } 
     429  if ( ed != NULL ) *ed = '/'; 
     430  return -1; 
     431 } 
     432 
     433 if ( ed != NULL ) *ed = '/'; 
    425434 
    426435 memcpy((struct in_addr *)&def->d.socket.sa.in.sin_addr, he->h_addr, sizeof(struct in_addr)); 
Note: See TracChangeset for help on using the changeset viewer.