-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathExpect.h
80 lines (56 loc) · 2.13 KB
/
Expect.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
Copyright (c) 2015 Colum Paget <[email protected]>
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
#ifndef LIBUSEFUL_EXPECT_H
#define LIBUSEFUL_EXPECT_H
/*
These functions handle 'chat' style dialogues on a STREAM connection.
Read Stream.h to understand the STREAM object. STREAMS can be pipes to other processes, network connections, etc.
*/
#include "Stream.h"
#define DIALOG_END 1
#define DIALOG_FAIL 2
#define DIALOG_OPTIONAL 4
#define DIALOG_TIMEOUT 8
typedef struct
{
int Flags;
int Match;
char *Expect;
char *Reply;
} TExpectDialog;
#ifdef __cplusplus
extern "C" {
#endif
//Consume data from a stream, waiting for it to be silent for 'wait' seconds, then return;
int STREAMExpectSilence(STREAM *S, int wait);
/*
consume data from a stream, until the string pointed to be 'Expect' is seen. Then send the string
pointed to by 'Reply' and return
*/
int STREAMExpectAndReply(STREAM *S, const char *Expect, const char *Reply);
/*
Add a Expect/Reply pair to a list (See List.h for details of libUseful lists.) A number of these can be
chained together in the list which is then passed to 'STREAMExpectDialog'. 'STREAMExpectDialog' will
work through the list, expecting to match one Expect/Reply pair after another in a conversation of
'expect' matches and sent replies.
The 'Flags' option can have the following values:
DIALOG_END
If the 'Expect' value is seen, then the dialog has successfully completed. STREAMExpectDialog
will immediately return TRUE, even if there are other items yet to be processed
DIALOG_FAIL
If the 'Expect' value is seen, then the dialog has failed. STREAMExpectDialog will immedialtely
return FALSE, even if there are other items yet to be processed
DIALOG_OPTIONAL
If this item isn't seen, but one after it is seen, then skip over this item.
the list used by STREAMExpectDialog should be destroyed like this:
ListDestroy(DialogList, ExpectDialogDestroy);
*/
void ExpectDialogAdd(ListNode *Dialogs, char *Expect, char *Reply, int Flags);
int STREAMExpectDialog(STREAM *S, ListNode *Dialogs, int Timeout);
void ExpectDialogDestroy(void *Item);
#ifdef __cplusplus
}
#endif
#endif