From bd8221d2791718f02ab1d067c797c62b29da9106 Mon Sep 17 00:00:00 2001
From: deva <deva>
Date: Mon, 4 Aug 2008 09:17:36 +0000
Subject: Added NotFound exception when trying to open a non-existing and
 non-empty macro.

---
 server/src/server.cc | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

(limited to 'server')

diff --git a/server/src/server.cc b/server/src/server.cc
index 27a6b9d..6f875b8 100644
--- a/server/src/server.cc
+++ b/server/src/server.cc
@@ -63,6 +63,12 @@ static std::string error_box(std::string message)
   return errorbox;
 }
 
+class NotFoundException : public Exception {
+public:
+  NotFoundException(Request &r)
+  : Exception("Macro " + r.macro + " not found in course " + r.course) {}
+};
+
 static void connection(TCPSocket &socket)
 {
   socket.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
@@ -154,6 +160,8 @@ static void connection(TCPSocket &socket)
       answer += templ->course.attributes["name"];
       answer += "\">\n";
       
+      bool foundmacro = false;
+
       // Generate the macro and return it to the client
       std::vector< Macro >::iterator mi2 = templ->course.macroes.begin();
       while(mi2 != templ->course.macroes.end()) {
@@ -162,11 +170,12 @@ static void connection(TCPSocket &socket)
         answer += "    <macro name=\"" + macro.attributes["name"] + "\" completed=";
         if(db.checkMacro(transaction.cpr, macro.attributes["name"])) answer += "\"true\"";
         else answer += "\"false\"";
-        // answer += " resume=\"" + macro.attributes["resume"] + "\"";
         answer += ">\n";
         
         if(macro.attributes["name"] == request.macro) {
 
+          foundmacro = true;
+
           MacroParser mp(request.macro);
           mp.parse();
           Macro *m = mp.getMacro();
@@ -189,9 +198,14 @@ static void connection(TCPSocket &socket)
         }
         answer += "    </macro>\n";
         mi2++;
+
       }
       
+      if(foundmacro == false && request.macro != "")
+        throw NotFoundException(request);
+
       answer += "  </course>\n";
+
       socket.write(answer);
       i++;
     }
-- 
cgit v1.2.3