snacc
這個庫比較早,最早是1997年,2002年的版本是1.4,後面沒有更新。在unix環境使用沒問題,在linux環境下編譯不過去。下面是unix環境下的使用方法。
- 升級make->gmake
http://ftp.gnu.org/gnu/make/make-3.75.tar.gz
編譯snacc
cd snacc/compiler
make./snacc
Usage: ./snacc [-h] [-P] [-t] [-v] [-e] [-d] [-p] [-f] [-c | -C | -[T|O] <table output file> | -idl ] [-u <useful types ASN.1 file>] [-mm] [-mf <max file name length>] [-l <neg number>] <ASN.1 file list>
編譯c-lib
cd snacc/c-lib
make編譯tap031111
cd snacc/c-examples/tap031111
make
asn1c
這個是目前使用的比較廣泛的一個庫
http://lionet.info/asn1c/blog/
http://lionet.info/soft/asn1c-0.9.27.tar.gz
編譯asn1c
cd asn1c-0.9.27
./configure & make
asn1c-0.9.27/asn1c/asn1c即爲asn1c編譯器建立自己的TAP轉換程序所在目錄
mkdir tap031001
cd tap031001
把tap031111.asn1文件放到該目錄下
asn1c-0.9.27/asn1c/asn1c -fnative-types tap031001.asn1
編譯器會在當前目錄下生成很多.h,.c文件
將該該目錄下的convert-example.c重命名爲自己的文件名,如main.c
#include <stdio.h>
#include <sys/types.h>
#include <DataInterChange.h> /* DataInterChange ASN.1 type */
/*
* This is a custom function which writes the
* encoded output into some FILE stream.
*/
static int
write_out(const void *buffer, size_t size, void *app_key) {
FILE *out_fp = app_key;
size_t wrote;
wrote = fwrite(buffer, 1, size, out_fp);
return (wrote == size) ? 0 : -1;
}
static int decode(const char *filename)
{
char buf[10240]; /* Temporary buffer */
DataInterChange_t *data_inter_change = 0; /* Type to decode */
asn_dec_rval_t rval; /* Decoder return value */
FILE *fp; /* Input file handler */
size_t size; /* Number of bytes read */
/* Open input file as read-only binary */
fp = fopen(filename, "rb");
if(!fp) {
perror(filename);
exit(66); /* better, EX_NOINPUT */
}
/* Read up to the buffer size */
size = fread(buf, 1, sizeof(buf), fp);
fclose(fp);
if(!size) {
fprintf(stderr, "%s: Empty or broken\n", filename);
exit(65); /* better, EX_DATAERR */
}
/* Decode the input buffer as DataInterChange type */
rval = ber_decode(0, &asn_DEF_DataInterChange,
(void **)&data_inter_change, buf, size);
if(rval.code != RC_OK) {
fprintf(stderr,
"%s: Broken DataInterChange encoding at byte %ld\n",
filename, (long)rval.consumed);
exit(65); /* better, EX_DATAERR */
}
/* Print the decoded DataInterChange type as XML */
xer_fprint(stdout, &asn_DEF_DataInterChange, data_inter_change);
return 0;
}
int main(int ac, char **av) {
const char *filename = av[1];
/* BER encode the data if filename is given */
if(ac < 2) {
fprintf(stderr, "Specify filename for BER output\n");
return -1;
}
decode(filename);
return 0; /* Encoding finished successfully */
}
cc -I. -o rdecode *.c
生成執行文件rdecode會直接將tap文件打印成xml文件
後面可以再用php處理這個xml文件
tap3xml
一個perl的轉換庫,最新版本支持tap0312,這個庫是專門轉換tap3文件的
安裝tap3xml的perl支持庫
http://www.tap3edit.com/
wget http://tap3edit.com/download/TAP3-Tap3edit-0.33.tar.gz
wget http://tap3edit.com/download/Convert-ASN1-0.19.tar.gz
wget http://search.cpan.org/CPAN/authors/id/M/MA/MAKAMAKA/JSON-2.90.tar.gz
安裝上面這三個perl庫
perl Makefile.PL
make
make install寫一個tap3話單轉換的prl腳本文件
use JSON;
use TAP3::Tap3edit;
use Data::Dumper;
$Data::Dumper::Indent=1;
$Data::Dumper::Quotekeys=1;
$Data::Dumper::Useqq=1;
$filename=shift;
if ( ! $filename ) {
die "Usage: $0 tapname\n";
}
$tap3 = TAP3::Tap3edit->new();
$tap3->decode($filename) or die $tap3->error;
$struct=$tap3->structure;
$json = JSON->new->encode($struct);
print "$json\n";
exit();
my $key;
# Will scan all the calls for Camel attachments.
foreach $key ( @{$struct->{'transferBatch'}->{'callEventDetails'} } ) {
foreach ( keys %{$key} ) {
print "This call is: $_\n";
print Dumper( $key->{$_} );
}
}
按自己的需要,也可以輸出成json格式
- 同時他也提供了一個tap3xml的C的源代碼
http://www.tap3edit.com/call.php?url=./download/tap3xml-0.18.zip
可以直接將tap文件轉換成xml文件