Difference between revisions of "U23 2007/NULL.0"

From C4 Wiki
Jump to: navigation, search
Line 3: Line 3:
 
aus Köln
 
aus Köln
  
==Team==
+
== Team ==
 
* Stefan
 
* Stefan
 
* Philipp
 
* Philipp
Line 9: Line 9:
 
* Hanno
 
* Hanno
  
==Links==
+
== Links ==
  
 
:'''I2C'''
 
:'''I2C'''
Line 15: Line 15:
 
:http://www.roboternetz.de/wissen/index.php/I2C
 
:http://www.roboternetz.de/wissen/index.php/I2C
  
==Projekt==
+
== Projek t==
===Idee===
+
=== Idee ===
 
Haben wir nun schon ein Ziel?
 
Haben wir nun schon ein Ziel?
 
Vorschläge bitte :D
 
Vorschläge bitte :D
Line 45: Line 45:
  
  
==HTTP SERVER==
+
== HTTP-Server ==
  
===zerohttp.c===
+
=== git ===
 +
 
 +
Das [http://de.wikipedia.org/wiki/Git Git]-Repository kann man sich mit folgendem Kommando besorgen:
 +
 
 +
<pre>
 +
git clone git://git.haemoglobin.org/zerohttp
 +
</pre>
 +
 
 +
Um die neuesten Updates zu bekommen:
 +
 
 +
<pre>
 +
cd zerohttp
 +
git pull
 +
</pre>
 +
 
 +
=== zerohttp.c ===
  
 
[http://www.haemoglobin.org/U23_2007/zerohttp.c zerohttp.c]
 
[http://www.haemoglobin.org/U23_2007/zerohttp.c zerohttp.c]
 +
 
<pre>
 
<pre>
 
#include <string.h>
 
#include <string.h>
Line 148: Line 164:
  
 
[http://www.haemoglobin.org/U23_2007/tokenize.c tokenize.c]
 
[http://www.haemoglobin.org/U23_2007/tokenize.c tokenize.c]
 +
 
<pre>
 
<pre>
 
/*
 
/*
Line 230: Line 247:
 
</pre>
 
</pre>
  
===tokenize.h===
+
=== tokenize.h ===
  
 
[http://www.haemoglobin.org/U23_2007/tokenize.h tokenize.h]
 
[http://www.haemoglobin.org/U23_2007/tokenize.h tokenize.h]
Line 237: Line 254:
 
char *strtokn(char *, unsigned int, char);
 
char *strtokn(char *, unsigned int, char);
 
char *strtokz(char *, char);
 
char *strtokz(char *, char);
 
 
</pre>
 
</pre>
 
  
 
[[Category:U23 2007]]
 
[[Category:U23 2007]]

Revision as of 22:15, 11 June 2007

Gruppe NULL.0

aus Köln

Team

  • Stefan
  • Philipp
  • Sebi
  • Hanno

Links

I2C
http://www.roboternetz.de/wissen/index.php/I2C

Projek t

Idee

Haben wir nun schon ein Ziel? Vorschläge bitte :D

Ich finde Server und Netzwerkgeschichten interessant: hier die die schon genannt wurden:

  1. NAS-Server zu Hause übers www einschalten(evtl. auch per Tel. zu aktivieren?) //dirtyheizer aka Marcus
  2. Network monitoring // Obstfliege aka Philipp
  3. Diverse Server: DHCP,DNS,FTP,HTTP... // Obstfliege aka Philipp

Hatten wir uns nicht grob auf folgendes geeinigt?

  • Audio Sound Steuerung
    • 4 analog Stereo in & 4 Lautsprecher out = front Rear Stero OUT
    • Lautstärkeregelung & Wahl des Einganges
    • WWW Interface
    • Infrarot Fernbedienung zum Ansteuern

Das waren dann 4 Teilprojekte (JavaScript, Infrarot, C-Software, Hardware Löten), das kann man teilweise noch aufteilen. Und beinhaltet so grob jedes Gebiet!
Aber ich weiß nicht, ob so nen Tuner so viel bringt. Mein Interesse ist da eher gering.

Alternativ:

  1. USB Ansteuerung

@Philipp deine Vorschläge sind aber auch ganz nett, auch wenn sie rein softwaremäßig ablaufen. Network Monitoring würde mich glaub ich am meisten interessieren. --Hanno 23:14, 31 May 2007 (CEST)

@Hanno: Ja Monitoring interessiert mich auch besonders. --Philipp


HTTP-Server

git

Das Git-Repository kann man sich mit folgendem Kommando besorgen:

git clone git://git.haemoglobin.org/zerohttp

Um die neuesten Updates zu bekommen:

cd zerohttp
git pull

zerohttp.c

zerohttp.c

#include <string.h>

#include "tokenize.h"

void zerohttp_invalid(char *data) {
	strcpy_P(data, PSTR("HTTP/1.1 400 Invalid request\r\n"
	 "Server: zerohttp\r\n"
	 "Connection: close\r\n"
	 "Content-Type: text/plain\r\n\r\n"
	 "Invalid request!"));
	uip_send(data, strlen(data));
}

void zerohttp_succeed(char *data) {
	strcpy_P(data, PSTR("HTTP/1.1 200 OK\r\n"
	 "Server: zerohttp\r\n"
	 "Connection: close\r\n"
	 "Content-Type: text/plain\r\n\r\n"
	 "Thy wish is my command."));
	uip_send(data, strlen(data));
}

void zerohttp_fail(char *data) {
	strcpy_P(data, PSTR("HTTP/1.1 404 Command not found\r\n"
	 "Server: zerohttp\r\n"
	 "Connection: close\r\n"
	 "Content-Type: text/plain\r\n\r\n"
	 "I could not fullfill thy humbly wish."));
	uip_send(data, strlen(data));
}

void zerohttp_main() {
	char *data = (char*) uip_appdata;
	
	register char *garbage;
	char *uri;


	uip_listen(HTONS(80));

	if(uip_newdata()) {
		garbage = strtokz(data, ' ');
		if(garbage) {
			zerohttp_invalid(data);
			uip_close();
		}

		if(strncmp(garbage, PSTR("GET"), 4)) {
			zerohttp_invalid(data);
			uip_close();
		}

		uri = strtokz(NULL, ' ');
		if(uri) {
			zerohttp_invalid(data);
			uip_close();
		}

		garbage = strtokz(NULL, '\r');
		if(garbage) {
			zerohttp_invalid(data);
			uip_close();
		}

		if(strncmp(garbage, PSTR("HTTP/1.0"), 9) && strncmp(garbage, PSTR("HTTP/1.1"), 9)) {
			zerohttp_invalid(data);
			uip_close();
		}

		if(!strncmp(uri, PSTR("http://"), 7))
			uri += 7;
		else
			uri++;

		if(!strncmp(uri, PSTR("lauter"), 7)) {
			// Lauter!
			zerohttp_succeed();
			uip_close();
		}
		else if(!strncmp(uri, PSTR("leiser"), 7)) {
			// Leiser!
			zerohttp_succeed();
			uip_close();
		}
		else {
			zerohttp_fail();
			uip_close();
		}

	}
}

tokenize.c

tokenize.c

/*
 * Copyright © MMVII
 *      Mikael Voss <ffefd6 at haemoglobin dot org>
 *
 * Provided that these terms and disclaimer and all copyright notices
 * are retained or reproduced in an accompanying document, permission
 * is granted to deal in this work without restriction, including un-
 * limited rights to use, publicly perform, distribute, sell, modify,
 * merge, give away, or sublicence.
 *
 * This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to
 * the utmost extent permitted by applicable law, neither express nor
 * implied; without malicious intent or gross negligence. In no event
 * may a licensor, author or contributor be held liable for indirect,
 * direct, other damage, loss, or other issues arising in any way out
 * of dealing in the work, even if advised of the possibility of such
 * damage or existence of a defect, except proven that it results out
 * of said person's immediate fault when using the work as intended.
 */

/*
 * strtokn parses a string of length bytes into a sequence of tokens
 * separated by delimiter. On the first call the string to be parsed
 * should be specified in string and its size in length. On each sub-
 * sequent call that should parse the same string, string should be
 * (char *) 0 and length will be ignored.
 * It returns the next token delimited by delimiter or (char *) 0 if
 * no other token is found.
 */

char *strtokn(char *string, unsigned int length, char delimiter) {
	static char *next;
	static unsigned int rest;
	register unsigned int iterator;

	if(string != (char *) 0) {
		next = string;
		rest = length;
	}

	for(iterator = 0; iterator < rest; iterator++) {
		if(next[iterator] == delimiter) {
			next[iterator] = '\0';
			string = next;
			next += iterator + 1;
			rest -= iterator - 1;
			return string;
		}
	}

	return (char *) 0;
}


/*
 * strtokz does the same as strtokn, but operates on a zero-terminated
 * string and thus does not take a length argument. Be careful as this
 * function might lead to buffer overflows if string is not properly
 * terminated!
 */

char *strtokz(char *string, char delimiter) {
	static char *next;

	if(string != (char *) 0)
		next = string;
	else
		string = next;

	while(*next++) {
		if(*next == delimiter) {
			*next++ = '\0';
			return string;
		}
	}

	return (char *) 0;
}

tokenize.h

tokenize.h

char *strtokn(char *, unsigned int, char);
char *strtokz(char *, char);