source: trunk/minix/servers/inet/qp.c@ 20

Last change on this file since 20 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 3.7 KB
RevLine 
[9]1/*
2inet/qp.c
3
4Query parameters
5
6Created: June 1995 by Philip Homburg <philip@f-mnx.phicoh.com>
7*/
8
9#include "inet.h"
10
11#include <sys/svrctl.h>
12#ifdef __minix_vmd
13#include <minix/queryparam.h>
14#else /* Minix 3 */
15#include <minix3/queryparam.h>
16#endif
17
18#include "generic/buf.h"
19#include "generic/clock.h"
20#include "generic/event.h"
21#include "generic/type.h"
22#include "generic/sr.h"
23
24#include "generic/tcp_int.h"
25#include "generic/udp_int.h"
26#include "mq.h"
27#include "qp.h"
28#include "sr_int.h"
29
30FORWARD int get_userdata ARGS(( int proc, vir_bytes vaddr, vir_bytes vlen,
31 void *buffer ));
32FORWARD int put_userdata ARGS(( int proc, vir_bytes vaddr, vir_bytes vlen,
33 void *buffer ));
34FORWARD int iqp_getc ARGS(( void ));
35FORWARD void iqp_putc ARGS(( int c ));
36
37PRIVATE struct export_param_list inet_ex_list[]=
38{
39 QP_VARIABLE(sr_fd_table),
40 QP_VARIABLE(ip_dev),
41 QP_VARIABLE(tcp_fd_table),
42 QP_VARIABLE(tcp_conn_table),
43 QP_VARIABLE(tcp_cancel_f),
44 QP_VECTOR(udp_port_table, udp_port_table, ip_conf_nr),
45 QP_VARIABLE(udp_fd_table),
46 QP_END()
47};
48
49PRIVATE struct export_params inet_ex_params= { inet_ex_list, NULL };
50
51PRIVATE struct queryvars {
52 int proc;
53 struct svrqueryparam qpar;
54 char parbuf[256], valbuf[256];
55 char *param, *value;
56 int r;
57} *qvars;
58
59PUBLIC void qp_init()
60{
61 qp_export(&inet_ex_params);
62}
63
64PUBLIC int qp_query(proc, argp)
65int proc;
66vir_bytes argp;
67{
68 /* Return values, sizes, or addresses of variables in MM space. */
69
70 struct queryvars qv;
71 void *addr;
72 size_t n, size;
73 int byte;
74 int more;
75 static char hex[]= "0123456789ABCDEF";
76
77 qv.r= get_userdata(proc, argp, sizeof(qv.qpar), &qv.qpar);
78
79 /* Export these to mq_getc() and mq_putc(). */
80 qvars= &qv;
81 qv.proc= proc;
82 qv.param= qv.parbuf + sizeof(qv.parbuf);
83 qv.value= qv.valbuf;
84
85 do {
86 more= queryparam(iqp_getc, &addr, &size);
87 for (n= 0; n < size; n++) {
88 byte= ((u8_t *) addr)[n];
89 iqp_putc(hex[byte >> 4]);
90 iqp_putc(hex[byte & 0x0F]);
91 }
92 iqp_putc(more ? ',' : 0);
93 } while (more);
94 return qv.r;
95}
96
97
98PRIVATE int iqp_getc()
99{
100 /* Return one character of the names to search for. */
101 struct queryvars *qv= qvars;
102 size_t n;
103
104 if (qv->r != OK || qv->qpar.psize == 0) return 0;
105 if (qv->param == qv->parbuf + sizeof(qv->parbuf)) {
106 /* Need to fill the parameter buffer. */
107 n= sizeof(qv->parbuf);
108 if (qv->qpar.psize < n) n= qv->qpar.psize;
109 qv->r= get_userdata(qv->proc, (vir_bytes) qv->qpar.param, n,
110 qv->parbuf);
111 if (qv->r != OK) return 0;
112 qv->qpar.param+= n;
113 qv->param= qv->parbuf;
114 }
115 qv->qpar.psize--;
116 return (u8_t) *qv->param++;
117}
118
119
120PRIVATE void iqp_putc(c)
121int c;
122{
123 /* Send one character back to the user. */
124 struct queryvars *qv= qvars;
125 size_t n;
126
127 if (qv->r != OK || qv->qpar.vsize == 0) return;
128 *qv->value++= c;
129 qv->qpar.vsize--;
130 if (qv->value == qv->valbuf + sizeof(qv->valbuf)
131 || c == 0 || qv->qpar.vsize == 0) {
132 /* Copy the value buffer to user space. */
133 n= qv->value - qv->valbuf;
134 qv->r= put_userdata(qv->proc, (vir_bytes) qv->qpar.value, n,
135 qv->valbuf);
136 qv->qpar.value+= n;
137 qv->value= qv->valbuf;
138 }
139}
140
141PRIVATE int get_userdata(proc, vaddr, vlen, buffer)
142int proc;
143vir_bytes vaddr;
144vir_bytes vlen;
145void *buffer;
146{
147#ifdef __minix_vmd
148 return sys_copy(proc, SEG_D, (phys_bytes)vaddr, this_proc, SEG_D,
149 (phys_bytes)buffer, (phys_bytes)vlen);
150#else /* Minix 3 */
151 return sys_vircopy(proc, D, vaddr, SELF, D, (vir_bytes)buffer, vlen);
152#endif
153}
154
155
156PRIVATE int put_userdata(proc, vaddr, vlen, buffer)
157int proc;
158vir_bytes vaddr;
159vir_bytes vlen;
160void *buffer;
161{
162#ifdef __minix_vmd
163 return sys_copy(this_proc, SEG_D, (phys_bytes)buffer,
164 proc, SEG_D, (phys_bytes)vaddr, (phys_bytes)vlen);
165#else /* Minix 3 */
166 return sys_vircopy(SELF, D, (vir_bytes)buffer, proc, D, vaddr, vlen);
167#endif
168}
169
170
171
172/*
173 * $PchId: qp.c,v 1.7 2005/06/28 14:25:25 philip Exp $
174 */
Note: See TracBrowser for help on using the repository browser.