diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/Buffer.cc | 22 | ||||
| -rw-r--r-- | lib/Confirm.cc | 2 | ||||
| -rw-r--r-- | lib/CopyJob.cc | 16 | ||||
| -rw-r--r-- | lib/Form.cc | 2 | ||||
| -rw-r--r-- | lib/Handle.cc | 2 | ||||
| -rw-r--r-- | lib/HttpServ.cc | 15 | ||||
| -rw-r--r-- | lib/Image.cc | 78 | ||||
| -rw-r--r-- | lib/Input.cc | 6 | ||||
| -rw-r--r-- | lib/Makefile.am | 2 | ||||
| -rw-r--r-- | lib/Menu.cc | 2 | ||||
| -rw-r--r-- | lib/Message.cc | 2 | ||||
| -rw-r--r-- | lib/Output.cc | 4 | ||||
| -rw-r--r-- | lib/Table.cc | 2 | ||||
| -rw-r--r-- | lib/TaskMan.cc | 5 | 
14 files changed, 136 insertions, 24 deletions
| diff --git a/lib/Buffer.cc b/lib/Buffer.cc index 2c2c955..e8335d9 100644 --- a/lib/Buffer.cc +++ b/lib/Buffer.cc @@ -3,7 +3,7 @@  #include "General.h"  #include "config.h" -Buffer::Buffer() : Handle(-1), buffer(0), realsiz(0), bufsiz(0), ptr(0) { } +Buffer::Buffer() : Handle(-1), buffer(0), zero(0), realsiz(0), bufsiz(0), ptr(0) { }  Buffer::~Buffer() {      free(buffer); @@ -75,3 +75,23 @@ Buffer Buffer::operator=(const Buffer & b) {  bool Buffer::CanWatch() {      return false;  } + +ssize_t Buffer::GetSize() { +    return realsiz; +} + +char Buffer::operator[](size_t p) const { +    if (p >= realsiz) { +	return 0; +    } else { +	return buffer[ptr + p]; +    } +} + +char & Buffer::operator[](size_t p) { +    if (p >= realsiz) { +	return zero; +    } else { +	return buffer[ptr + p]; +    } +} diff --git a/lib/Confirm.cc b/lib/Confirm.cc index 7d72ee0..1176db1 100644 --- a/lib/Confirm.cc +++ b/lib/Confirm.cc @@ -7,7 +7,7 @@  Confirm::Confirm(const String & t, const String & m, const String & U, Action * y, Action * n) :      Action(U), tit(t), msg(m), NYes(y), NNo(n) { } -Task * Confirm::Do(Variables * v, Handle * h) { +Task * Confirm::Do(Variables * v, Variables *, Handle * h) {      Handle * b = new Buffer;      Task * t = new CopyJob(b, h, -1, true);      SendHead(b); diff --git a/lib/CopyJob.cc b/lib/CopyJob.cc index 864706b..1e151c3 100644 --- a/lib/CopyJob.cc +++ b/lib/CopyJob.cc @@ -2,13 +2,21 @@  #include "General.h"  #include "config.h" -CopyJob::CopyJob(Handle * as, Handle * ad, ssize_t asiz, bool ads) : s(as), d(ad), ds(ads), siz(asiz), cursiz(0), r(0) { +CopyJob::CopyJob(Handle * as, Handle * ad, ssize_t asiz, bool ads, bool add) : s(as), d(ad), ds(ads), dd(add), siz(asiz), cursiz(0), r(0) {      s->SetNonBlock();      d->SetNonBlock();      WaitFor(s, W4_READING);  } -CopyJob::~CopyJob() { } +CopyJob::~CopyJob() { +    if (ds) { +	delete s; +    } +     +    if (dd) { +	delete d; +    } +}  int CopyJob::Do() throw (GeneralException) {      int tr; @@ -44,10 +52,6 @@ int CopyJob::Do() throw (GeneralException) {  	Suspend(TASK_ON_HOLD);      } -    if (ds) { -	delete s; -    } -          return TASK_DONE;  } diff --git a/lib/Form.cc b/lib/Form.cc index e26cf72..464dec3 100644 --- a/lib/Form.cc +++ b/lib/Form.cc @@ -12,7 +12,7 @@ String Form::GetTitle(void) {      return tit;  } -Task * Form::Do(Variables * v, Handle * h) { +Task * Form::Do(Variables * v, Variables *, Handle * h) {      Handle * b = new Buffer();      Task * t = new CopyJob(b, h, -1, true);      SendHead(b); diff --git a/lib/Handle.cc b/lib/Handle.cc index 0221e71..4585b61 100644 --- a/lib/Handle.cc +++ b/lib/Handle.cc @@ -174,7 +174,7 @@ String Handle::GetName(void) {      return _("Bare Handle - should not happend");  } -off_t Handle::GetSize(void) { +ssize_t Handle::GetSize(void) {      return -1;  } diff --git a/lib/HttpServ.cc b/lib/HttpServ.cc index c20862a..d2c3c02 100644 --- a/lib/HttpServ.cc +++ b/lib/HttpServ.cc @@ -33,7 +33,7 @@ class ProcessRequest : public Task {      Socket s;      String name, host; -    Variables * Vars; +    Variables * Vars, * Heads;      bool bad, hasvars, post;  }; @@ -63,9 +63,12 @@ int ProcessRequest::Do() {  //	cerr << "---- Got a request from handle " << s.GetHandle() << " \n";          post = ParseUri(file, domain, &b); +	 +	Heads = new Variables();          len = -1;          do { +	    int p;      	    b >> t;  //	    cerr << "Read Request (n): " << t << endl;  	    if ((t.strstr("Content-Length: ") == 0) || (t.strstr("Content-length: ") == 0)) { @@ -75,6 +78,13 @@ int ProcessRequest::Do() {  	    if (t.strstr("Host: ") == 0) {  		host = t.extract(6);  	    } +	     +	    if ((p = t.strchr(':')) >= 0) { +		String s = t.extract(0, p - 1); +		s += '='; +		s += t.extract(p + 2); +		Heads->Add(s); +	    }  	} while (t.strlen());  //	cerr << "---- Processing it.\n"; @@ -144,7 +154,7 @@ int ProcessRequest::Do() {  		// Le domaine 'bin' est réservé aux actions. On cherche donc l'action à effectuer.  	        if ((f = p->Look4URL(file))) {      		    SendHeads(&b, "text/html"); -		    a = f->Do(Vars, &s); +		    a = f->Do(Vars, Heads, &s);  		} else {  		    ShowError(&b);  	        } @@ -169,6 +179,7 @@ int ProcessRequest::Do() {  	if (a) a->Stop();  	delete Vars; +	delete Heads;  //	cerr << "---- Sending header buffer.\n";  	c = new CopyJob(&b, &s, -1, false);  	WaitFor(c); diff --git a/lib/Image.cc b/lib/Image.cc new file mode 100644 index 0000000..9b41b4e --- /dev/null +++ b/lib/Image.cc @@ -0,0 +1,78 @@ +#include "Image.h" +#include "config.h" + +Image::Image(unsigned int ax, unsigned int ay) : x(ax), y(ay), img((Color *) malloc(x * y * sizeof(Color))) { +    Fill(); +} + +Image::~Image() { +    free((void *)img); +} + +bool Image::CanWrite() { +    return false; +} + +String Image::GetName() { +    return String(_("Image ")) + x + "x" + y; +} + +void Image::Fill(Color c) { +    for (unsigned int i = 0; i < x * y; i++) { +	img[i] = c; +    } +} + +Color Image::GetPixel(unsigned int px, unsigned int py) { +    if ((px >= x) || (py >= y)) { +	return Color(0, 0, 0, 0); +    } +     +    return img[x * py + px]; +} + +void Image::SetPixel(unsigned int px, unsigned int py, Color c) { +    if ((px >= x) || (py >= y)) { +	return; +    } + +    img[x * py + px] = c; +} + +bool Image::Prepare(unsigned int f) { +    if (GetSize()) return false; +     +    switch (f) { +	case FORMAT_TGA_BASIC: +	    TGAHeader Header; +	    TGAFooter Footer; +	     +	    Header.IDLength = 0; +	    Header.ColorMapType = 0; +	    Header.ImageType = 2; +	    Header.CM_FirstEntry = 0; +	    Header.CM_Length = 0; +	    Header.CM_EntrySize = 0; +	    Header.IS_XOrigin = 0; +	    Header.IS_YOrigin = 0; +	    Header.IS_Width = x; +	    Header.IS_Height = y; +	    Header.IS_Depth = 32; +	    Header.IS_Descriptor = 0x20; + +	    Footer.ExtOffset = 0; +	    Footer.DevOffset = 0; +	    strcpy(Footer.Sig, "TRUEVISION-XFILE."); +	     +	    write(&Header, sizeof(Header)); +	    write(img, x * y * sizeof(Color)); +	    write(&Footer, sizeof(Footer)); +	     +	    return true; +	     +	    break; +	default: +	    return false; +    } +} + diff --git a/lib/Input.cc b/lib/Input.cc index be6981f..318821d 100644 --- a/lib/Input.cc +++ b/lib/Input.cc @@ -10,10 +10,10 @@  #include "config.h"  Input::Input(String no) throw (GeneralException) : -    Handle(no.strlen() ? open(no.to_charp(), O_RDONLY) : 0), +    Handle(no.strlen() ? open(no.to_charp(), O_RDONLY) : dup(0)),      n(no) {      if (GetHandle() < 0) { -	throw IOGeneral(String(_("Error opening file")) + no + _(" for reading: ") + strerror(errno)); +	throw IOGeneral(String(_("Error opening file ")) + no + _(" for reading: ") + strerror(errno));      }      size = lseek(GetHandle(), 0, SEEK_END); @@ -38,7 +38,7 @@ String Input::GetName() {      return n;  } -off_t Input::GetSize() { +ssize_t Input::GetSize() {      return size;  } diff --git a/lib/Makefile.am b/lib/Makefile.am index a88f7be..a2f0930 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -8,6 +8,6 @@ lib_LTLIBRARIES = libBaltisot.la  libBaltisot_la_SOURCES = Exceptions.cc Handle.cc Output.cc String.cc\   Socket.cc Input.cc HttpServ.cc Variables.cc Action.cc Menu.cc Message.cc\   Form.cc Confirm.cc Table.cc checkargs.c datecalc.c IRC.cc Task.cc Buffer.cc\ - CopyJob.cc ReadJob.cc Regex.cc TaskMan.cc InPipe.cc OutPipe.cc + CopyJob.cc ReadJob.cc Regex.cc TaskMan.cc InPipe.cc OutPipe.cc Image.cc  libBaltisot_la_LDFLAGS = -release $(Baltisot_VERSION_INFO) diff --git a/lib/Menu.cc b/lib/Menu.cc index f804cef..f730e5b 100644 --- a/lib/Menu.cc +++ b/lib/Menu.cc @@ -7,7 +7,7 @@  Menu::Menu(const String & t, const String & U, String * ts, Action ** as, int nb) :      Action(U), tit(t), lt(ts), la(as), nba(nb) { } -Task * Menu::Do(Variables * v, Handle * h) { +Task * Menu::Do(Variables * v, Variables *, Handle * h) {      int i, f = 0;      Handle * b = new Buffer();      Task * t = new CopyJob(b, h, -1, true); diff --git a/lib/Message.cc b/lib/Message.cc index acd7933..572b0a0 100644 --- a/lib/Message.cc +++ b/lib/Message.cc @@ -7,7 +7,7 @@  Message::Message(const String & t, const String & m, const String & U, Action * n) :      Action(U), tit(t), msg(m), Next(n) { } -Task * Message::Do(Variables * v, Handle * h) { +Task * Message::Do(Variables * v, Variables *, Handle * h) {      Handle * b = new Buffer();      Task * t = new CopyJob(b, h, -1, true); diff --git a/lib/Output.cc b/lib/Output.cc index c85d372..27f28d2 100644 --- a/lib/Output.cc +++ b/lib/Output.cc @@ -10,10 +10,10 @@  #include "config.h"  Output::Output(String no, int trunc = 1) throw (GeneralException) : -    Handle(no.strlen() ? open(no.to_charp(), O_WRONLY | O_CREAT | (trunc ? O_TRUNC : O_APPEND)) : 1), +    Handle(no.strlen() ? open(no.to_charp(), O_WRONLY | O_CREAT | (trunc ? O_TRUNC : O_APPEND), 00666) : dup(1)),      n(no) {      if (GetHandle() < 0) { -	throw IOGeneral(String(_("Error opening file")) + no + _(" for writing: ") + strerror(errno)); +	throw IOGeneral(String(_("Error opening file ")) + no + _(" for writing: ") + strerror(errno));      }  } diff --git a/lib/Table.cc b/lib/Table.cc index 30f3127..f2b7bad 100644 --- a/lib/Table.cc +++ b/lib/Table.cc @@ -11,7 +11,7 @@ String Table::GetTitle(void) {      return tit;  } -Task * Table::Do(Variables * v, Handle * h) { +Task * Table::Do(Variables * v, Variables *, Handle * h) {      Handle * b = new Buffer();      Task * t = new CopyJob(b, h, -1, true); diff --git a/lib/TaskMan.cc b/lib/TaskMan.cc index 9053d0b..94e89b1 100644 --- a/lib/TaskMan.cc +++ b/lib/TaskMan.cc @@ -212,7 +212,7 @@ void TaskMan::MainLoop() throw (GeneralException) {  		}  	    } -	    r = poll(ufsd, nfds, (no_burst) && !(Zombies.size()) ? -1: 1); +	    r = poll(ufsd, nfds, (no_burst) && !(Zombies.size()) ? -1: 0);  #else  	    FD_ZERO(readfds);  	    FD_ZERO(writefds); @@ -232,7 +232,7 @@ void TaskMan::MainLoop() throw (GeneralException) {  	    r = select(highest + 1, &readfds, &writefds, &exceptfds, NULL);  #endif -	    if (r == -1) { +	    if (r < 0) {  		if (errno == EINTR) {  		    // child  		} else { @@ -256,7 +256,6 @@ void TaskMan::MainLoop() throw (GeneralException) {  		    if (q->revents & POLLHUP) {  			cerr << _("Handle ") << q->fd << _(" hung up.\n"); -			// What should I do now?  		    }  		    fd = q->fd; | 
