Skip to contentSkip to conversation

Add HTTP protocol using curl v6

PATCH New [email protected] 1 participant 1 message May 11, 2009 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add HTTP protocol using curl v6

From: Alexander Graf <[email protected]>

Currently Qemu can read from posix I/O and NBD. This patch adds a third protocol to the game: HTTP.

In certain situations it can be useful to access HTTP data directly, for example if you want to try out an http provided OS image, but don't know if you want to download it yet.

Using this patch you can now try it on on the fly. Just use it like:

qemu -cdrom http://host/path/my.iso

In order to not reinvent the wheel, this patch uses libcurl.

v2 changes:

- fix the segfault (yay!)
- implement AIO

v3 changes:

- remove synchronous API
- implement caching

v4 changes:

- enable other protocols (HTTPS, FTP, FTPS, TFTP, SFTP, SCP) (I only tested FTP so far, but they _should_ work)

v5 changes:

- address Anthony's comments
- deactivate ssh protocols again

v6 changes:

- s/^I/ /g
- s/http/curl/g

---
 Makefile        |    6 +
 Makefile.target |    2 +-
 block-curl.c    |  540 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 block.c         |   12 ++
 block.h         |    7 +
 configure       |   25 +++
 6 files changed, 591 insertions(+), 1 deletions(-)
 create mode 100644 block-curl.c
Makefile +6 -0
index 3c70068..421cd41 100644
@@ -77,6 +77,10 @@ endif
 BLOCK_OBJS += block-raw-posix.o
 endif
 
+ifdef CONFIG_CURL
+BLOCK_OBJS += block-curl.o
+endif
+
 ######################################################################
 # libqemu_common.a: Target independent part of system emulation. The
 # long term path is to suppress *all* target specific code in case of
@@ -185,6 +189,8 @@ endif
 
 LIBS+=$(VDE_LIBS)
 
+LIBS+=$(CURL_LIBS)
+
 cocoa.o: cocoa.m
 
 keymaps.o: keymaps.c keymaps.h
Makefile.target +1 -1
index f735105..3a9226c 100644
@@ -735,7 +735,7 @@ endif
 
 vl.o: qemu-options.h
 
-$(QEMU_PROG): LIBS += $(SDL_LIBS) $(COCOA_LIBS) $(CURSES_LIBS) $(BRLAPI_LIBS) $(VDE_LIBS)
+$(QEMU_PROG): LIBS += $(SDL_LIBS) $(COCOA_LIBS) $(CURSES_LIBS) $(BRLAPI_LIBS) $(VDE_LIBS) $(CURL_LIBS)
 
 $(QEMU_PROG): $(OBJS) ../libqemu_common.a libqemu.a
 	$(LINK)
block-curl.c new file +540 -0

540 lines not on this page · raw message

block.c +12 -0
index 3d1223d..55af1eb 100644
@@ -1504,6 +1504,18 @@ void bdrv_init(void)
     bdrv_register(&bdrv_qcow2);
     bdrv_register(&bdrv_parallels);
     bdrv_register(&bdrv_nbd);
+#ifdef CONFIG_CURL
+    bdrv_register(&bdrv_http);
+    bdrv_register(&bdrv_https);
+    bdrv_register(&bdrv_ftp);
+    bdrv_register(&bdrv_ftps);
+    bdrv_register(&bdrv_tftp);
+#if 0
+    /* SSH over curl can't detect file sizes :-( */
+    bdrv_register(&bdrv_sftp);
+    bdrv_register(&bdrv_scp);
+#endif
+#endif
 }
 
 void aio_pool_init(AIOPool *pool, int aiocb_size,
block.h +7 -0
index 5aef076..5e554e8 100644
@@ -20,6 +20,13 @@ extern BlockDriver bdrv_vvfat;
 extern BlockDriver bdrv_qcow2;
 extern BlockDriver bdrv_parallels;
 extern BlockDriver bdrv_nbd;
+extern BlockDriver bdrv_http;
+extern BlockDriver bdrv_https;
+extern BlockDriver bdrv_ftp;
+extern BlockDriver bdrv_ftps;
+extern BlockDriver bdrv_sftp;
+extern BlockDriver bdrv_scp;
+extern BlockDriver bdrv_tftp;
 
 typedef struct BlockDriverInfo {
     /* in bytes, 0 if irrelevant */
configure +25 -0
index 82fb60a..49b5b84 100755
@@ -181,6 +181,7 @@ bsd_user="no"
 build_docs="no"
 uname_release=""
 curses="yes"
+curl="yes"
 pthread="yes"
 aio="yes"
 io_thread="no"
@@ -477,6 +478,8 @@ for opt do
   ;;
   --disable-curses) curses="no"
   ;;
+  --disable-curl) curl="no"
+  ;;
   --disable-nptl) nptl="no"
   ;;
   --enable-mixemu) mixemu="yes"
@@ -600,6 +603,7 @@ echo "  --disable-brlapi         disable BrlAPI"
 echo "  --disable-vnc-tls        disable TLS encryption for VNC server"
 echo "  --disable-vnc-sasl       disable SASL encryption for VNC server"
 echo "  --disable-curses         disable curses output"
+echo "  --disable-curl           disable curl connectivity"
 echo "  --disable-bluez          disable bluez stack connectivity"
 echo "  --disable-kvm            disable KVM acceleration support"
 echo "  --disable-nptl           disable usermode NPTL support"
@@ -1062,6 +1066,21 @@ EOF
 fi # test "$curses"
 
 ##########################################
+# curl probe
+
+if test "$curl" = "yes" ; then
+  curl=no
+  cat > $TMPC << EOF
+#include <curl/curl.h>
+int main(void) { return curl_easy_init(); }
+EOF
+  curl_libs=`curl-config --libs`
+ if $cc $ARCH_CFLAGS $curl_libs -o $TMPE $TMPC > /dev/null 2> /dev/null ; then
+    curl=yes
+  fi
+fi # test "$curl"
+
+##########################################
 # bluez support probe
 if test "$bluez" = "yes" ; then
   `pkg-config bluez 2> /dev/null` || bluez="no"
@@ -1311,6 +1330,7 @@ if test "$sdl" != "no" ; then
     echo "SDL static link   $sdl_static"
 fi
 echo "curses support    $curses"
+echo "curl support      $curl"
 echo "mingw32 support   $mingw32"
 echo "Audio drivers     $audio_drv_list"
 echo "Extra audio cards $audio_card_list"
@@ -1637,6 +1657,11 @@ fi
 if test "$inotify" = "yes" ; then
   echo "#define CONFIG_INOTIFY 1" >> $config_h
 fi
+if test "$curl" = "yes" ; then
+  echo "CONFIG_CURL=yes" >> $config_mak
+  echo "CURL_LIBS=$curl_libs" >> $config_mak
+  echo "#define CONFIG_CURL 1" >> $config_h
+fi
 if test "$brlapi" = "yes" ; then
   echo "CONFIG_BRLAPI=yes" >> $config_mak
   echo "#define CONFIG_BRLAPI 1" >> $config_h
Signature · 1 line
1.6.0.2