r1650 - in dev/concept/moongoo: . libalfs syntax test

neocool at linuxfromscratch.org neocool at linuxfromscratch.org
Mon Dec 13 16:51:03 PST 2004


Author: neocool
Date: 2004-12-13 17:51:02 -0700 (Mon, 13 Dec 2004)
New Revision: 1650

Added:
   dev/concept/moongoo/README
   dev/concept/moongoo/libalfs/crypto.c
   dev/concept/moongoo/libalfs/crypto.h
   dev/concept/moongoo/syntax/diyl.c
   dev/concept/moongoo/test/tst_md5.c
   dev/concept/moongoo/test/tst_sha1.c
Modified:
   dev/concept/moongoo/Makefile
   dev/concept/moongoo/inc.mak
   dev/concept/moongoo/libalfs/Makefile
   dev/concept/moongoo/libalfs/alfs.c
   dev/concept/moongoo/libalfs/alfs.h
   dev/concept/moongoo/libalfs/gen.c
   dev/concept/moongoo/libalfs/gen.h
   dev/concept/moongoo/libalfs/libalfs.h
   dev/concept/moongoo/syntax/
   dev/concept/moongoo/syntax/Makefile
   dev/concept/moongoo/syntax/ass.c
   dev/concept/moongoo/syntax/syn.c
   dev/concept/moongoo/test/
   dev/concept/moongoo/test/Makefile
   dev/concept/moongoo/test/tst_squeeze.c
Log:
Update.


Modified: dev/concept/moongoo/Makefile
===================================================================
--- dev/concept/moongoo/Makefile	2004-12-13 14:14:27 UTC (rev 1649)
+++ dev/concept/moongoo/Makefile	2004-12-14 00:51:02 UTC (rev 1650)
@@ -4,14 +4,15 @@
 OBJS=build.o moongoo.o plugin.o url.o
 
 ifeq ($(OPTS),)
-OPTS=-q -s blfs
-#OPTS+=~/projects/alfs/book/index.xml
+OPTS=-q #-s ass
+OPTS+=~/projects/alfs/book/index.xml
 #OPTS+=~/projects/alfs/lfs-profile/LFS.xml
 #OPTS+=~/projects/alfs/ass/index.xml
 #OPTS+=~/projects/hive/unstable/profile.xml
-OPTS+=~/projects/alfs/blfs/index.xml
+#OPTS+=~/projects/alfs/blfs/index.xml
 #OPTS+=~/projects/alfs/hlfs/index.xml
 #OPTS+=~/projects/alfs/book-rng/index.xml
+#OPTS+=~/projects/alfs/refbuild/xml/x86-reference-build.xml
 endif
 
 SUBDIRS=libalfs syntax test

Added: dev/concept/moongoo/README
===================================================================
--- dev/concept/moongoo/README	2004-12-13 14:14:27 UTC (rev 1649)
+++ dev/concept/moongoo/README	2004-12-14 00:51:02 UTC (rev 1650)
@@ -0,0 +1,14 @@
+Moongoo
+-------
+
+* Dependencies:
+
+libcurl 	http://curl.haxx.se/
+libtar 		http://www.feep.net/libtar/
+libxml2 	http://www.xmlsoft.org/
+openssl		http://www.openssl.org/
+
+libtar can be installed by cmmi, all others are in BLFS.
+
+--
+Boris Buegling <boris at icculus.org>

Modified: dev/concept/moongoo/inc.mak
===================================================================
--- dev/concept/moongoo/inc.mak	2004-12-13 14:14:27 UTC (rev 1649)
+++ dev/concept/moongoo/inc.mak	2004-12-14 00:51:02 UTC (rev 1650)
@@ -3,7 +3,7 @@
 CFLAGS+=-Wall -Werror -g3
 
 CFLAGS+=`xml2-config --cflags` `curl-config --cflags`
