1 /*
2  * %CopyrightBegin%
3  *
4  * Copyright Ericsson AB 2002-2020. All Rights Reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * %CopyrightEnd%
19  */
20 
21 /***************************************************************************
22  *
23  *  This is a fake program that contains all functions, variables and
24  *  defined symbols mentioned in the manual. We compile this file to see
25  *  that the header files and created library is complete.
26  *
27  *  You can't run this program, it is for compiling and linking only.
28  *
29  ***************************************************************************/
30 
31 /* This is a link and header file test. Including "ei.h" and linking
32    with libei.a should be enough */
33 
34 /* Use most of
35  * CFLAGS="-I../include -g -O2
36  *         -ansi -pedantic
37  *         -Wall
38  *         -Wshadow
39  *         -Wstrict-prototypes
40  *         -Wmissing-prototypes
41  *         -Wmissing-declarations
42  *         -Wnested-externs
43  *         -Winline
44  *         -Werror"
45  */
46 
47 /* An exception from using eidef.h, use config.h directly */
48 #include "config.h"
49 
50 #if defined(HAVE_GMP_H) && defined(HAVE_LIBGMP)
51 #include <gmp.h>
52 #endif /* HAVE_GMP_H && HAVE_LIBGMP */
53 
54 /* #include <netdb.h> now included by ei.h */
55 #include "ei.h"
56 
main(void)57 int main(void)
58 {
59   ErlConnect conp;
60   Erl_IpAddr thisipaddr = (Erl_IpAddr)0;
61   FILE *fp = (FILE *)0;
62   char* charp = "foo";
63   double *doublep = NULL;
64   double doublex = 0.0;
65   ei_cnode xec;
66   ei_reg *ei_regp = NULL;
67   ei_term eterm;
68   ei_x_buff eix;
69   erlang_big *bigp = NULL;
70   erlang_fun efun;
71   erlang_msg *msgp = NULL;
72   erlang_msg emsg;
73   erlang_pid *pidp = NULL;
74   erlang_pid epid;
75   erlang_port eport;
76   erlang_ref eref;
77   erlang_trace etrace;
78   int *intp = NULL;
79   int intx = 0;
80   long *longp = NULL;
81   long longx = 0;
82   short creation = 0;
83   struct ei_reg_stat *ei_reg_statp = NULL;
84   struct ei_reg_tabstat *ei_reg_tabstatp = NULL;
85   struct hostent *hostp = NULL;
86   unsigned char * ucharp = (unsigned char *)"foo";
87   unsigned long *ulongp = NULL;
88   unsigned long ulongx = 0;
89   void *voidp = NULL;
90   EI_LONGLONG *longlongp = (EI_LONGLONG*)NULL;
91   EI_LONGLONG longlongx = 0;
92   EI_ULONGLONG *ulonglongp = (EI_ULONGLONG*)NULL;
93   EI_ULONGLONG ulonglongx = 0;
94   erlang_char_encoding enc;
95   ei_socket_callbacks cbs;
96 
97   intx = erl_errno;
98 
99   ei_init();
100 
101   ei_close_connection(intx);
102 
103   ei_connect_init(&xec, charp, charp, creation);
104   ei_connect_init_ussi(&xec, charp, charp, creation, &cbs, sizeof(cbs), NULL);
105   ei_connect_xinit (&xec, charp, charp, charp, thisipaddr, charp, creation);
106   ei_connect_xinit_ussi(&xec, charp, charp, charp, thisipaddr, charp, creation, &cbs, sizeof(cbs), NULL);
107 
108   ei_connect(&xec, charp);
109   ei_xconnect (&xec, thisipaddr, charp);
110 
111   ei_receive(intx, ucharp, intx);
112   ei_receive_msg(intx, &emsg, &eix);
113   ei_xreceive_msg(intx, &emsg, &eix);
114 
115   ei_send(intx, &epid, charp, intx);
116   ei_reg_send(&xec, intx, charp, charp, intx);
117 
118   ei_rpc(&xec, intx, charp, charp, charp, intx, &eix);
119   ei_rpc_to(&xec, intx, charp, charp, charp, intx);
120   ei_rpc_from(&xec, intx, intx, &emsg, &eix);
121 
122   ei_publish(&xec, intx);
123   ei_accept(&xec, intx, &conp);
124   ei_unpublish(&xec);
125   ei_listen(&xec, intp, intx);
126   ei_xlisten(&xec, thisipaddr, intp, intx);
127 
128   ei_thisnodename(&xec);
129   ei_thishostname(&xec);
130   ei_thisalivename(&xec);
131 
132   ei_self(&xec);
133 
134   ei_gethostbyname(charp);
135   ei_gethostbyaddr(charp, intx, intx);
136   ei_gethostbyname_r(charp, hostp, charp, intx, intp);
137   ei_gethostbyaddr_r(charp, intx, intx, hostp, charp, intx, intp);
138 
139   ei_encode_version(charp, intp);
140   ei_x_encode_version(&eix);
141   ei_encode_long(charp, intp, longx);
142   ei_x_encode_long(&eix, longx);
143   ei_encode_ulong(charp, intp, ulongx);
144   ei_x_encode_ulong(&eix, ulongx);
145   ei_encode_double(charp, intp, doublex);
146   ei_x_encode_double(&eix, doublex);
147   ei_encode_boolean(charp, intp, intx);
148   ei_x_encode_boolean(&eix, intx);
149   ei_encode_char(charp, intp, 'a');
150   ei_x_encode_char(&eix, 'a');
151   ei_encode_string(charp, intp, charp);
152   ei_encode_string_len(charp, intp, charp, intx);
153   ei_x_encode_string(&eix, charp);
154   ei_x_encode_string_len(&eix, charp, intx);
155   ei_encode_atom(charp, intp, charp);
156   ei_encode_atom_as(charp, intp, charp, ERLANG_LATIN1, ERLANG_UTF8);
157   ei_encode_atom_len(charp, intp, charp, intx);
158   ei_encode_atom_len_as(charp, intp, charp, intx, ERLANG_ASCII, ERLANG_LATIN1);
159   ei_x_encode_atom(&eix, charp);
160   ei_x_encode_atom_as(&eix, charp, ERLANG_LATIN1, ERLANG_UTF8);
161   ei_x_encode_atom_len(&eix, charp, intx);
162   ei_x_encode_atom_len_as(&eix, charp, intx, ERLANG_LATIN1, ERLANG_UTF8);
163   ei_encode_binary(charp, intp, (void *)0, longx);
164   ei_x_encode_binary(&eix, (void*)0, intx);
165   ei_encode_pid(charp, intp, &epid);
166   ei_x_encode_pid(&eix, &epid);
167   ei_encode_fun(charp, intp, &efun);
168   ei_x_encode_fun(&eix, &efun);
169   ei_encode_port(charp, intp, &eport);
170   ei_x_encode_port(&eix, &eport);
171   ei_encode_ref(charp, intp, &eref);
172   ei_x_encode_ref(&eix, &eref);
173   ei_encode_trace(charp, intp, &etrace);
174   ei_x_encode_trace(&eix, &etrace);
175   ei_encode_tuple_header(charp, intp, intx);
176   ei_x_encode_tuple_header(&eix, longx);
177   ei_encode_list_header(charp, intp, intx);
178   ei_x_encode_list_header(&eix, longx);
179 /* #define ei_encode_empty_list(buf,i) ei_encode_list_header(buf,i,0) */
180   ei_x_encode_empty_list(&eix);
181 
182   ei_get_type(charp, intp, intp, intp);
183 
184   ei_decode_version(charp, intp, intp);
185   ei_decode_long(charp, intp, longp);
186   ei_decode_ulong(charp, intp, ulongp);
187   ei_decode_double(charp, intp, doublep);
188   ei_decode_boolean(charp, intp, intp);
189   ei_decode_char(charp, intp, charp);
190   ei_decode_string(charp, intp, charp);
191   ei_decode_atom(charp, intp, charp);
192   ei_decode_atom_as(charp, intp, charp, MAXATOMLEN_UTF8, ERLANG_UTF8, &enc, &enc);
193   ei_decode_binary(charp, intp, (void *)0, longp);
194   ei_decode_fun(charp, intp, &efun);
195   free_fun(&efun);
196   ei_decode_pid(charp, intp, &epid);
197   ei_decode_port(charp, intp, &eport);
198   ei_decode_ref(charp, intp, &eref);
199   ei_decode_trace(charp, intp, &etrace);
200   ei_decode_tuple_header(charp, intp, intp);
201   ei_decode_list_header(charp, intp, intp);
202 
203   ei_decode_ei_term(charp, intp, &eterm);
204 
205   ei_print_term(fp, charp, intp);
206   ei_s_print_term(&charp, charp, intp);
207 
208   ei_x_format(&eix, charp);
209   ei_x_format_wo_ver(&eix, charp);
210 
211   ei_x_new(&eix);
212   ei_x_new_with_version(&eix);
213   ei_x_free(&eix);
214   ei_x_append(&eix, &eix);
215   ei_x_append_buf(&eix, charp, intx);
216   ei_skip_term(charp, intp);
217 
218   ei_reg_open(intx);
219   ei_reg_resize(ei_regp, intx);
220   ei_reg_close(ei_regp);
221 
222   ei_reg_setival(ei_regp, charp, longx);
223   ei_reg_setfval(ei_regp, charp, doublex);
224   ei_reg_setsval(ei_regp, charp, charp);
225   ei_reg_setpval(ei_regp, charp, voidp, intx);
226 
227   ei_reg_setval(ei_regp, charp, intx);
228 
229   ei_reg_getival(ei_regp, charp);
230   ei_reg_getfval(ei_regp, charp);
231   ei_reg_getsval(ei_regp, charp);
232   ei_reg_getpval(ei_regp, charp, intp);
233 
234   ei_reg_getval(ei_regp, charp, intx);
235 
236   ei_reg_markdirty(ei_regp, charp);
237 
238   ei_reg_delete(ei_regp, charp);
239 
240   ei_reg_stat(ei_regp, charp, ei_reg_statp);
241 
242   ei_reg_tabstat(ei_regp, ei_reg_tabstatp);
243 
244   ei_reg_dump(intx, ei_regp, charp, intx);
245   ei_reg_restore(intx, ei_regp, charp);
246   ei_reg_purge(ei_regp);
247 
248 #if defined(HAVE_GMP_H) && defined(HAVE_LIBGMP)
249   {
250       mpz_t obj;
251       ei_decode_bignum(charp, intp, obj);
252       ei_encode_bignum(charp, intp, obj);
253       ei_x_encode_bignum(&eix, obj);
254   }
255 #endif /* HAVE_GMP_H && HAVE_LIBGMP */
256 
257   ei_decode_longlong(charp, intp, longlongp);
258   ei_decode_ulonglong(charp, intp, ulonglongp);
259   ei_encode_longlong(charp, intp, longlongx);
260   ei_encode_ulonglong(charp, intp, ulonglongx);
261   ei_x_encode_longlong(&eix, longlongx);
262   ei_x_encode_ulonglong(&eix, ulonglongx);
263 
264 #ifdef USE_EI_UNDOCUMENTED
265 
266   ei_decode_intlist(charp, intp, longp, intp);
267 
268   ei_receive_encoded(intx, &charp, intp, msgp, intp);
269   ei_send_encoded(intx, pidp, charp, intx);
270   ei_send_reg_encoded(intx, pidp, charp, charp, intx);
271 
272   ei_decode_big(charp, intp, bigp);
273   ei_big_comp(bigp, bigp);
274   ei_big_to_double(bigp, doublep);
275   ei_small_to_big(intx, bigp);
276   ei_alloc_big(intx);
277   ei_free_big(bigp);
278 
279 #endif /* USE_EI_UNDOCUMENTED */
280 
281   return
282       BUFSIZ +
283       EAGAIN +
284       EHOSTUNREACH +
285       EIO +
286       EI_BIN +
287       EI_DELET +
288       EI_DIRTY +
289       EI_FLT +
290       EI_FORCE +
291       EI_INT +
292       EI_NOPURGE +
293       EI_STR +
294       EMSGSIZE +
295       ENOMEM +
296       ERL_ERROR +
297       ERL_EXIT +
298       ERL_LINK +
299       ERL_MSG +
300       ERL_NO_TIMEOUT +
301       ERL_REG_SEND +
302       ERL_SEND +
303       ERL_TICK +
304       ERL_TIMEOUT +
305       ERL_UNLINK +
306       ETIMEDOUT +
307       MAXATOMLEN;
308 }
309