1 #include "../nterfacer/nterfacer.h"
2 #include "../lib/strlfunc.h"
3 #include "../core/nsmalloc.h"
8 #define Stringify(x) __Stringify(x)
9 #define __Stringify(x) #x
11 static void tm_trustdump(trustmigration
*tm
);
13 static void tm_fini(trustmigration
*tm
, int errcode
) {
14 tm
->fini(tm
->tag
, errcode
);
17 nterfacer_freeline(tm
->schedule
);
21 nsfree(POOL_TRUSTS
, tm
);
24 void migration_stop(trustmigration
*tm
) {
25 tm_fini(tm
, MIGRATION_STOPPED
);
28 static void tm_stage2(int failure
, int linec
, char **linev
, void *tag
) {
29 trustmigration
*tm
= tag
;
31 unsigned int groupcount
, totallines
, i
, dummy
;
33 #ifdef TRUSTS_MIGRATION_DEBUG
34 Error("trusts", ERR_INFO
, "Migration total lines: %d", linec
);
37 Error("trusts", ERR_INFO
, "Migration line %d: |%s|", i
, linev
[i
]);
41 if(failure
|| (linec
< 1)) {
46 finishline
= linev
[linec
- 1];
47 if(sscanf(finishline
, "Start ID cannot exceed current maximum group ID (#%u).", &dummy
) == 1) {
48 /* the list was truncated while we were reading it, we're done! */
53 if(sscanf(finishline
, "End of list, %u groups and %u lines returned.", &groupcount
, &totallines
) != 2) {
58 if(totallines
!= linec
- 1) {
63 for(i
=0;i
<linec
-1;i
++) {
64 char *linestart
= &linev
[i
][2], type
= linev
[i
][0];
68 if(!parsetg(linestart
, &tg
, 1)) {
74 tm
->group(tm
->tag
, &tg
);
77 freesstring(tg
.createdby
);
78 freesstring(tg
.contact
);
79 freesstring(tg
.comment
);
88 } else if (type
== 'H') {
92 if(!parseth(linestart
, &th
, &groupid
, 1)) {
97 if(groupid
< tm
->cur
) {
102 if(groupid
> tm
->cur
)
105 tm
->host(tm
->tag
, &th
, groupid
);
115 static void tm_trustdump(trustmigration
*tm
) {
118 if(tm
->cur
>= tm
->count
) {
125 snprintf(buf
, sizeof(buf
), "trustdump #%d 1", tm
->cur
);
126 tm
->schedule
= nterfacer_sendline("R", "relay", 4, (char *[]){"2", "^(Start ID cannot exceed current maximum group ID \\(#\\d+\\)|End of list, 1 groups and \\d+ lines returned\\.)$", "O", buf
}, tm_stage2
, tm
);
129 static void tm_stage1(int failure
, int linec
, char **linev
, void *tag
) {
131 trustmigration
*tm
= tag
;
135 if(failure
|| (linec
!= 1)) {
140 if(sscanf(linev
[0], "Start ID cannot exceed current maximum group ID (#%u).", &count
) != 1) {
145 Error("trusts", ERR_INFO
, "Migration in progress, total groups: %d", count
);
152 trustmigration
*migration_start(TrustMigrationGroup group
, TrustMigrationHost host
, TrustMigrationFini fini
, void *tag
) {
153 trustmigration
*tm
= nsmalloc(POOL_TRUSTS
, sizeof(trustmigration
));
164 tm
->schedule
= nterfacer_sendline("R", "relay", 4, (char *[]){"1", "1", "O", "trustdump #9999999 1"}, tm_stage1
, tm
);
166 nsfree(POOL_TRUSTS
, tm
);