/[cvs]/nfo/site/htdocs/netfraggle.php
ViewVC logotype

Annotation of /nfo/site/htdocs/netfraggle.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.11 - (hide annotations)
Wed Sep 15 16:39:06 2004 UTC (19 years, 9 months ago) by xabbu
Branch: MAIN
Changes since 1.10: +14 -4 lines
+ function query fixed a bug where the response data structure would be corrupt and thus not be delivered correctly to the client. Important thing I learned from this one that you have parse EACH structure/array item as new XML_RPC_Value individually

1 rabit 1.2 <?php
2     /*------------------------------------------------------------------------------
3     --- www.netfrag.org
4     --- NetFraggle client link page.
5     --------------------------------------------------------------------------------
6     --- rabit, 01:28 24.08.2004
7 joko 1.4 --- joko, 04:05 30.08.2004
8 xabbu 1.11 --- $Id: netfraggle.php,v 1.10 2004/09/13 18:49:02 xabbu Exp $
9 rabit 1.2 ------------------------------------------------------------------------------*/
10    
11 joko 1.4 include('inc/common/common.php.inc');
12 rabit 1.2
13     //------------------------------------------------------------------------------
14    
15     // ...NetFraggle interconnection code...
16 joko 1.4 // by now using XML-RPC, see API-Documentation at:
17     // http://pear.php.net/manual/en/package.webservices.xml-rpc.api.php
18    
19     $type = 'XMLRPC';
20    
21     switch ($type) {
22     case 'XMLRPC':
23 joko 1.5 include('libs/XML/Server.php');
24 joko 1.4 $s = new XML_RPC_Server(array(
25 xabbu 1.8 "query" => array(
26 xabbu 1.10 "function" => "nfo_query"
27 xabbu 1.8 ),
28 joko 1.6 "getContent" => array(
29     "function" => "nfo_get_content",
30     "signature" => array(array('struct', 'string')),
31     ),
32     "listTopics" => array(
33     "function" => "nfo_list_topics",
34     "signature" => array(array('struct', 'struct')),
35     ),
36     "authenticate" => array(
37     "function" => "nfo_authenticate",
38     "signature" => array(array('boolean', 'struct')),
39     ),
40 joko 1.5 "listContents" => array("function" => "nfo_list_contents"),
41     "listUsers" => array("function" => "nfo_list_users"),
42 joko 1.4 ));
43     break;
44 joko 1.5 default:
45 joko 1.4 break;
46     }
47 joko 1.6 #"getContent" => array("function" => "nfo_get_content"),
48     #"signature" => array(array($xmlrpcStruct, $xmlrpcString))
49     #"signature" => array($XML_RPC_Struct, $XML_RPC_String)
50 joko 1.4
51 xabbu 1.8 function nfo_query($params) {
52    
53     $querytxt = $params->getParam(0);
54     $nqlquery = $querytxt->getval();
55     nfo_debug_clean();
56     #nfo_debug_write($params);
57     #nfo_debug_write($nqlquery);
58     $result = array();
59     cms_query($nqlquery,&$result);
60 xabbu 1.10 nfo_debug_write($result);
61 xabbu 1.8
62     $structinfo = array();
63     $structcontent = array();
64     $structfields = array();
65    
66     foreach ($result[0] as $key => $value) {
67     $structinfo[$key] = new XML_RPC_Value($value,"string");
68     }
69 xabbu 1.11
70     #foreach ($result[1] as $key => $value) {
71     #$structcontent[$key] = new XML_RPC_Value($value,"struct");
72     # }
73    
74     foreach ($result[1] as $key => $value) {
75     $cdata = array();
76     foreach($value as $item => $data) {
77     $cdata[$item] = new XML_RPC_Value($data,"string");
78     }
79     $structcontent[$key] = new XML_RPC_Value($cdata,"struct");
80     }
81    
82 xabbu 1.8 foreach ($result[2] as $key => $value) {
83     $structfields[$key] = new XML_RPC_Value($value,"string");
84     }
85     $struct = array();
86     $struct[0] = new XML_RPC_Value($structinfo,"struct");
87     $struct[1] = new XML_RPC_Value($structcontent,"struct");
88     $struct[2] = new XML_RPC_Value($structfields,"struct");
89    
90     $xmldoc = new XML_RPC_Response(new XML_RPC_Value($struct, "struct"));
91     nfo_debug_write($xmldoc);
92     #nfo_debug_write($xmldoc->serialize());
93    
94     return $xmldoc;
95    
96     }
97    
98 joko 1.4
99 joko 1.6 function nfo_get_content($params) {
100     $ck = $params->getParam(0);
101     $ck = $ck->scalarval();
102 joko 1.5 #nfo_debug_clean();
103 joko 1.6 #nfo_debug_write($ck);
104 joko 1.5 $content = cms_getcontent('xmlpage', $ck);
105 joko 1.6 #nfo_debug_write($content);
106 joko 1.5 #return new XML_RPC_Response(new XML_RPC_Value("content", "string"));
107     $struct = array();
108     foreach ($content as $key => $value) {
109     $struct[$key] = new XML_RPC_Value($value, "string");
110     }
111     $xmldoc = new XML_RPC_Response(new XML_RPC_Value($struct, "struct"));
112     return $xmldoc;
113 joko 1.4 }
114 joko 1.6
115     function nfo_list_topics($params) {
116 xabbu 1.8 nfo_debug_clean();
117     nfo_debug_write($params);
118     nfo_debug_write("list_topics");
119 joko 1.6 $meta = $params->getParam(0);
120 xabbu 1.8 nfo_debug_write($meta);
121 joko 1.6 $type = $meta->structmem('type');
122     $type = $type->scalarval();
123     #nfo_debug_write("$type");
124     $res = cms_getindex($type);
125 joko 1.7 #nfo_debug_write($res);
126 joko 1.6 $newentries = array();
127     $tmp = new XML_RPC_Value();
128     foreach ($res as $entry) {
129     $newentry = array();
130     foreach ($entry as $key => $value) {
131     $newvalue = new XML_RPC_Value($value, 'string');
132     $newentry[$key] = $newvalue;
133     }
134     #$tmp->addStruct($newentry);
135     array_push($newentries, new XML_RPC_Value($newentry, 'struct'));
136     }
137     $final = new XML_RPC_Value($newentries, 'array');
138     #$final->addArray($tmp);
139     #nfo_debug_write($final);
140     #$res = array('key' => new XML_RPC_Value('value', 'string'));
141     $msg = new XML_RPC_Response($final);
142     #nfo_debug_write($msg);
143     return $msg;
144     }
145    
146     function nfo_authenticate($params) {
147     global $common_sessiondata;
148     #nfo_debug_clean();
149     #nfo_debug_write($params);
150     $meta = $params->getParam(0);
151     $user = $meta->structmem('user');
152     $user = $user->scalarval();
153     $pass = $meta->structmem('pass');
154     $pass = $pass->scalarval();
155     $common_sessiondata['userdata']['name'] = $user;
156     $common_sessiondata['userdata']['password'] = $pass;
157 joko 1.7 #nfo_debug_write($common_sessiondata);
158 joko 1.6 $retval = common_checkauthorisation();
159     return new XML_RPC_Response(new XML_RPC_Value($retval, 'boolean'));
160     }
161    
162     function nfo_list_contents() {
163     }
164    
165 joko 1.4 function nfo_list_users() {
166 joko 1.5 }
167    
168     function nfo_debug_clean() {
169 joko 1.6 `rm dump`;
170 joko 1.5 }
171    
172     function nfo_debug_write($data) {
173     ob_start();
174     print_r($data);
175     $data = ob_get_clean();
176 joko 1.6 $f = fopen('dump', 'a');
177     fputs($f, $data . "\n");
178 joko 1.5 fclose($f);
179 joko 1.4 }
180 rabit 1.2
181     //------------------------------------------------------------------------------
182    
183     ?>

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed