/[hyperestraier]/upstream/0.5.0/estnode.h
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /upstream/0.5.0/estnode.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (show annotations)
Fri Jul 29 21:52:03 2005 UTC (18 years, 9 months ago) by dpavlin
File MIME type: text/plain
File size: 20707 byte(s)
import of HyperEstraier 0.5.0

1 /*************************************************************************************************
2 * The node API of Hyper Estraier
3 * Copyright (C) 2004-2005 Mikio Hirabayashi
4 * This file is part of Hyper Estraier.
5 * Hyper Estraier is free software; you can redistribute it and/or modify it under the terms of
6 * the GNU Lesser General Public License as published by the Free Software Foundation; either
7 * version 2.1 of the License or any later version. Hyper Estraier is distributed in the hope
8 * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10 * License for more details.
11 * You should have received a copy of the GNU Lesser General Public License along with Hyper
12 * Estraier; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
13 * Boston, MA 02111-1307 USA.
14 *************************************************************************************************/
15
16
17 #ifndef _ESTNODE_H /* duplication check */
18 #define _ESTNODE_H
19
20 #if defined(__cplusplus) /* export for C++ */
21 extern "C" {
22 #endif
23
24
25 #include <estraier.h>
26 #include <estmtdb.h>
27 #include <cabin.h>
28 #include <pthread.h>
29 #include <stdlib.h>
30
31
32
33 /*************************************************************************************************
34 * API for search result of node
35 *************************************************************************************************/
36
37
38 typedef struct { /* type of structure for a document in result */
39 const char *uri; /* URI */
40 CBMAP *attrs; /* attributes */
41 char *snippet; /* snippet */
42 } ESTRESDOC;
43
44 typedef struct { /* type of structure for search result */
45 ESTRESDOC *docs; /* array of documents */
46 int top; /* offset number of the top element */
47 int max; /* maximum number of allcated elements */
48 int dnum; /* number of effective elements */
49 CBMAP *hints; /* map object for hints */
50 } ESTNODERES;
51
52
53 /* Delete a node result object.
54 `nres' specifies a node result object. */
55 void est_noderes_delete(ESTNODERES *nres);
56
57
58 /* Get a map object for hints of a node result object.
59 `nres' specifies a node result object.
60 The return value is a map object for hints. Keys of the map are "VERSION", "NODE", "HIT",
61 "HINT#n", "DOCNUM", "WORDNUM", "TIME", "LINK#n", and "VIEW". The life duration of the
62 returned object is synchronous with the one of the node result object. */
63 CBMAP *est_noderes_hints(ESTNODERES *nres);
64
65
66 /* Get the number of documents in a node result object.
67 `nres' specifies a node result object.
68 The return value is the number of documents in a node result object. */
69 int est_noderes_doc_num(ESTNODERES *nres);
70
71
72 /* Refer a result document object in a node result object.
73 `nres' specifies a node result object.
74 `index' specifies the index of a document.
75 The return value is a result document object or `NULL' if `index' is equal to or more than
76 the number of documents. The life duration of the returned object is synchronous with the
77 one of the node result object. */
78 ESTRESDOC *est_noderes_get_doc(ESTNODERES *nres, int index);
79
80
81 /* Get the URI of a result document object.
82 `doc' specifies a result document object.
83 The return value is the URI of the result document object. The life duration of the returned
84 string is synchronous with the one of the result document object. */
85 const char *est_resdoc_uri(ESTRESDOC *rdoc);
86
87
88 /* Get a list of attribute names of a result document object.
89 `rdoc' specifies a result document object.
90 The return value is a new list object of attribute names of the result document object.
91 Because the object of the return value is opened with the function `cblistopen', it should be
92 closed with the function `cblistclose' if it is no longer in use. */
93 CBLIST *est_resdoc_attr_names(ESTRESDOC *rdoc);
94
95
96 /* Get the value of an attribute of a result document object.
97 `rdoc' specifies a result document object.
98 `name' specifies the name of an attribute.
99 The return value is the value of the attribute or `NULL' if it does not exist. The life
100 duration of the returned string is synchronous with the one of the result document object. */
101 const char *est_resdoc_attr(ESTRESDOC *rdoc, const char *name);
102
103
104 /* Get the snippet of a result document object.
105 `rdoc' specifies a result document object.
106 The return value is the snippet of the result document object. There are tab separated
107 values. Each line is a string to be shown. Though most lines have only one field, some
108 lines have two fields. If the second field exists, the first field is to be shown with
109 highlighted, and the second field means its normalized form. The life duration of the
110 returned string is synchronous with the one of the result document object. */
111 const char *est_resdoc_snippet(ESTRESDOC *rdoc);
112
113
114
115 /*************************************************************************************************
116 * API for node
117 *************************************************************************************************/
118
119
120 typedef struct { /* type of structure for a node object */
121 char *url; /* URL */
122 char *pxhost; /* host name of the proxy */
123 int pxport; /* port number of the proxy */
124 int timeout; /* timeout in seconds */
125 char *auth; /* authority */
126 char *name; /* name */
127 char *label; /* label */
128 int dnum; /* number of documents */
129 int wnum; /* number of words */
130 double size; /* size of the database */
131 int status; /* last status code */
132 CBMAP *heads; /* extention headers */
133 } ESTNODE;
134
135
136 /* Initialize the networking environment.
137 The return value is true if success, else it is false. */
138 int est_init_net_env(void);
139
140
141 /* Create a node connection object.
142 `url' specifies the URL of a node.
143 The return value is a node connection object. */
144 ESTNODE *est_node_new(const char *url);
145
146
147 /* Destroy a node connection object.
148 `node' specifies a node connection object. */
149 void est_node_delete(ESTNODE *node);
150
151
152 /* Get the status code of the last request of a node.
153 `node' specifies a node connection object.
154 The return value is the status code of the last request of the node. -1 means failure of
155 connection. */
156 int est_node_status(ESTNODE *node);
157
158
159 /* Set the proxy information of a node connection object.
160 `node' specifies a node connection object.
161 `host' specifies the host name of a proxy server.
162 `port' specifies the port number of the proxy server. */
163 void est_node_set_proxy(ESTNODE *node, const char *host, int port);
164
165
166 /* Set timeout of a connection.
167 `node' specifies a node connection object.
168 `sec' specifies timeout of the connection in seconds. */
169 void est_node_set_timeout(ESTNODE *node, int sec);
170
171
172 /* Set the authoririty information of a node connection object.
173 `node' specifies a node connection object.
174 `name' specifies the name of an authority.
175 `passwd' specifies the password of the authority. */
176 void est_node_set_auth(ESTNODE *node, const char *name, const char *passwd);
177
178
179 /* Add a document to a node.
180 `node' specifies a node connection object.
181 `doc' specifies a document object. The document object should have the URI attribute.
182 The return value is true if success, else it is false.
183 If the URI attribute is same with an existing document in the node, the existing one is
184 deleted. */
185 int est_node_put_doc(ESTNODE *node, ESTDOC *doc);
186
187
188 /* Remove a document from a node.
189 `node' specifies a node connection object.
190 `id' specifies the ID number of a registered document.
191 The return value is true if success, else it is false. */
192 int est_node_out_doc(ESTNODE *node, int id);
193
194
195 /* Remove a document specified by URI from a node.
196 `node' specifies a node connection object.
197 `uri' specifies the URI of a registered document.
198 The return value is true if success, else it is false. */
199 int est_node_out_doc_by_uri(ESTNODE *node, const char *uri);
200
201
202 /* Retrieve a document in a node.
203 `node' specifies a node connection object.
204 `id' specifies the ID number of a registered document.
205 The return value is a document object. It should be deleted with `est_doc_delete' if it is
206 no longer in use. On error, `NULL' is returned. */
207 ESTDOC *est_node_get_doc(ESTNODE *node, int id);
208
209
210 /* Retrieve a document specified by URI in a node.
211 `node' specifies a node connection object.
212 `uri' specifies the URI of a registered document.
213 The return value is a document object. It should be deleted with `est_doc_delete' if it is
214 no longer in use. On error, `NULL' is returned. */
215 ESTDOC *est_node_get_doc_by_uri(ESTNODE *node, const char *uri);
216
217
218 /* Retrieve the value of an attribute of a document in a node.
219 `node' specifies a node connection object.
220 `id' specifies the ID number of a registered document.
221 `name' specifies the name of an attribute.
222 The return value is the value of the attribute or `NULL' if it does not exist. Because the
223 region of the return value is allocated with the `malloc' call, it should be released with
224 the `free' call if it is no longer in use. */
225 char *est_node_get_doc_attr(ESTNODE *node, int id, const char *name);
226
227
228 /* Retrieve the value of an attribute of a document specified by URI in a node.
229 `node' specifies a node connection object.
230 `uri' specifies the URI of a registered document.
231 `name' specifies the name of an attribute.
232 The return value is the value of the attribute or `NULL' if it does not exist. Because the
233 region of the return value is allocated with the `malloc' call, it should be released with
234 the `free' call if it is no longer in use. */
235 char *est_node_get_doc_attr_by_uri(ESTNODE *node, const char *uri, const char *name);
236
237
238 /* Get the ID of a document spacified by URI.
239 `node' specifies a node connection object.
240 `uri' specifies the URI of a registered document.
241 The return value is the ID of the document. On error, -1 is returned. */
242 int est_node_uri_to_id(ESTNODE *node, const char *uri);
243
244
245 /* Get the name of a node.
246 `node' specifies a node connection object.
247 The return value is the name of the node. On error, `NULL' is returned. The life duration
248 of the returned string is synchronous with the one of the node object. */
249 const char *est_node_name(ESTNODE *node);
250
251
252 /* Get the label of a node.
253 `node' specifies a node connection object.
254 The return value is the label of the node. On error, `NULL' is returned. The life duration
255 of the returned string is synchronous with the one of the node object. */
256 const char *est_node_label(ESTNODE *node);
257
258
259 /* Get the number of documents in a node.
260 `node' specifies a node connection object.
261 The return value is the number of documents in the node. On error, -1 is returned. */
262 int est_node_doc_num(ESTNODE *node);
263
264
265 /* Get the number of words in a node.
266 `node' specifies a node connection object.
267 The return value is the number of words in the node. On error, -1 is returned. */
268 int est_node_word_num(ESTNODE *node);
269
270
271 /* Get the size of the datbase of a node.
272 `node' specifies a node connection object.
273 The return value is the size of the datbase of the node. On error, -1.0 is returned. */
274 double est_node_size(ESTNODE *node);
275
276
277 /* Search documents corresponding a condition for a node.
278 `node' specifies a node connection object.
279 `cond' specifies a condition object.
280 `depth' specifies the depth of meta search.
281 The return value is a node result object. It should be deleted with `est_noderes_delete' if
282 it is no longer in use. On error, `NULL' is returned. */
283 ESTNODERES *est_node_search(ESTNODE *node, ESTCOND *cond, int depth);
284
285
286 /* Manage a user account of a node.
287 `node' specifies a node connection object.
288 `name' specifies the name of a user.
289 `mode' specifies the operation mode. 0 means to delete the account. 1 means to set the
290 account as an administrator. 2 means to set the account as a normal user.
291 The return value is true if success, else it is false. */
292 int est_node_set_user(ESTNODE *node, const char *name, int mode);
293
294
295 /* Manage a link of a node.
296 `node' specifies a node connection object.
297 `url' specifies the URL of the target node of a link.
298 `label' specifies the label of the link.
299 `credit' specifies the credit of the link. If it is negative, the link is removed.
300 The return value is true if success, else it is false. */
301 int est_node_set_link(ESTNODE *node, const char *url, const char *label, int credit);
302
303
304
305 /*************************************************************************************************
306 * features for experts
307 *************************************************************************************************/
308
309
310 #define ESTAGENTNAME "HyperEstraier" /* name of the user agent */
311 #define ESTFORMTYPE "application/x-www-form-urlencoded" /* media type of docuemnt draft */
312 #define ESTINFORMTYPE "text/x-estraier-nodeinfo" /* media type of node information */
313 #define ESTRESULTTYPE "text/x-estraier-result" /* media type of search result */
314 #define ESTDRAFTTYPE "text/x-estraier-draft" /* media type of docuemnt draft */
315 #define ESTHTHVIA "X-Estraier-Via" /* header to escape from looping route */
316
317
318 /* Get the name of this host.
319 The return value is the name of this host. */
320 const char *est_get_host_name(void);
321
322
323 /* Get the address of a host.
324 `name' specifies the name of a host.
325 The return value is the address of a host or `NULL' if failure. Because the region of the
326 return value is allocated with the `malloc' call, it should be released with the `free' call
327 if it is no longer in use. */
328 char *est_get_host_addr(const char *name);
329
330
331 /* Get a server socket of an address and a port.
332 `addr' specifies an address of a host. If it is `NULL', every network address is binded.
333 `port' specifies a port number.
334 The return value is the socket of the address and the port or -1 if failure. */
335 int est_get_server_sock(const char *addr, int port);
336
337
338 /* Accept a connection from a client.
339 `sock' specifies a server socket.
340 `abuf' specifies a buffer into which the address of a connected client is written. The size of
341 the buffer should be more than 32. If it is `NULL', it is ignored.
342 `pp' specifies the pointer to a variable to which the port of the client is assigned. If it
343 is `NULL', it is ignored.
344 The return value is a socket connected to the client, or 0 if intterupted, or -1 if failure.
345 The thread blocks until the connection is established. */
346 int est_accept_conn(int sock, char *abuf, int *pp);
347
348
349 /* Get a client socket to an address and a port.
350 `addr' specifies an address of a host.
351 `port' specifies a port number.
352 The return value is the socket to the address and the port or -1 if failure. */
353 int est_get_client_sock(const char *addr, int port);
354
355
356 /* Shutdown and close a socket.
357 `sock' specifies a socket. */
358 void est_sock_down(int sock);
359
360
361 /* Receive all data from a socket.
362 `sock' specifies a socket.
363 `len' specifies the length of data to be read.
364 The return value is the pointer to the region of an allocated region containing the received
365 data.
366 Because an additional zero code is appended at the end of the region of the return value, the
367 return value can be treated as a character string. Because the region of the return value is
368 allocated with the `malloc' call, it should be released with the `free' call if it is no
369 longer in use. */
370 char *est_sock_recv_all(int sock, int len);
371
372
373 /* Receive a line from a socket.
374 `sock' specifies a socket.
375 `buf' specifies a buffer to store read data.
376 `max' specifies the maximum length to read. It should be more than 0.
377 The return value is the size of received data.
378 Because an additional zero code is appended at the end of the region of the buffer, it can be
379 treated as a character string. */
380 int est_sock_recv_line(int sock, char *buf, int max);
381
382
383 /* Receive void data from a socket.
384 `sock' specifies a socket. */
385 void est_sock_recv_void(int sock);
386
387
388 /* Send all data into a socket.
389 `sock' specifies a socket.
390 `buf' specifies a buffer of data to write.
391 `len' specifies the length of the data. */
392 void est_sock_send_all(int sock, const char *buf, int len);
393
394
395 /* Perform formatted output into a datum object.
396 `format' specifies a printf-like format string.
397 The conversion character `%' can be used with such flag characters as `s', `d', `o', `u',
398 `x', `X', `c', `e', `E', `f', `g', `G', `@', `?', `%'. `@' works as with `s' but escapes
399 meta characters of XML. `?' works as with `s' but escapes meta characters of URL. The other
400 conversion character work as with each original. */
401 void est_datum_printf(CBDATUM *datum, const char *format, ...);
402
403
404 /* Perform an interaction of a URL.
405 `url' specifies a URL.
406 `pxhost' specifies the host name of a proxy. If it is `NULL', it is not used.
407 `pxport' specifies the port number of the proxy.
408 `outsec' specifies timeout in seconds. If it is negative, it is not used.
409 `auth' specifies an authority information in such form as "user:pass". If it is `NULL', it is
410 not used.
411 `reqheads' specifies a list object of extension headers. If it is `NULL' it is ignored.
412 `reqbody' specifies the pointer of the entitiy body of request. If it is `NULL', "GET"
413 method is used.
414 `rbsiz' specifies the size of the entity body.
415 `rescodep' specifies the pointer to a variable to which the status code of respnese is
416 assigned. If it is `NULL', it is not used.
417 `resheads' specifies a map object into which headers of response is stored. The value of each
418 header is recorded as an attribute whose name is converted from the header name into lower
419 cases. The top header for the status code is recorded with the key of an empty string. If it
420 is `NULL', it is not used.
421 `reqbody' specifies a datum object into which the entity body of response is stored. If it is
422 `NULL', it is not used.
423 The return value is true if success, else it is false.
424 Headers of "Host", "Connection", "User-Agent", "Authorization", and "Content-Length" are sent
425 implicitly. */
426 int est_url_shuttle(const char *url, const char *pxhost, int pxport, int outsec,
427 const char *auth, const CBLIST *reqheads, const char *reqbody, int rbsiz,
428 int *rescodep, CBMAP *resheads, CBDATUM *resbody);
429
430
431 /* Add a header to a node connection object.
432 `node' specifies a node connection object.
433 `name' specifies the name of a header.
434 `value' specifies the value of the header. If it is `NULL', the header is removed.
435 If the specified header is already added, the value is concatenated at the end. */
436 void est_node_add_header(ESTNODE *node, const char *name, const char *value);
437
438
439 /* Create a node result object.
440 The return value is a node result object. */
441 ESTNODERES *est_noderes_new(void);
442
443
444 /* Add a document information to a node result object.
445 `nres' specifies a node result object.
446 `attrs' specifies a map object of attributes of the document. The object is closed internally.
447 `snippet' specifies the snippet of the document. The region is released internally. */
448 void est_noderes_add_doc(ESTNODERES *nres, CBMAP *attrs, char *snippet);
449
450
451 /* Remove the top of result document objects in a node result object.
452 `nres' specifies a node result object.
453 `attrp' specifies the pointer to a variable to which reference of the map object of attribute
454 is assigned. The object should be deleted with the function `cbmapclose'.
455 `snippetp' specifies the pointer to a variable to which reference of the snippet string is
456 assigned. The region should be released with the function `free'.
457 The return value is true if success, else it is false. */
458 int est_noderes_shift(ESTNODERES *nres, CBMAP **attrp, char **snippetp);
459
460
461
462 #if defined(__cplusplus) /* export for C++ */
463 }
464 #endif
465
466 #endif /* duplication check */
467
468
469 /* END OF FILE */

  ViewVC Help
Powered by ViewVC 1.1.26