-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy pathblob.c
131 lines (105 loc) · 4.04 KB
/
blob.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
/*
* The MIT License
*
* Copyright (c) 2010 - 2011 Shuhei Tanuma
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "php_git.h"
#include <spl/spl_array.h>
#include <zend_interfaces.h>
#include <string.h>
#include <time.h>
zend_class_entry *git_blob_class_entry;
ZEND_BEGIN_ARG_INFO_EX(arginfo_git_blob__construct, 0, 0, 1)
ZEND_ARG_INFO(0, repository)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_git_blob_set_content, 0, 0, 1)
ZEND_ARG_INFO(0, string)
ZEND_END_ARG_INFO()
static void php_git_blob_free_storage(php_git_blob_t *obj TSRMLS_DC)
{
zend_object_std_dtor(&obj->zo TSRMLS_CC);
//obj->object will free by git_repository.
obj->object = NULL;
efree(obj);
}
zend_object_value php_git_blob_new(zend_class_entry *ce TSRMLS_DC)
{
zend_object_value retval;
php_git_repository_t *obj;
zval *tmp;
obj = ecalloc(1, sizeof(*obj));
zend_object_std_init( &obj->zo, ce TSRMLS_CC );
zend_hash_copy(obj->zo.properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));
retval.handle = zend_objects_store_put(obj,
(zend_objects_store_dtor_t)zend_objects_destroy_object,
(zend_objects_free_object_storage_t)php_git_blob_free_storage,
NULL TSRMLS_CC);
retval.handlers = zend_get_std_object_handlers();
return retval;
}
PHP_METHOD(git_blob, __construct)
{
zval *z_repository;
php_git_repository_t *git;
php_git_blob_t *obj;
int ret;
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"z", &z_repository) == FAILURE){
return;
}
git = (php_git_repository_t *) zend_object_store_get_object(z_repository TSRMLS_CC);
obj = (php_git_blob_t *) zend_object_store_get_object(getThis() TSRMLS_CC);
ret = git_blob_new(&obj->object,git->repository);
if(ret != GIT_SUCCESS){
php_error_docref(NULL TSRMLS_CC, E_WARNING,"Can't create new blob!");
return;
}
}
PHP_METHOD(git_blob, setContent)
{
char *string;
size_t string_len = 0;
php_git_blob_t *obj;
int ret;
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"s", &string, &string_len) == FAILURE){
return;
}
obj = (php_git_blob_t *) zend_object_store_get_object(getThis() TSRMLS_CC);
ret = git_blob_set_rawcontent(obj->object,string, string_len);
if(ret != GIT_SUCCESS){
php_error_docref(NULL TSRMLS_CC, E_WARNING,"Can't set content!");
return;
}
add_property_string_ex(getThis(), "data", sizeof("data"),string, 1 TSRMLS_CC);
}
zend_function_entry php_git_blob_methods[] = {
PHP_ME(git_blob, __construct, arginfo_git_blob__construct, ZEND_ACC_PUBLIC)
PHP_ME(git_blob, setContent, arginfo_git_blob_set_content, ZEND_ACC_PUBLIC)
{NULL, NULL, NULL}
};
void git_init_blob(TSRMLS_D)
{
zend_class_entry ce;
INIT_NS_CLASS_ENTRY(ce, PHP_GIT_NS,"Blob", php_git_blob_methods);
git_blob_class_entry = zend_register_internal_class_ex(&ce, git_object_class_entry, NULL TSRMLS_CC);
git_blob_class_entry->create_object = php_git_blob_new;
}