[PC-BSD Commits] r1185 - pcbsd/trunk/SoundDetect
svn at pcbsd.org
svn at pcbsd.org
Tue Jan 15 19:23:25 PST 2008
Author: carlos
Date: 2008-01-15 19:23:24 -0800 (Tue, 15 Jan 2008)
New Revision: 1185
Modified:
pcbsd/trunk/SoundDetect/Makefile
pcbsd/trunk/SoundDetect/sound_detect.c
Log:
update xml file using libcurl
Modified: pcbsd/trunk/SoundDetect/Makefile
===================================================================
--- pcbsd/trunk/SoundDetect/Makefile 2008-01-16 03:09:30 UTC (rev 1184)
+++ pcbsd/trunk/SoundDetect/Makefile 2008-01-16 03:23:24 UTC (rev 1185)
@@ -3,17 +3,19 @@
OBJECTS= sound_detect.o parse_sound.o
CC=/usr/bin/gcc
-INCLUDES=-I/usr/local/include/libxml2 -I/usr/local/include
-LIB=-L/usr/local/lib -lxml2
+INCLUDES=-I/usr/local/include -I/usr/local/include/libxml2 -I/usr/local/include/curl
+LIB=-L/usr/local/lib -lxml2 -L/usr/local/lib -lcurl
-sound_detect :$(OBJECTS)
- $(CC) $(LIB) -o $(.TARGET) $(.ALLSRC)
+sound_detect : $(OBJECTS)
+ $(CC) $(OBJECTS) $(LIB) -o $(.TARGET)
strip sound_detect
sound_detect.o : sound_detect.c
- $(CC) -c sound_detect.c
+ $(CC) -c sound_detect.c $(INCLUDES)
parse_sound.o : parse_sound.c
- $(CC) $(INCLUDES) -c parse_sound.c
+ $(CC) $(INCLUDES) -c parse_sound.c
+
clean :
rm -f *.o
+ rm sound_detect
Modified: pcbsd/trunk/SoundDetect/sound_detect.c
===================================================================
--- pcbsd/trunk/SoundDetect/sound_detect.c 2008-01-16 03:09:30 UTC (rev 1184)
+++ pcbsd/trunk/SoundDetect/sound_detect.c 2008-01-16 03:23:24 UTC (rev 1185)
@@ -19,16 +19,20 @@
#include <sys/param.h>
#include <sys/linker.h>
#include </usr/src/sys/dev/pci/pcireg.h>
+#include <curl/curl.h>
#define _PATH_DEVPCI "/dev/pci"
#define SOUNDCARD_XML "/PCBSD/soundDetect/soundcards.xml"
+#define ALREADY_CALLED 2
+#define FIRST_CALL 1
/* Prototipes */
extern const char* parse_Sound_CardXML(char *docname, char* Vendor_Name, char* chip_id ) ;
-static void look_for_soundcard(void);
+static void look_for_soundcard(short called);
+static int update_soundcards_xml(void);
/* end proto*/
-static void look_for_soundcard()
+static void look_for_soundcard(short called)
{
int fd;
struct pci_conf_io pc;
@@ -85,11 +89,13 @@
warn("\nError loading module... ");
}else{
if(memcmp(kmodule,"snd_driver",10))
- {
+ {
+ if (called != ALREADY_CALLED)update_soundcards_xml();
printf("*** Great you have sound !!***\n");
printf("I have found a module for your card ! is : %s.\n",kmodule);
printf("i just have loaded the module for you !.\n");
}else {
+ if (called != ALREADY_CALLED)update_soundcards_xml();
printf("*** This is BAD !!***\n");
printf("I Could not find a driver for your card.\n");
printf("snd_driver was loaded..\n");
@@ -105,10 +111,70 @@
close(fd);
}
+static int copy_file(char* src , char* dest)
+{
+ int inF, ouF;
+ char line[512];
+ int bytes;
+ if((inF = open((const char*) src, O_RDONLY)) == -1) {
+ perror("open");
+ return -1;
+ }
+
+ if((ouF = open((const char*) dest, O_WRONLY | O_CREAT)) == -1) {
+ perror("open");
+ return -1;
+ }
+
+ while((bytes = read(inF, line, sizeof(line))) > 0)
+ write(ouF, line, bytes);
+
+ close(inF);
+ close(ouF);
+ return 0 ;
+}
+
+
+static int update_soundcards_xml(void)
+{
+
+ CURL *curl_handle;
+ static const char *new_soundcards_xml="/tmp/temp.soundcards.xml";
+ FILE* bodyfile ;
+
+
+ curl_global_init(CURL_GLOBAL_ALL);
+ curl_handle = curl_easy_init();
+
+ curl_easy_setopt(curl_handle, CURLOPT_URL, "updates.pcbsd.org/soundcards.xml");
+
+ curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, 1);
+
+ bodyfile = fopen(new_soundcards_xml,"w");
+
+ if (bodyfile == NULL) {
+ curl_easy_cleanup(curl_handle);
+ return -1;
+ }
+
+ curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, bodyfile);
+
+
+ curl_easy_perform(curl_handle);
+
+ fclose(bodyfile);
+
+ curl_easy_cleanup(curl_handle);
+
+ if (copy_file(new_soundcards_xml,SOUNDCARD_XML) == 0)
+ look_for_soundcard(ALREADY_CALLED);
+return 0 ;
+}
+
int main()
{
- look_for_soundcard();
+ look_for_soundcard(FIRST_CALL);
}
More information about the Commits
mailing list