Skip to content

Commit 0d993a8

Browse files
author
Evan Klinger
committed
@- Added CyberCash support. (Evan)
CyberCash support.
1 parent ef596bb commit 0d993a8

File tree

7 files changed

+521
-0
lines changed

7 files changed

+521
-0
lines changed

ext/cybercash/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
noinst_LTLIBRARIES=libphpext_cybercash.la
2+
libphpext_cybercash_la_SOURCES=cybercash.c

ext/cybercash/config.h.stub

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#define HAVE_MCK 0

ext/cybercash/config.m4

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
dnl config.m4 for extension CyberCash
2+
dnl don't forget to call PHP_EXTENSION(cybercash)
3+
4+
AC_MSG_CHECKING(for CyberCash support)
5+
AC_ARG_WITH(cybercash,
6+
[ --with-cybercash[=DIR] Include CyberCash support. DIR is the CyberCash MCK
7+
install directory.],
8+
[
9+
if test "$withval" != "no"; then
10+
test -f $withval/mckcrypt.h && MCK_DIR="$withval"
11+
test -f $withval/c-api/mckcrypt.h && MCK_DIR="$withval/c-api"
12+
if test -n "$MCK_DIR"; then
13+
AC_MSG_RESULT(yes)
14+
PHP_EXTENSION(cybercash)
15+
LIBS="$LIBS -L$withval/lib"
16+
AC_ADD_LIBRARY_WITH_PATH(mckcrypto, $MCK_DIR/lib)
17+
AC_ADD_INCLUDE($MCK_DIR)
18+
AC_DEFINE(HAVE_MCK)
19+
else
20+
AC_MSG_ERROR(Please reinstall the CyberCash MCK - I cannot find mckcrypt.h)
21+
AC_MSG_RESULT(no)
22+
fi
23+
fi
24+
],[
25+
AC_MSG_RESULT(no)
26+
])

ext/cybercash/cybercash.c

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
/*
2+
+----------------------------------------------------------------------+
3+
| PHP HTML Embedded Scripting Language Version 3.0 |
4+
+----------------------------------------------------------------------+
5+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
6+
+----------------------------------------------------------------------+
7+
| This program is free software; you can redistribute it and/or modify |
8+
| it under the terms of one of the following licenses: |
9+
| |
10+
| A) the GNU General Public License as published by the Free Software |
11+
| Foundation; either version 2 of the License, or (at your option) |
12+
| any later version. |
13+
| |
14+
| B) the PHP License as published by the PHP Development Team and |
15+
| included in the distribution in the file: LICENSE |
16+
| |
17+
| This program is distributed in the hope that it will be useful, |
18+
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
19+
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
20+
| GNU General Public License for more details. |
21+
| |
22+
| You should have received a copy of both licenses referred to here. |
23+
| If you did not, or have any questions about PHP licensing, please |
24+
| contact core@php.net. |
25+
+----------------------------------------------------------------------+
26+
| Authors: Evan Klinger <evan715@sirius.com> |
27+
| Timothy Whitfield <timothy@ametro.net> |
28+
+----------------------------------------------------------------------+
29+
*/
30+
31+
#include "php.h"
32+
33+
#if HAVE_MCK
34+
#include "cybercash.h"
35+
#include "mckcrypt.h"
36+
37+
function_entry cybercash_functions[] = {
38+
PHP_FE(cybercash_encr, NULL)
39+
PHP_FE(cybercash_decr, NULL)
40+
PHP_FE(cybercash_base64_encode, NULL)
41+
PHP_FE(cybercash_base64_decode, NULL)
42+
{0}
43+
};
44+
45+
zend_module_entry cybercash_module_entry = {
46+
"CyberCash",
47+
cybercash_functions,
48+
NULL,NULL,
49+
NULL,NULL,
50+
NULL,
51+
STANDARD_MODULE_PROPERTIES,
52+
};
53+
54+
PHP_FUNCTION(cybercash_encr)
55+
{
56+
pval **wmk, **sk, **inbuff;
57+
unsigned char *outbuff, *macbuff;
58+
unsigned int outAlloc, outLth;
59+
long errcode;
60+
61+
if(ARG_COUNT(ht) != 3 || getParametersEx(3,&wmk,&sk,&inbuff) == FAILURE) {
62+
WRONG_PARAM_COUNT;
63+
}
64+
65+
convert_to_string_ex(wmk);
66+
convert_to_string_ex(sk);
67+
convert_to_string_ex(inbuff);
68+
69+
outAlloc = (*inbuff)->value.str.len + 10;
70+
71+
outbuff = (unsigned char *)emalloc(outAlloc);
72+
macbuff = (unsigned char *)emalloc(20);
73+
74+
errcode = mck_encr((*wmk)->value.str.val,(*sk)->value.str.val,
75+
(*inbuff)->value.str.len+1,
76+
(*inbuff)->value.str.val,
77+
outAlloc,
78+
outbuff,
79+
&outLth,
80+
macbuff);
81+
82+
array_init(return_value);
83+
84+
add_assoc_long(return_value,"errcode",errcode);
85+
86+
if(!errcode)
87+
{
88+
add_assoc_stringl(return_value,"outbuff",outbuff,outLth,0);
89+
add_assoc_long(return_value,"outLth",outLth);
90+
add_assoc_stringl(return_value,"macbuff",macbuff,20,0);
91+
}
92+
else
93+
{
94+
efree(outbuff);
95+
efree(macbuff);
96+
}
97+
}
98+
99+
PHP_FUNCTION(cybercash_decr)
100+
{
101+
pval **wmk,**sk,**inbuff;
102+
unsigned char *outbuff, *macbuff;
103+
unsigned int outAlloc, outLth;
104+
long errcode;
105+
106+
107+
if(ARG_COUNT(ht) != 3 || getParametersEx(3,&wmk,&sk,&inbuff) == FAILURE)
108+
{
109+
WRONG_PARAM_COUNT;
110+
}
111+
112+
convert_to_string_ex(wmk);
113+
convert_to_string_ex(sk);
114+
convert_to_string_ex(inbuff);
115+
116+
outAlloc=(*inbuff)->value.str.len;
117+
118+
outbuff=(unsigned char *)emalloc(outAlloc);
119+
macbuff=(unsigned char *)emalloc(20);
120+
121+
errcode=mck_decr((*wmk)->value.str.val,
122+
(*sk)->value.str.val,
123+
(*inbuff)->value.str.len,
124+
(*inbuff)->value.str.val,
125+
outAlloc,
126+
outbuff,
127+
&outLth,
128+
macbuff);
129+
130+
array_init(return_value);
131+
132+
add_assoc_long(return_value,"errcode",errcode);
133+
134+
if(!errcode) {
135+
add_assoc_stringl(return_value,"outbuff",outbuff,outLth,0);
136+
add_assoc_long(return_value,"outLth",outLth);
137+
add_assoc_stringl(return_value,"macbuff",macbuff,20,0);
138+
}
139+
else
140+
{
141+
efree(outbuff);
142+
efree(macbuff);
143+
}
144+
}
145+
146+
PHP_FUNCTION(cybercash_base64_encode)
147+
{
148+
pval **inbuff;
149+
char *outbuff;
150+
long ret_length;
151+
152+
if(ARG_COUNT(ht) != 1 ||
153+
getParametersEx(1,&inbuff) == FAILURE)
154+
{
155+
WRONG_PARAM_COUNT;
156+
}
157+
158+
convert_to_string_ex(inbuff);
159+
160+
outbuff=(char *)emalloc(
161+
base64_enc_size((unsigned int)(*inbuff)->value.str.len));
162+
163+
ret_length=base64_encode(outbuff,
164+
(*inbuff)->value.str.val,(*inbuff)->value.str.len);
165+
166+
return_value->value.str.val=outbuff;
167+
return_value->value.str.len=ret_length;
168+
return_value->type=IS_STRING;
169+
170+
}
171+
172+
PHP_FUNCTION(cybercash_base64_decode)
173+
{
174+
pval **inbuff;
175+
char *outbuff;
176+
long ret_length;
177+
178+
if(ARG_COUNT(ht) != 1 ||
179+
getParametersEx(1,&inbuff) == FAILURE)
180+
{
181+
WRONG_PARAM_COUNT;
182+
}
183+
184+
convert_to_string_ex(inbuff);
185+
186+
outbuff=(char *)emalloc(
187+
base64_dec_size((unsigned int)(*inbuff)->value.str.len));
188+
189+
ret_length=base64_decode(outbuff,
190+
(*inbuff)->value.str.val,(*inbuff)->value.str.len);
191+
192+
return_value->value.str.val=outbuff;
193+
return_value->value.str.len=ret_length;
194+
return_value->type=IS_STRING;
195+
196+
}
197+
#endif

