properly differentiate between subdoc or fatal error in execm protocol

This commit is contained in:
Jean-Francois Dockes 2010-11-22 15:50:14 +01:00
parent 21e16bb8a2
commit f4aa7fcec4
2 changed files with 41 additions and 21 deletions

View File

@ -10,6 +10,10 @@ class RclExecM:
eofnext = 1 eofnext = 1
eofnow = 2 eofnow = 2
noerror = 0
subdocerror = 1
fileerror = 2
def __init__(self): def __init__(self):
self.myname = os.path.basename(sys.argv[0]) self.myname = os.path.basename(sys.argv[0])
self.mimetype = "" self.mimetype = ""
@ -60,24 +64,29 @@ class RclExecM:
return (paramname, paramdata) return (paramname, paramdata)
# Send answer: document, ipath, possible eof. # Send answer: document, ipath, possible eof.
def answer(self, docdata, ipath, iseof = noteof): def answer(self, docdata, ipath, iseof = noteof, iserror = noerror):
print "Document:", len(docdata) if iserror != RclExecM.fileerror and iseof != RclExecM.eofnow:
sys.stdout.write(docdata) print "Document:", len(docdata)
sys.stdout.write(docdata)
if len(ipath): if len(ipath):
print "Ipath:", len(ipath) print "Ipath:", len(ipath)
sys.stdout.write(ipath) sys.stdout.write(ipath)
if len(self.mimetype): if len(self.mimetype):
print "Mimetype:", len(self.mimetype) print "Mimetype:", len(self.mimetype)
sys.stdout.write(self.mimetype) sys.stdout.write(self.mimetype)
# If we're at the end of the contents, say so # If we're at the end of the contents, say so
if iseof == self.eofnow: if iseof == RclExecM.eofnow:
print "Eofnow: 0" print "Eofnow: 0"
elif iseof == self.eofnext: elif iseof == RclExecM.eofnext:
print "Eofnext: 0" print "Eofnext: 0"
if iserror == RclExecM.subdocerror:
print "Subdocerror: 0"
elif iserror == RclExecM.fileerror:
print "Fileerror: 0"
# End of message # End of message
print print
@ -93,7 +102,7 @@ class RclExecM:
# If we're given a file name, open it. # If we're given a file name, open it.
if len(params["filename:"]) != 0: if len(params["filename:"]) != 0:
if not processor.openfile(params): if not processor.openfile(params):
self.answer("", "", True) self.answer("", "", iserror = RclExecM.fileerror)
return return
# If we have an ipath, that's what we look for, else ask for next entry # If we have an ipath, that's what we look for, else ask for next entry
@ -107,7 +116,7 @@ class RclExecM:
if ok: if ok:
self.answer(data, ipath, eof) self.answer(data, ipath, eof)
else: else:
self.answer("", "", eof) self.answer("", "", eof, RclExecM.subdocerror)
# Loop on messages from our master # Loop on messages from our master
def mainloop(self, processor): def mainloop(self, processor):

View File

@ -181,6 +181,8 @@ bool MimeHandlerExecMultiple::next_document()
LOGDEB1(("MHExecMultiple: reading answer\n")); LOGDEB1(("MHExecMultiple: reading answer\n"));
bool eofnext_received = false; bool eofnext_received = false;
bool eofnow_received = false; bool eofnow_received = false;
bool fileerror_received = false;
bool subdocerror_received = false;
string ipath; string ipath;
string mtype; string mtype;
for (int loop=0;;loop++) { for (int loop=0;;loop++) {
@ -194,16 +196,22 @@ bool MimeHandlerExecMultiple::next_document()
if (!stringlowercmp("eofnext:", name)) { if (!stringlowercmp("eofnext:", name)) {
LOGDEB(("MHExecMultiple: got EOFNEXT\n")); LOGDEB(("MHExecMultiple: got EOFNEXT\n"));
eofnext_received = true; eofnext_received = true;
} } else if (!stringlowercmp("eofnow:", name)) {
if (!stringlowercmp("eofnow:", name)) {
LOGDEB(("MHExecMultiple: got EOFNOW\n")); LOGDEB(("MHExecMultiple: got EOFNOW\n"));
eofnow_received = true; eofnow_received = true;
} } else if (!stringlowercmp("subdocerror:", name)) {
if (!stringlowercmp("ipath:", name)) { LOGDEB(("MHExecMultiple: got SUBDOCERROR\n"));
subdocerror_received = true;
} else if (!stringlowercmp("fileerror:", name)) {
LOGDEB(("MHExecMultiple: got FILEERROR\n"));
fileerror_received = true;
} else if (!stringlowercmp("subdocerror:", name)) {
LOGDEB(("MHExecMultiple: got SUBDOCERROR\n"));
return false;
} else if (!stringlowercmp("ipath:", name)) {
ipath = data; ipath = data;
LOGDEB(("MHExecMultiple: got ipath [%s]\n", data.c_str())); LOGDEB(("MHExecMultiple: got ipath [%s]\n", data.c_str()));
} } else if (!stringlowercmp("mimetype:", name)) {
if (!stringlowercmp("mimetype:", name)) {
mtype = data; mtype = data;
LOGDEB(("MHExecMultiple: got mimetype [%s]\n", data.c_str())); LOGDEB(("MHExecMultiple: got mimetype [%s]\n", data.c_str()));
} }
@ -214,11 +222,14 @@ bool MimeHandlerExecMultiple::next_document()
} }
} }
if (eofnow_received) { if (eofnow_received || fileerror_received) {
// No more docs // No more docs
m_havedoc = false; m_havedoc = false;
return false; return false;
} }
if (subdocerror_received) {
return false;
}
// It used to be that eof could be signalled just by an empty document, but // It used to be that eof could be signalled just by an empty document, but
// this was wrong. Empty documents can be found ie in zip files and should // this was wrong. Empty documents can be found ie in zip files and should