-LDLIBS+=`xml2-config --libs` `curl-config --libs` -ldl
+LDLIBS+=`xml2-config --libs` `curl-config --libs` -ldl -ltar -lcrypto
 
 .PHONY: clean todo all-subdirs clean-subdirs sloccount
 

Modified: dev/concept/moongoo/libalfs/Makefile
===================================================================
--- dev/concept/moongoo/libalfs/Makefile	2004-12-13 14:14:27 UTC (rev 1649)
+++ dev/concept/moongoo/libalfs/Makefile	2004-12-14 00:51:02 UTC (rev 1650)
@@ -1,7 +1,7 @@
 CFLAGS=-I.
 
 LIB=libalfs.a
-OBJS=alfs.o devel.o gen.o net.o parse.o repl.o util.o
+OBJS=alfs.o crypto.o devel.o gen.o net.o parse.o repl.o util.o
 
 all: $(LIB)
 
@@ -12,6 +12,7 @@
 	ranlib $@
 
 alfs.o: alfs.h
+crypto.o: crypto.h
 devel.o: devel.h
 gen.o: gen.h
 net.o: net.h

Modified: dev/concept/moongoo/libalfs/alfs.c
===================================================================
--- dev/concept/moongoo/libalfs/alfs.c	2004-12-13 14:14:27 UTC (rev 1649)
+++ dev/concept/moongoo/libalfs/alfs.c	2004-12-14 00:51:02 UTC (rev 1650)
@@ -449,9 +449,9 @@
 	{
 		case (ALGO_NONE):
 			return "none";
-		case (MD5):
+		case (ALGO_MD5):
 			return "md5";
-		case (SHA1):
+		case (ALGO_SHA1):
 			return "sha1";
 		default:
 			return "unknown";

Modified: dev/concept/moongoo/libalfs/alfs.h
===================================================================
--- dev/concept/moongoo/libalfs/alfs.h	2004-12-13 14:14:27 UTC (rev 1649)
+++ dev/concept/moongoo/libalfs/alfs.h	2004-12-14 00:51:02 UTC (rev 1650)
@@ -22,8 +22,8 @@
 typedef enum
 {
 	ALGO_NONE = 1,
-	MD5,
-	SHA1
+	ALGO_MD5,
+	ALGO_SHA1
 } hash_algo;
 
 typedef enum

Added: dev/concept/moongoo/libalfs/crypto.c
===================================================================
--- dev/concept/moongoo/libalfs/crypto.c	2004-12-13 14:14:27 UTC (rev 1649)
+++ dev/concept/moongoo/libalfs/crypto.c	2004-12-14 00:51:02 UTC (rev 1650)
@@ -0,0 +1,51 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <openssl/md5.h>
+#include <openssl/sha.h>
+
+#include <alfs.h>
+#include <crypto.h>
+#include <gen.h>
+
+static char *__hashsum (char *fname, hash_algo algo)
+{
+	char *ret;
+	unsigned char *digest, *data;
+	unsigned long data_len, i, len;
+
+	data = read_file(fname);
+	data_len = strlen(data);
+	switch (algo)
+	{
+		case ALGO_MD5:
+			len = MD5_DIGEST_LENGTH;
+			digest = (char *)malloc(len+1);
+			MD5(data, data_len, digest);
+			break;
+		case ALGO_SHA1:
+			len = SHA_DIGEST_LENGTH;
+			digest = (char *)malloc(len+1);
+			SHA1(data, data_len, digest);
+			break;
+		default:
+			fprintf(stderr, "Unknown hash algorithm.\n");
+			return NULL;
+	}
+	ret = (char *)malloc(42);
+	strcpy(ret, "");
+	for (i=0;i<len;i++)
+		sprintf(ret, "%s%02x", ret, digest[i]);
+	return ret;
+}
+
+char *md5sum (char *fname)
+{
+	return __hashsum(fname, ALGO_MD5);
+}
+
+char *sha1sum (char *fname)
+{
+	return __hashsum(fname, ALGO_SHA1);
+}

Added: dev/concept/moongoo/libalfs/crypto.h
===================================================================
--- dev/concept/moongoo/libalfs/crypto.h	2004-12-13 14:14:27 UTC (rev 1649)
+++ dev/concept/moongoo/libalfs/crypto.h	2004-12-14 00:51:02 UTC (rev 1650)
@@ -0,0 +1,7 @@
+#ifndef __CRYPTO_H__
+#define __CRYPTO_H__
+
+char *sha1sum (char *fname);
+char *md5sum (char *fname);
+
+#endif

Modified: dev/concept/moongoo/libalfs/gen.c
===================================================================
--- dev/concept/moongoo/libalfs/gen.c	2004-12-13 14:14:27 UTC (rev 1649)
+++ dev/concept/moongoo/libalfs/gen.c	2004-12-14 00:51:02 UTC (rev 1650)
@@ -1,3 +1,9 @@
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <libtar.h>
+
 #include <gen.h>
 
 const char *compr[NUM_COMPR] = { ".bz2", ".gz" };
@@ -2 +8,79 @@
 const char *unpck[NUM_COMPR] = { "tar xfj ", "tar xfz " };
+
+char *directory (char *tarball)
+{
+	char *ret;
+	TAR *t = NULL;
+
+	tar_open(&t, tarball, NULL, O_RDONLY, 0, 0);
+	
+	if (!t)
+		return NULL;
+	
+	th_read(t);
+	ret = th_get_pathname(t);
+	tar_close(t);
+
+	return ret;
+}
+
+char *read_file (char *fname)
+{
+	FILE *f;
+	int sz=0;
+	char c, *ch=calloc(1, sizeof(char));
+
+	if (!fname)
+	{
+		free(ch);
+		return NULL;
+	}
+
+	f=fopen(fname, "r");
+	if (!f)
+	{
+		perror(fname);
+		free(ch);
+		return NULL;
+	}
+	
+	while ((c=fgetc(f))!=EOF)
+	{
+		ch=realloc(ch, (++sz)*sizeof(char));
+		ch[sz-1]=c;
+	}
+
+	ch=realloc(ch, (++sz)*sizeof(char));
+	ch[sz-1]='\0';
+
+	return ch;
+}
+
+char *popen_read (char *cmd)
+{
+	char *ch=NULL, c;
+	int sz=0;
+	FILE *moo;
+
+	if (!cmd)
+		return NULL;
+
+	moo = popen(cmd, "r");
+	if (!moo)
+	{
+		perror("popen_read()");
+		return NULL;
+	}
+		
+	while ((c=fgetc(moo))!=EOF)
+	{
+		ch=realloc(ch, (++sz)*sizeof(char));
+		ch[sz-1]=c;
+	}
+
+	ch=realloc(ch, (++sz)*sizeof(char));
+	ch[sz-1]='\0';
+
+	pclose(moo);
+	return ch;
+}

Modified: dev/concept/moongoo/libalfs/gen.h
===================================================================
--- dev/concept/moongoo/libalfs/gen.h	2004-12-13 14:14:27 UTC (rev 1649)
+++ dev/concept/moongoo/libalfs/gen.h	2004-12-14 00:51:02 UTC (rev 1650)
@@ -5,4 +5,8 @@
 
 extern const char *compr[NUM_COMPR], *unpck[NUM_COMPR];
 
+char *directory (char *tarball);
+char *read_file (char *fname);
+char *popen_read (char *cmd);
+
 #endif

Modified: dev/concept/moongoo/libalfs/libalfs.h
===================================================================
--- dev/concept/moongoo/libalfs/libalfs.h	2004-12-13 14:14:27 UTC (rev 1649)
+++ dev/concept/moongoo/libalfs/libalfs.h	2004-12-14 00:51:02 UTC (rev 1650)
@@ -2,6 +2,7 @@
 #define __LIBALFS_H__
 
 #include <alfs.h>
+#include <crypto.h>
 #include <devel.h>
 #include <gen.h>
 #include <net.h>


Property changes on: dev/concept/moongoo/syntax
___________________________________________________________________
Name: svn:ignore
   - nalfs.so
ass.so
syn.so
blfs.so
book.so
rng.so
sample.so

   + nalfs.so
ass.so
syn.so
blfs.so
book.so
rng.so
sample.so
diyl.so


Modified: dev/concept/moongoo/syntax/Makefile
===================================================================
--- dev/concept/moongoo/syntax/Makefile	2004-12-13 14:14:27 UTC (rev 1649)
+++ dev/concept/moongoo/syntax/Makefile	2004-12-14 00:51:02 UTC (rev 1650)
@@ -1,6 +1,6 @@
 CFLAGS=-I../libalfs -I..
 
-LIBS=ass.so blfs.so book.so nalfs.so syn.so
+LIBS=ass.so blfs.so book.so diyl.so nalfs.so syn.so
 #LIBS+=sample.so
 
 all: $(LIBS)
@@ -10,5 +10,6 @@
 ass.so: ../libalfs/libalfs.a
 blfs.so: ../libalfs/libalfs.a
 book.so: ../libalfs/libalfs.a
+diyl.so: ../libalfs/libalfs.a
 nalfs.so: ../libalfs/libalfs.a
 syn.so: ../libalfs/libalfs.a

Modified: dev/concept/moongoo/syntax/ass.c
===================================================================
--- dev/concept/moongoo/syntax/ass.c	2004-12-13 14:14:27 UTC (rev 1649)
+++ dev/concept/moongoo/syntax/ass.c	2004-12-14 00:51:02 UTC (rev 1650)
@@ -17,6 +17,7 @@
 	return &ass_plugin;
 }
 
