~ubuntu-branches/debian/jessie/openchange/jessie

« back to all changes in this revision

Viewing changes to php/mapi_attachment_table.c

  • Committer: Package Import Robot
  • Author(s): Jelmer Vernooij
  • Date: 2014-08-15 02:48:41 UTC
  • mfrom: (1.2.9)
  • Revision ID: package-import@ubuntu.com-20140815024841-egnb9akqjw7jvrsl
Tags: 1:2.2-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
   OpenChange MAPI PHP bindings
 
3
 
 
4
   Copyright (C) 2013 Javier Amor Garcia.
 
5
 
 
6
   This program is free software; you can redistribute it and/or modify
 
7
   it under the terms of the GNU General Public License as published by
 
8
   the Free Software Foundation; either version 3 of the License, or
 
9
   (at your option) any later version.
 
10
 
 
11
   This program is distributed in the hope that it will be useful,
 
12
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
   GNU General Public License for more details.
 
15
 
 
16
   You should have received a copy of the GNU General Public License
 
17
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
 */
 
19
 
 
20
#include <php_mapi.h>
 
21
 
 
22
static zend_function_entry mapi_attachment_table_class_functions[] = {
 
23
        PHP_ME(MAPIAttachmentTable,     __construct,    NULL, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
 
24
        PHP_ME(MAPIAttachmentTable,     getAttachments, NULL, ZEND_ACC_PUBLIC)
 
25
        PHP_ME(MAPIAttachmentTable,     getParentFolder,NULL, ZEND_ACC_PUBLIC)
 
26
        PHP_ME(MAPIAttachmentTable,   count,          NULL, ZEND_ACC_PUBLIC)
 
27
        { NULL, NULL, NULL }
 
28
};
 
29
 
 
30
static zend_class_entry         *mapi_attachment_table_ce;
 
31
static zend_object_handlers     mapi_attachment_table_object_handlers;
 
32
 
 
33
void MAPIAttachmentTableRegisterClass(TSRMLS_D)
 
34
{
 
35
        zend_class_entry        ce;
 
36
 
 
37
        INIT_CLASS_ENTRY(ce, "MAPIAttachmentTable", mapi_attachment_table_class_functions);
 
38
        mapi_attachment_table_ce = zend_register_internal_class_ex(&ce, NULL, "mapitable" TSRMLS_CC);
 
39
        mapi_attachment_table_ce->create_object = mapi_table_create_handler;
 
40
        memcpy(&mapi_attachment_table_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
 
41
 
 
42
        MAPITableClassSetObjectHandlers(&mapi_attachment_table_object_handlers);
 
43
        mapi_attachment_table_object_handlers.clone_obj = NULL;
 
44
}
 
45
 
 
46
zval *create_attachment_table_object(zval* parent, mapi_object_t* attachment_table TSRMLS_DC)
 
47
{
 
48
        int                     i;
 
49
        struct SPropTagArray    *tag_array;
 
50
        mapi_table_object_t     *new_obj;
 
51
        TALLOC_CTX              *mem_ctx;
 
52
 
 
53
        mem_ctx =   talloc_named(NULL, 0, "attachment_table");
 
54
        tag_array = set_SPropTagArray(mem_ctx, 1,  PR_ATTACH_NUM);
 
55
 
 
56
        zval *new_php_obj = create_table_object("mapiattachmenttable", parent, attachment_table,
 
57
                                                mem_ctx, tag_array, 0 TSRMLS_CC);
 
58
        new_obj = (mapi_table_object_t*)  zend_object_store_get_object(new_php_obj TSRMLS_CC);
 
59
        new_obj->type = ATTACHMENTS;
 
60
 
 
61
        return new_php_obj;
 
62
}
 
63
 
 
64
PHP_METHOD(MAPIAttachmentTable, __construct)
 
65
{
 
66
        php_error(E_ERROR, "The attachment message object should not be created directly.");
 
67
}
 
68
 
 
69
 
 
70
 
 
71
PHP_METHOD(MAPIAttachmentTable, getParentFolder)
 
72
{
 
73
        php_error(E_ERROR, "This method cannot be called in an attachment table");
 
74
}
 
75
 
 
76
 
 
77
PHP_METHOD(MAPIAttachmentTable, getAttachments)
 
78
{
 
79
        struct SRowSet          row_set;
 
80
        enum MAPISTATUS         retval;
 
81
        zval                    *res;
 
82
        uint32_t                i;
 
83
        const uint32_t          *attach_num;
 
84
        long                    countParam;
 
85
        uint32_t                count;
 
86
        zval                    *message;
 
87
        zval                    *attachment;
 
88
        mapi_table_object_t     *this_obj;
 
89
 
 
90
 
 
91
        countParam = -1;
 
92
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
 
93
                               "|l", &countParam) == FAILURE) {
 
94
                RETURN_NULL();
 
95
        }
 
96
 
 
97
        count = (countParam > 0) ? (uint32_t) countParam : 50;
 
98
        this_obj = THIS_STORE_OBJECT(mapi_table_object_t*);
 
99
        message  = this_obj->parent;
 
100
 
 
101
        MAKE_STD_ZVAL(res);
 
102
        array_init(res);
 
103
 
 
104
        while (mapi_table_next_row_set(this_obj->table, &row_set, count TSRMLS_CC)) {
 
105
                for (i = 0; i < row_set.cRows; i++) {
 
106
                        attach_num = (const uint32_t *)find_SPropValue_data(&(row_set.aRow[i]), PR_ATTACH_NUM);
 
107
                        attachment = mapi_message_get_attachment(message, *attach_num TSRMLS_CC);
 
108
                        if (attachment) {
 
109
                                add_next_index_zval(res, attachment);
 
110
                        }
 
111
                }
 
112
 
 
113
                if (countParam > 0) {
 
114
                        break;  // no unlimited
 
115
                }
 
116
        }
 
117
 
 
118
        RETURN_ZVAL(res, 0, 1);
 
119
}
 
120
 
 
121
PHP_METHOD(MAPIAttachmentTable, count)
 
122
{
 
123
        php_error(E_ERROR, "This method is not available for attachments tables");
 
124
}