1 /*
2    +----------------------------------------------------------------------+
3    | Copyright (c) The PHP Group                                          |
4    +----------------------------------------------------------------------+
5    | This source file is subject to version 3.01 of the PHP license,      |
6    | that is bundled with this package in the file LICENSE, and is        |
7    | available through the world-wide-web at the following url:           |
8    | http://www.php.net/license/3_01.txt                                  |
9    | If you did not receive a copy of the PHP license and are unable to   |
10    | obtain it through the world-wide-web, please send a note to          |
11    | license@php.net so we can mail you a copy immediately.               |
12    +----------------------------------------------------------------------+
13    | Authors:                                                             |
14    |         Omar Shaban <omars@php.net>                                  |
15    |         Israel Ekpo <iekpo@php.net>                                  |
16    +----------------------------------------------------------------------+
17 */
18 
19 #include "php_solr.h"
20 
21 /* {{{ void solr_debug_printf(const char *format, ...) */
solr_debug_printf(const char * format,...)22 PHP_SOLR_API void solr_debug_printf(const char *format, ...)
23 {
24 #ifdef SOLR_DEBUG
25 	va_list args;
26 	va_start(args,format);
27 	vprintf(format,args);
28 	va_end(args);
29 #endif
30 }
31 /* }}} */
32 
33 /* {{{ void solr_debug_print_fields(const solr_field_list_t *field_list) */
solr_debug_print_fields(const solr_field_list_t * field_list)34 PHP_SOLR_API void solr_debug_print_fields(const solr_field_list_t *field_list)
35 {
36 	/* Used to debug field inserted */
37 }
38 /* }}} */
39 
40 /**
41  * print_xpath_nodes:
42  * @nodes:      the nodes set.
43  * @output:     the output file handle.
44  *
45  * Prints the @nodes content to @output.
46  */
47 /* {{{ void print_xpath_nodes(xmlNodeSetPtr nodes, FILE* output) */
print_xpath_nodes(xmlNodeSetPtr nodes,FILE * output)48 PHP_SOLR_API void print_xpath_nodes(xmlNodeSetPtr nodes, FILE* output) {
49     xmlNodePtr cur;
50     int size;
51     int i;
52 
53     assert(output);
54     size = (nodes) ? nodes->nodeNr : 0;
55 
56     fprintf(output, "Result (%d nodes):\n", size);
57     for(i = 0; i < size; ++i) {
58         assert(nodes->nodeTab[i]);
59 
60         if(nodes->nodeTab[i]->type == XML_NAMESPACE_DECL) {
61             xmlNsPtr ns;
62 
63             ns = (xmlNsPtr)nodes->nodeTab[i];
64             cur = (xmlNodePtr)ns->next;
65             if(cur->ns) {
66                 fprintf(output, "= namespace \"%s\"=\"%s\" for node %s:%s\n",
67                         ns->prefix, ns->href, cur->ns->href, cur->name);
68             } else {
69                 fprintf(output, "= namespace \"%s\"=\"%s\" for node %s\n",
70                         ns->prefix, ns->href, cur->name);
71             }
72         } else if(nodes->nodeTab[i]->type == XML_ELEMENT_NODE) {
73             cur = nodes->nodeTab[i];
74             if(cur->ns) {
75                 fprintf(output, "= element node \"%s:%s\"\n",
76                         cur->ns->href, cur->name);
77             } else {
78                 fprintf(output, "= element node \"%s\"\n",
79                         cur->name);
80             }
81         } else {
82             cur = nodes->nodeTab[i];
83             fprintf(output, "= node \"%s\": type %d\n", cur->name, cur->type);
84         }
85     }
86 }
87 /* }}} */
88 
89 /* {{{ void print_children (xmlNode * node) */
print_children(xmlNode * node)90 PHP_SOLR_API void print_children (xmlNode * node)
91 {
92     fprintf(stdout,"\n================- start print children -=================\n");
93     while (node != NULL)
94     {
95         if(node->ns) {
96             fprintf(stdout, "= element node \"%s:%s\"\n",
97                     node->ns->href,node->name);
98         } else {
99             fprintf(stdout, "= element node \"%s\"\n",
100                     node->name);
101         }
102 
103         if(node->type == XML_ELEMENT_NODE){
104             xmlNode * cur2 = node->children;
105             while (cur2 != NULL)
106             {
107                 if(strcmp((const char *)cur2->name,"text")==0)
108                 {
109                     fprintf(stdout, "= element node \"%s\", text: %s\n",cur2->name,cur2->content);
110                 }else{
111                     fprintf(stdout, "= element node \"%s\"\n",
112                             cur2->name);
113                 }
114                 cur2 = cur2->next;
115             }
116         }
117 
118         if(node->children != NULL)
119         {
120             print_children(node->children);
121         }
122 
123         node = node->next;
124     }
125     fprintf(stdout,"\n======================- end -=====================\n");
126 }
127 /* }}} */
128 
129 /*
130  * Local variables:
131  * tab-width: 4
132  * c-basic-offset: 4
133  * End:
134  * vim600: fdm=marker
135  * vim: noet sw=4 ts=4
136  */
137