Browse Source

Rebarize ibrowse. Slightly tweakeed Andrew Tunnell-Jones' pull request

pull/35/head
Chandrashekhar Mullaparthi 14 years ago
parent
commit
0757ff975d
12 changed files with 7 additions and 234 deletions
  1. +1
    -1
      .gitignore
  2. +4
    -4
      Makefile
  3. +0
    -1
      c_src/build_darwin
  4. +0
    -162
      c_src/ibrowse_drv.c
  5. +0
    -13
      ebin/ibrowse.app
  6. BIN
      rebar
  7. +1
    -0
      rebar.config
  8. +0
    -32
      src/Makefile
  9. +1
    -1
      src/ibrowse.app.src
  10. +0
    -16
      src/ibrowse_test.erl
  11. +0
    -2
      test/Makefile
  12. +0
    -2
      vsn.mk

+ 1
- 1
.gitignore View File

@ -1,2 +1,2 @@
*.beam
ebin/*

+ 4
- 4
Makefile View File

@ -1,17 +1,17 @@
include vsn.mk
IBROWSE_VSN = $(shell sed -n 's/.*{vsn,.*"\(.*\)"}.*/\1/p' src/ibrowse.app.src)
all:
(cd src ; make)
(cd test ; make)
./rebar compile
clean:
(cd src ; make clean)
./rebar clean
install: all
mkdir -p $(DESTDIR)/lib/ibrowse-$(IBROWSE_VSN)/
cp -r ebin $(DESTDIR)/lib/ibrowse-$(IBROWSE_VSN)/
test: all
(cd test; make)
erl -noshell -pa ebin -pa test -s ibrowse -s ibrowse_test unit_tests \
-s ibrowse_test verify_chunked_streaming \
-s ibrowse_test test_chunked_streaming_once \

+ 0
- 1
c_src/build_darwin View File

@ -1 +0,0 @@
cc -o ../priv/ibrowse_drv.so -I ~/R9C-0/usr/include/ -bundle -flat_namespace -undefined suppress -fno-common ibrowse_drv.c

+ 0
- 162
c_src/ibrowse_drv.c View File

@ -1,162 +0,0 @@
/* Created 07/March/2004 Chandrashekhar Mullaparthi
$Id: ibrowse_drv.c,v 1.1 2005/05/05 22:28:28 chandrusf Exp $
Erlang Linked in driver to URL encode a set of data
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "erl_driver.h"
static ErlDrvData ibrowse_drv_start(ErlDrvPort port, char* buff);
static void ibrowse_drv_stop(ErlDrvData handle);
static void ibrowse_drv_command(ErlDrvData handle, char *buff, int bufflen);
static void ibrowse_drv_finish(void);
static int ibrowse_drv_control(ErlDrvData handle, unsigned int command,
char* buf, int count, char** res, int res_size);
/* The driver entry */
static ErlDrvEntry ibrowse_driver_entry = {
NULL, /* init, N/A */
ibrowse_drv_start, /* start, called when port is opened */
ibrowse_drv_stop, /* stop, called when port is closed */
NULL, /* output, called when erlang has sent */
NULL, /* ready_input, called when input descriptor
ready */
NULL, /* ready_output, called when output
descriptor ready */
"ibrowse_drv", /* char *driver_name, the argument
to open_port */
NULL, /* finish, called when unloaded */
NULL, /* void * that is not used (BC) */
ibrowse_drv_control, /* control, port_control callback */
NULL, /* timeout, called on timeouts */
NULL, /* outputv, vector output interface */
NULL,
NULL,
NULL, /* call, synchronous call to driver */
NULL
};
typedef struct ibrowse_drv_data {
unsigned int count;
void *alloc_ptr;
} State;
static State *ibrowse_drv_data;
DRIVER_INIT(ibrowse_drv)
{
ibrowse_drv_data = NULL;
return &ibrowse_driver_entry;
}
static ErlDrvData ibrowse_drv_start(ErlDrvPort port, char *buff)
{
State *state;
state = driver_alloc(sizeof(State));
state->count = 0;
state->alloc_ptr = NULL;
ibrowse_drv_data = state;
return ((ErlDrvData) state);
}
void ibrowse_drv_stop(ErlDrvData desc)
{
return;
}
static int ibrowse_drv_control(ErlDrvData handle, unsigned int command,
char *buf, int bufflen, char **rbuf, int rlen)
{
State* state = (State *) handle;
unsigned int j = 0, i = 0;
unsigned int temp = 0, rlen_1 = 0;
char* replybuf;
fprintf(stderr, "alloc_ptr -> %d\n", state->alloc_ptr);
/* if(state->alloc_ptr != NULL) */
/* { */
/* driver_free(state->alloc_ptr); */
/* } */
/* Calculate encoded length. If same as bufflen, it means there is
no encoding to do. Do return an empty list */
rlen_1 = calc_encoded_length(buf, bufflen);
if(rlen_1 == bufflen)
{
*rbuf = NULL;
state->alloc_ptr = NULL;
return 0;
}
*rbuf = driver_alloc(rlen_1);
state->alloc_ptr = *rbuf;
fprintf(stderr, "*rbuf -> %d\n", *rbuf);
replybuf = *rbuf;
for(i=0;i<bufflen;i++)
{
temp = buf[i];
if( 'a' <= temp && temp <= 'z'
|| 'A' <= temp && temp <= 'Z'
|| '0' <= temp && temp <= '9'
|| temp == '-' || temp == '_' || temp == '.' )
{
replybuf[j++] = temp;
/* printf("j -> %d\n", j); */
}
else
{
replybuf[j++] = 37;
/* printf("temp -> %d\n", temp);
printf("d2h(temp >> 4) -> %d\n", d2h(temp >> 4));
printf("d2h(temp & 15) -> %d\n", d2h(temp & 15)); */
replybuf[j++] = d2h(temp >> 4);
replybuf[j++] = d2h(temp & 15);
/* printf("j -> %d\n", j); */
}
}
return rlen_1;
}
/* Calculates the length of the resulting buffer if a string is URL encoded */
int calc_encoded_length(char* buf, int bufflen)
{
unsigned int count=0, i=0, temp=0;
for(i=0;i<bufflen;i++)
{
temp = buf[i];
if( 'a' <= temp && temp <= 'z'
|| 'A' <= temp && temp <= 'Z'
|| '0' <= temp && temp <= '9'
|| temp == '-' || temp == '_' || temp == '.' )
{
count++;
}
else
{
count = count+3;
}
}
return count;
}
/* Converts an integer in the range 1-15 into it's ascii value
1 -> 49 (ascii value of 1)
10 -> 97 (ascii value of a)
*/
int d2h(unsigned int i)
{
if( i < 10 )
{
return i + 48;
}
else
{
return i + 97 - 10;
}
}

