-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy pathcred.c
140 lines (117 loc) · 3.83 KB
/
cred.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include "php_git2.h"
#include "php_git2_priv.h"
#include "cred.h"
/* {{{ proto long git_cred_has_username(resource $cred)
*/
PHP_FUNCTION(git_cred_has_username)
{
int result = 0;
zval *cred = NULL;
php_git2_t *_cred = NULL;
int error = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"r", &cred) == FAILURE) {
return;
}
ZEND_FETCH_RESOURCE(_cred, php_git2_t*, &cred, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
result = git_cred_has_username(PHP_GIT2_V(_cred, cred));
RETURN_BOOL(result);
}
/* }}} */
/* {{{ proto resource git_cred_userpass_plaintext_new(string $username, string $password)
*/
PHP_FUNCTION(git_cred_userpass_plaintext_new)
{
php_git2_t *result = NULL;
git_cred *out = NULL;
char *username = NULL, *password = NULL;
int username_len = 0, password_len = 0, error = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"ss", &username, &username_len, &password, &password_len) == FAILURE) {
return;
}
error = git_cred_userpass_plaintext_new(&out, username, password);
if (php_git2_check_error(error, "git_cred_userpass_plaintext_new" TSRMLS_CC)) {
RETURN_FALSE;
}
if (php_git2_make_resource(&result, PHP_GIT2_TYPE_CRED, out, 0 TSRMLS_CC)) {
RETURN_FALSE;
}
ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result));
}
/* }}} */
/* {{{ proto resource git_cred_ssh_key_new(string $username, string $publickey, string $privatekey, string $passphrase)
*/
PHP_FUNCTION(git_cred_ssh_key_new)
{
php_git2_t *result = NULL;
git_cred *out = NULL;
char *username = NULL, *publickey = NULL, *privatekey = NULL, *passphrase = NULL;
int username_len = 0, publickey_len = 0, privatekey_len = 0, passphrase_len = 0, error = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"ssss", &username, &username_len, &publickey, &publickey_len, &privatekey, &privatekey_len, &passphrase, &passphrase_len) == FAILURE) {
return;
}
error = git_cred_ssh_key_new(&out, username, publickey, privatekey, passphrase);
if (php_git2_check_error(error, "git_cred_ssh_key_new" TSRMLS_CC)) {
RETURN_FALSE;
}
if (php_git2_make_resource(&result, PHP_GIT2_TYPE_CRED, out, 0 TSRMLS_CC)) {
RETURN_FALSE;
}
ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result));
}
/* }}} */
/* {{{ proto resource git_cred_ssh_custom_new(username, publickey, publickey_len, sign_fn, sign_data)
*/
PHP_FUNCTION(git_cred_ssh_custom_new)
{
char *username = {0};
int username_len;
char *publickey = {0};
int publickey_len;
zval *sign_fn;
php_git2_t *_sign_fn;
/* TODO(chobie): implement this */
php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_cred_ssh_custom_new not implemented yet");
return;
// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
// "ssr", &username, &username_len, &publickey, &publickey_len, &publickey_len, &sign_fn, &sign_data) == FAILURE) {
// return;
// }
// ZEND_FETCH_RESOURCE(_username, php_git2_t*, &username, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
}
/* {{{ proto resource git_cred_default_new()
*/
PHP_FUNCTION(git_cred_default_new)
{
php_git2_t *result = NULL;
git_cred *out = NULL;
int error = 0;
error = git_cred_default_new(&out);
if (php_git2_check_error(error, "git_cred_default_new" TSRMLS_CC)) {
RETURN_FALSE;
}
if (php_git2_make_resource(&result, PHP_GIT2_TYPE_CRED, out, 0 TSRMLS_CC)) {
RETURN_FALSE;
}
ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result));
}
/* }}} */
/* {{{ proto resource git_cred_userpass(url, user_from_url, allowed_types, payload)
*/
PHP_FUNCTION(git_cred_userpass)
{
char *url = {0};
int url_len;
char *user_from_url = {0};
int user_from_url_len;
long allowed_types;
/* TODO(chobie): implement this */
php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_cred_userpass not implemented yet");
return;
// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
// "ssl", &url, &url_len, &user_from_url, &user_from_url_len, &allowed_types, &payload) == FAILURE) {
// return;
// }
}