+// TODO: Implement the new ASS syntax
 static void t_shell (xmlNodePtr node, void *data)
 {
 	parse_cmdblock(prof, node);
@@ -28,13 +29,13 @@
 
 	if (xmlGetProp(node, "sha1"))
 	{
-		moo->algo = SHA1;
+		moo->algo = ALGO_SHA1;
 		moo->sum = xmlGetProp(node, "sha1");
 	}
 	else
 	if (xmlGetProp(node, "md5"))
 	{
-		moo->algo = MD5;
+		moo->algo = ALGO_MD5;
 		moo->sum = xmlGetProp(node, "md5");
 	}
 	

Added: dev/concept/moongoo/syntax/diyl.c
===================================================================
--- dev/concept/moongoo/syntax/diyl.c	2004-12-13 14:14:27 UTC (rev 1649)
+++ dev/concept/moongoo/syntax/diyl.c	2004-12-14 00:51:02 UTC (rev 1650)
@@ -0,0 +1,57 @@
+#include <plugin.h>
+
+profile *prof;
+
+profile *parse_diyl (xmlNodePtr node, replaceable *r);
+
+static t_plug diyl_plugin =
+{
+	name:	"DIY Linux",
+	vers:	PLUG_VER,
+	parse:	parse_diyl
+};
+
+t_plug *getplug ()
+{
+	return &diyl_plugin;
+}
+
+static void t_userinput (xmlNodePtr node, void *data)
+{
+	parse_cmdblock(prof, node);
+}
+
+static void t_sect2 (xmlNodePtr node, void *data)
+{
+	package *pkg = next_pkg_title(prof, node);
+	foreach(node->children, "userinput", (xml_handler_t)t_userinput, NULL);
+
+	if (!pkg->n)
+		prof->ch[prof->n-1].n--;
+}
+
+static void t_sect1 (xmlNodePtr node, void *data)
+{
+	chapter *ch = next_chpt(prof);
+	ch->name = find_value(node->children, "title");
+	ch->ref = xmlGetProp(node, "id");
+	foreach(node->children, "sect2", (xml_handler_t)t_sect2, NULL);
+}
+
+profile *parse_diyl (xmlNodePtr node, replaceable *r)
+{
+	xmlNodePtr info = find_node(node, "articleinfo");
+	
+	if (!info)
+	{
+		fprintf(stderr, "XML document is not a valid DIY Linux refbuild.\n");
+		return NULL;
+	}
+
+	prof = new_prof();
+	prof->name = find_value(info, "title");
+	prof->vers = find_value(info, "pubdate");
+
+	foreach(node->children, "sect1", (xml_handler_t)t_sect1, NULL);
+	return prof;
+}

Modified: dev/concept/moongoo/syntax/syn.c
===================================================================
--- dev/concept/moongoo/syntax/syn.c	2004-12-13 14:14:27 UTC (rev 1649)
+++ dev/concept/moongoo/syntax/syn.c	2004-12-14 00:51:02 UTC (rev 1650)
@@ -46,7 +46,7 @@
 {
 	download *dl = next_dl(prof);
 
-	dl->algo = SHA1;
+	dl->algo = ALGO_SHA1;
 	dl->sum = xmlGetProp(node, "sha");
 	
 	foreach(node->children, "ftp", (xml_handler_t)t_dl, dl);


Property changes on: dev/concept/moongoo/test
___________________________________________________________________
Name: svn:ignore
   - tst_squeeze

   + tst_squeeze
tst_sha1
tst_md5


Modified: dev/concept/moongoo/test/Makefile
===================================================================
--- dev/concept/moongoo/test/Makefile	2004-12-13 14:14:27 UTC (rev 1649)
+++ dev/concept/moongoo/test/Makefile	2004-12-14 00:51:02 UTC (rev 1650)
@@ -2,7 +2,7 @@
 
 CFLAGS=-I. -I../libalfs
 
-TESTS=tst_squeeze
+TESTS=tst_md5 tst_sha1 tst_squeeze
 
 .PHONY: all
 
@@ -15,4 +15,6 @@
 
 include ../inc.mak
 
+tst_md5: tst.o ../libalfs/libalfs.a
+tst_sha1: tst.o ../libalfs/libalfs.a
 tst_squeeze: tst.o ../libalfs/libalfs.a

Added: dev/concept/moongoo/test/tst_md5.c
===================================================================
--- dev/concept/moongoo/test/tst_md5.c	2004-12-13 14:14:27 UTC (rev 1649)
+++ dev/concept/moongoo/test/tst_md5.c	2004-12-14 00:51:02 UTC (rev 1650)
@@ -0,0 +1,11 @@
+#include <stdio.h>
+
+#include <libalfs.h>
+#include <tst.h>
+
+int main (int argc, char **argv)
+{
+	char *sum = popen_read("md5sum /etc/fstab");
+	sum = strcut(sum, 0, whereis(sum, ' '));
+	return tst_harness(md5sum("/etc/fstab"), sum);
+}

Added: dev/concept/moongoo/test/tst_sha1.c
===================================================================
--- dev/concept/moongoo/test/tst_sha1.c	2004-12-13 14:14:27 UTC (rev 1649)
+++ dev/concept/moongoo/test/tst_sha1.c	2004-12-14 00:51:02 UTC (rev 1650)
@@ -0,0 +1,11 @@
+#include <stdio.h>
+
+#include <libalfs.h>
+#include <tst.h>
+
+int main (int argc, char **argv)
+{
+	char *sum = popen_read("sha1sum /etc/fstab");
+	sum = strcut(sum, 0, whereis(sum, ' '));
+	return tst_harness(sha1sum("/etc/fstab"), sum);
+}

Modified: dev/concept/moongoo/test/tst_squeeze.c
===================================================================
--- dev/concept/moongoo/test/tst_squeeze.c	2004-12-13 14:14:27 UTC (rev 1649)
+++ dev/concept/moongoo/test/tst_squeeze.c	2004-12-14 00:51:02 UTC (rev 1650)
@@ -1,4 +1,4 @@
-#include <util.h>
+#include <libalfs.h>
 #include <tst.h>
 
 int main (int argc, char **argv)




More information about the alfs-log mailing list