+ 0
- 13
ebin/ibrowse.app View File

@ -1,13 +0,0 @@
{application, ibrowse,
[{description, "HTTP client application"},
{vsn, "2.1.3"},
{modules, [ ibrowse,
ibrowse_http_client,
ibrowse_app,
ibrowse_sup,
ibrowse_lib,
ibrowse_lb ]},
{registered, []},
{applications, [kernel,stdlib,sasl]},
{env, []},
{mod, {ibrowse_app, []}}]}.

BIN
rebar View File


+ 1
- 0
rebar.config View File

@ -0,0 +1 @@
{erl_opts, [warn_unused_vars, nowarn_shadow_vars, warn_unused_import]}.

+ 0
- 32
src/Makefile View File

@ -1,32 +0,0 @@
include ../vsn.mk
ERL_FILES = ibrowse.erl \
ibrowse_http_client.erl \
ibrowse_app.erl \
ibrowse_sup.erl \
ibrowse_lib.erl \
ibrowse_lb.erl \
ibrowse_test.erl
INCLUDE_DIRS = -I./
ERLC ?= erlc
ERLC_EMULATOR ?= erl -boot start_clean
COMPILER_OPTIONS = -W +debug_info +warn_unused_vars +nowarn_shadow_vars +warn_unused_import
.SUFFIXES: .erl .beam $(SUFFIXES)
EBIN = ../ebin
all: $(ERL_FILES:%.erl=$(EBIN)/%.beam) ../ebin/ibrowse.app
$(EBIN)/%.beam: %.erl
${ERLC} $(COMPILER_OPTIONS) $(INCLUDE_DIRS) -o ../ebin $<
$(EBIN)/%.app: %.app.src ../vsn.mk Makefile
sed -e s/%IBROWSE_VSN%/$(IBROWSE_VSN)/ \
$< > $@
clean:
rm -f $(EBIN)/*.beam $(EBIN)/*.app

+ 1
- 1
src/ibrowse.app.src View File

@ -1,6 +1,6 @@
{application, ibrowse,
[{description, "HTTP client application"},
{vsn, "%IBROWSE_VSN%"},
{vsn, "2.1.2"},
{modules, [ ibrowse,
ibrowse_http_client,
ibrowse_app,

+ 0
- 16
src/ibrowse_test.erl View File

@ -11,8 +11,6 @@
unit_tests/0,
unit_tests/1,
unit_tests_1/2,
drv_ue_test/0,
drv_ue_test/1,
ue_test/0,
ue_test/1,
verify_chunked_streaming/0,
@ -414,20 +412,6 @@ execute_req(Url, Method, Options) ->
io:format("~p~n", [Err])
end.
drv_ue_test() ->
drv_ue_test(lists:duplicate(1024, 127)).
drv_ue_test(Data) ->
[{port, Port}| _] = ets:lookup(ibrowse_table, port),
% erl_ddll:unload_driver("ibrowse_drv"),
% timer:sleep(1000),
% erl_ddll:load_driver("../priv", "ibrowse_drv"),
% Port = open_port({spawn, "ibrowse_drv"}, []),
{Time, Res} = timer:tc(ibrowse_lib, drv_ue, [Data, Port]),
io:format("Time -> ~p~n", [Time]),
io:format("Data Length -> ~p~n", [length(Data)]),
io:format("Res Length -> ~p~n", [length(Res)]).
% io:format("Result -> ~s~n", [Res]).
ue_test() ->
ue_test(lists:duplicate(1024, $?)).
ue_test(Data) ->

+ 0
- 2
test/Makefile View File

@ -1,5 +1,3 @@
include ../vsn.mk
ERL_FILES = ibrowse_test_server.erl

+ 0
- 2
vsn.mk View File

@ -1,2 +0,0 @@
IBROWSE_VSN = 2.1.3

Loading…
Cancel
Save