root/trunk/midgard/apis/php5/php_midgard_compat.c

Revision 13806, 3.4 kB (checked in by piotras, 1 year ago)

Added replicator bindings.
Added midgard_connection_set(get)_lang

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 /*
2  * Copyright (C) 2007 Piotr Pokora <piotrek.pokora@gmail.com>
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU Lesser General Public License as published
6  * by the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18
19 #include "php_midgard_compat.h"
20
21 PHP_FUNCTION(mgd_version)
22 {
23         RETVAL_NULL();
24
25         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") != SUCCESS)
26                 return;
27        
28         const gchar *version = midgard_version();
29        
30         if(!version)
31                 version = "";
32
33         RETURN_STRING((gchar *)version, 1);
34 }
35
36 PHP_FUNCTION(mgd_errno)
37 {
38         CHECK_MGD;
39        
40         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") != SUCCESS)
41                 return;
42
43         MidgardConnection *mgd = mgd_handle();
44        
45         RETURN_LONG(mgd->errnum);
46 }
47
48 PHP_FUNCTION(mgd_errstr)
49 {
50         CHECK_MGD;
51        
52         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") != SUCCESS)
53                 return;
54
55         MidgardConnection *mgd = mgd_handle();
56        
57         RETURN_STRING(mgd->errstr, 1);
58 }
59
60 PHP_FUNCTION(mgd_auth_midgard)
61 {
62         CHECK_MGD;
63         RETVAL_FALSE;
64        
65         php_error(E_NOTICE,
66                         "mgd_auth_midgard is obsolete. Use midgard_user::auth instead.");
67
68         gchar *username, *password , *sgname = NULL;
69         guint username_length, password_length;
70         guint oldcookie;
71         MidgardConnection *mgd = mgd_handle();
72
73         if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|l",
74                                                 &username, &username_length,
75                                                 &password, &password_length,
76                                                 &oldcookie) == FAILURE) {
77                 return;
78         }
79        
80         /* TODO, split username ( to get SG name ) if needed */
81
82         MidgardUser *user =
83                 midgard_user_auth(mgd, username, password,
84                                 sgname, FALSE);
85
86         if(!user)
87                 RETURN_FALSE;
88
89         /* It's important to initialize *any* object here.
90          * MidgardUser will be automagicaly unref'ed at request end */
91
92         zval *zobject = NULL;
93         php_midgard_gobject_init(zobject, "midgard_user", G_OBJECT(user), TRUE);
94
95         RETURN_TRUE;
96 }
97
98 PHP_FUNCTION(mgd_unsetuid)
99 {
100         CHECK_MGD;
101         RETVAL_FALSE;
102
103         php_error(E_NOTICE, "mgd_unsetuid is obsolete.");
104 }
105
106 PHP_FUNCTION(mgd_issetuid)
107 {
108         CHECK_MGD;
109         RETVAL_FALSE;
110
111         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") != SUCCESS)
112                 return;
113
114         /*
115         gint setuid = 3;
116         MidgardConnection *mgd = mgd_handle(); */
117
118         php_error(E_NOTICE, "mgd_issetuid is obsolete.");
119 }
120
121 PHP_FUNCTION(mgd_set_lang)
122 {
123         CHECK_MGD;
124         RETVAL_FALSE;
125         gint langid;
126         MidgardConnection *mgd = mgd_handle();
127
128         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
129                                 "l", &langid) == FAILURE)
130                 return;
131        
132         if(langid < 0) {
133                 php_error(E_WARNING, "Ignoring negative language id (%d)", langid);
134                 RETURN_FALSE;
135         }
136        
137         const gchar *language =
138                 midgard_connection_get_lang_from_id(mgd, (guint)langid);
139
140         gboolean rv = midgard_connection_set_lang(mgd, language);
141
142         RETURN_BOOL(rv);
143 }
144
145 PHP_FUNCTION(mgd_get_lang)
146 {
147         CHECK_MGD;
148         RETVAL_FALSE;
149         MidgardConnection *mgd = mgd_handle();
150        
151         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") != SUCCESS)
152                 return;
153
154         guint langid =
155                 midgard_connection_get_lang_id(mgd, NULL);
156
157         RETURN_LONG(langid);
158 }
Note: See TracBrowser for help on using the browser.