ext/cybercash/cybercash.h

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
+----------------------------------------------------------------------+
3+
| PHP HTML Embedded Scripting Language Version 3.0 |
4+
+----------------------------------------------------------------------+
5+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
6+
+----------------------------------------------------------------------+
7+
| This program is free software; you can redistribute it and/or modify |
8+
| it under the terms of one of the following licenses: |
9+
| |
10+
| A) the GNU General Public License as published by the Free Software |
11+
| Foundation; either version 2 of the License, or (at your option) |
12+
| any later version. |
13+
| |
14+
| B) the PHP License as published by the PHP Development Team and |
15+
| included in the distribution in the file: LICENSE |
16+
| |
17+
| This program is distributed in the hope that it will be useful, |
18+
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
19+
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
20+
| GNU General Public License for more details. |
21+
| |
22+
| You should have received a copy of both licenses referred to here. |
23+
| If you did not, or have any questions about PHP licensing, please |
24+
| contact core@php.net. |
25+
+----------------------------------------------------------------------+
26+
| Authors: Evan Klinger <evan715@sirius.com> |
27+
+----------------------------------------------------------------------+
28+
*/
29+
30+
#ifndef _CYBERCASH_H
31+
#define _CYBERCASH_H
32+
33+
34+
#if HAVE_MCK
35+
36+
#if PHP_API_VERSION < 19990421
37+
#define zend_module_entry cybercash_module_entry
38+
#include "modules.h"
39+
#include "internal_functions.h"
40+
#endif
41+
42+
extern zend_module_entry cybercash_module_entry;
43+
#define cybercash_module_ptr &cybercash_module_entry
44+
45+
PHP_FUNCTION(cybercash_encr);
46+
PHP_FUNCTION(cybercash_decr);
47+
PHP_FUNCTION(cybercash_base64_encode);
48+
PHP_FUNCTION(cybercash_base64_decode);
49+
50+
#else
51+
#define cybercash_module_ptr NULL
52+
#endif
53+
54+
#define phpext_cybercash_ptr cybercash_module_ptr
55+
56+
#endif

0 commit comments

Comments
 (0)