summaryrefslogtreecommitdiff
path: root/src/server.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/server.cc')
-rw-r--r--src/server.cc116
1 files changed, 8 insertions, 108 deletions
diff --git a/src/server.cc b/src/server.cc
index fad79ae..e6a6ff7 100644
--- a/src/server.cc
+++ b/src/server.cc
@@ -31,6 +31,11 @@
/*
* $Log$
+ * Revision 1.24 2005/06/19 11:44:14 deva
+ * Cleaned up a log of logging.
+ * Fixed server queue (shouldn't happen).
+ * Added user and group lookup.
+ *
* Revision 1.23 2005/06/14 18:58:35 deva
* *** empty log message ***
*
@@ -198,125 +203,18 @@ void saveFrameAsImage(char* cpr, Frame *f)
fprintf(stderr, "Success - using filename: [%s.jpg]\n", fname); fflush(stderr);
imgenc.encode(f, fname, 100); // Quality is between 0...100, where 100 is best.
}
-/*
-struct tm
-{
- int tm_sec; // Seconds. [0-60] (1 leap second)
- int tm_min; // Minutes. [0-59]
- int tm_hour; // Hours. [0-23]
- int tm_mday; // Day. [1-31]
- int tm_mon; // Month. [0-11]
- int tm_year; // Year - 1900.
- int tm_wday; // Day of week. [0-6]
- int tm_yday; // Days in year.[0-365]
- int tm_isdst; // DST. [-1/0/1]
-};
-*/
-
-MovEncoderThread *newMovEncoder(char* cpr)
-{
- /*
- MovEncoderThread *enc;
- struct tm *ltime;
- time_t t = time(NULL);
- FILE *fp;
- int cnt = 0;
- char fname[256];
- char birthmonth[3];
- char date[9];
-
- string *root = config->readString("server_root");
-
- // Test for server root writeability
- sprintf(fname, "%s/miavtemp.tmp%d", (char*)root->c_str(), rand());
- fp = fopen(fname, "w");
- if(!fp) {
- int r = rand();
- fprintf(stderr, "MIaV does not have write access to the server root [%s]\n", root->c_str());
- fprintf(stderr, "Redirecting output to [/tmp/miav-%d.mpg]\n", r);
- sprintf(fname, "/tmp/miav-%d", r);
- enc = new MovEncoderThread(fname);
- return enc;
- }
- fclose(fp);
- unlink(fname);
-
- // Check for cpr length correctness
- if(strlen(cpr) != 11) {
- int r = rand();
- fprintf(stderr, "Illigal CPR, it must have length 11, it had lentgh %d\n", strlen(cpr));
- fprintf(stderr, "Redirecting output to [/tmp/miav-%d.mpg]\n", r);
- sprintf(fname, "/tmp/miav-%d", r);
- enc = new MovEncoderThread(fname);
- return enc;
- }
-
- // Copy the bytes representing the birth month from the cpr
- // [dd][mm][yy]-[nn][nn]
- strncpy(birthmonth, &cpr[2], 2);
- birthmonth[2] = 0;
-
- // Create folder named birthmonth in server root
- sprintf(fname, "%s/%s", root->c_str(), birthmonth);
- if(!mkdir(fname, S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH | S_IROTH) == -1 && errno != EEXIST) {
- int r = rand();
- fprintf(stderr, "Not possible to create subfolder %s\n", fname);
- fprintf(stderr, "Redirecting output to [/tmp/miav-%d.mpg]\n", r);
- sprintf(fname, "/tmp/miav-%d", r);
- enc = new MovEncoderThread(fname);
- return enc;
- }
-
- // Create folder named cpr in serverroot/birthmonth
- sprintf(fname, "%s/%s/%s", root->c_str(), birthmonth, cpr);
- if(!mkdir(fname, S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH | S_IROTH) == -1 && errno != EEXIST) {
- int r = rand();
- fprintf(stderr, "Not possible to create subfolder %s\n", fname);
- fprintf(stderr, "Redirecting output to [/tmp/miav-%d.mpg]\n", r);
- sprintf(fname, "/tmp/miav-%d", r);
- enc = new MovEncoderThread(fname);
- return enc;
- }
-
- // Create date (today) in [yyyy][mm][dd]
- ltime = localtime(&t);
- sprintf(date, "%.4d%.2d%.2d",
- ltime->tm_year + 1900,
- ltime->tm_mon,
- ltime->tm_mday);
-
- // Create filename: [serverroot]/[birthmonth]/[cpr]/[cpr]-[date]-[cnt].mpg
- sprintf(fname, "%s/%s/%s/%s-%s-%.3d.mpg", root->c_str(), birthmonth, cpr, cpr, date, cnt);
-
- // test filename-[cnt] for existamce cnt++ until not existing.
- fp = fopen(fname, "r");
- while(fp) {
- fclose(fp);
- cnt++;
- sprintf(fname, "%s/%s/%s/%s-%s-%.3d.mpg", root->c_str(), birthmonth, cpr, cpr, date, cnt);
- fp = fopen(fname, "r");
- }
- sprintf(fname, "%s/%s/%s/%s-%s-%.3d", root->c_str(), birthmonth, cpr, cpr, date, cnt);
-
- fprintf(stderr, "Success - using filename: [%s.mpg]\n", fname); fflush(stderr);
- enc = new MovEncoderThread(fname);
- return enc;
-*/
- return NULL;
-}
void newConnection(Socket *socket, Info *info)
{
char cpr[256];
bool hasCpr = false;
- ServerStatus status;
+ ServerStatus status(info);
n_savestate savestate = LATER;
n_header h;
Frame *frame;
Frame *freeze_frame = NULL;
MovEncoderThread *enc = NULL;
- // unsigned char dvbuf[DVPACKAGE_SIZE];
frame = new Frame(NULL, DVPACKAGE_SIZE);
@@ -324,7 +222,9 @@ void newConnection(Socket *socket, Info *info)
Network network = Network(socket, info);
while(int ret = network.recvPackage(&h, frame->data, frame->size)) {
+
status.checkPoint();
+
if(ret == -1) {
info->error("A network error ocurred, terminating session");
break;