From c9f03a1150b8ab4f163c9cd43c4e9650cf0ba024 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Minisini?= Date: Sun, 19 Oct 2014 22:18:10 +0000 Subject: [PATCH] [GB.NET.CURL] * NEW: Add a Gambas part to the component. * NEW: HttpForm is a new class that inherits HttpClient and that allows to post HTML forms easily. git-svn-id: svn://localhost/gambas/trunk@6567 867c0c6c-44f3-4631-809d-bfa615b0a4ec --- gb.net.curl/src/gb.net.curl/.directory | 2 + gb.net.curl/src/gb.net.curl/.gitignore | 13 ++ gb.net.curl/src/gb.net.curl/.icon.png | Bin 0 -> 2982 bytes gb.net.curl/src/gb.net.curl/.info | 31 +++++ gb.net.curl/src/gb.net.curl/.list | 1 + gb.net.curl/src/gb.net.curl/.project | 10 ++ .../src/gb.net.curl/.src/HttpForm.class | 121 ++++++++++++++++++ gb.net.curl/src/gb.net.curl/.src/MMain.module | 5 + gb.net.curl/src/gb.net.curl/.startup | 9 ++ 9 files changed, 192 insertions(+) create mode 100644 gb.net.curl/src/gb.net.curl/.directory create mode 100644 gb.net.curl/src/gb.net.curl/.gitignore create mode 100644 gb.net.curl/src/gb.net.curl/.icon.png create mode 100644 gb.net.curl/src/gb.net.curl/.info create mode 100644 gb.net.curl/src/gb.net.curl/.list create mode 100644 gb.net.curl/src/gb.net.curl/.project create mode 100644 gb.net.curl/src/gb.net.curl/.src/HttpForm.class create mode 100644 gb.net.curl/src/gb.net.curl/.src/MMain.module create mode 100644 gb.net.curl/src/gb.net.curl/.startup diff --git a/gb.net.curl/src/gb.net.curl/.directory b/gb.net.curl/src/gb.net.curl/.directory new file mode 100644 index 000000000..06dab1c8a --- /dev/null +++ b/gb.net.curl/src/gb.net.curl/.directory @@ -0,0 +1,2 @@ +[Desktop Entry] +Icon=./.icon.png diff --git a/gb.net.curl/src/gb.net.curl/.gitignore b/gb.net.curl/src/gb.net.curl/.gitignore new file mode 100644 index 000000000..cb95c3b71 --- /dev/null +++ b/gb.net.curl/src/gb.net.curl/.gitignore @@ -0,0 +1,13 @@ +#---- Gambas files to ignore (v1) +*.gambas +.lock +*~ +core +core.* +vgcore +vgcore.* +.kdbg* +.*.prof +.lang/*.pot +.gambas/* +#---- diff --git a/gb.net.curl/src/gb.net.curl/.icon.png b/gb.net.curl/src/gb.net.curl/.icon.png new file mode 100644 index 0000000000000000000000000000000000000000..0b24e4643a3d537c727a31bbca7a39e3bdfecfc7 GIT binary patch literal 2982 zcmV;X3t9AuP){MFup^IMnxV&n_34i2=Fj7P%VPkg@my~!Eg)I&{lQ7c;)TE~qv=Nz{$b7g5? z@B7A!y?0DEk()29n%Z9VE?=Nl<5hiqjzuepB*4DV2?$kOs)hmSd zrn{I_gx2}FfR~^Aa`hL--!l_EU>yYZ<^=#)QT6ejpJYT&Tv88CbYo%xLI}gD9no|{ zAU4tUi3K1Z*k%*L>(IGYfX5zF*_`Ui4-mxt;&Vj$0j%NT8xr0ZCQP zP<1Iqag7%J^E;RVTw?(y^h`wQv@&CFOoj(^ooQjPVjdFsxX!bjtGBFfxE=RiGfE47 zI)y1JL8<8z!;NDW33S?MtuohGfctnB5cnA`UFjfFUk}a^+4*Ub7fx|!MTE1=s z5wd+RAZ|b^IS_8j~uzk_n!JLEwBC#cohvz%iE-IQ816hm>4qH)rv@1E11gG3FZJu+Etv466e_OMh=0YqqT5g*Te$Or|NS zs>PHf7-)HmvUS@@UGC-c^)U`)=5eO!br$S;i1c6z^^?8S`yR(peD1T4u&};yhA59k z#ONMDLV(aZ{_MV@S_2T#;)xIkP!6mWve`88TrbwH;Bwhwq`!@9Zx^|ND2aw`44yth zqG};;p6a1Aa~zW>Cwc5=MB>FHmTn+czL4MBw3A3IK9iisK+Dwy2_@pe$o~RboQIY; zfOUwnAOu|MYNt0^gf|o+(Xf>u)lcfg&u}(iL0vs1Ljw#(qVx|!NmR2m?qf8RRn>Ca z9rw)?&+9_;sAMp7qXaN2Q&7f+h*g4)L`f{DBT`z*(82v={WKy%Y|(ORynd81bmu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59ef1 --- /dev/null +++ b/gb.net.curl/src/gb.net.curl/.info @@ -0,0 +1,31 @@ +#HttpForm +HttpClient +C +Add +m + +(Field)s(Value)s +AddFile +m + +(Field)s(Path)s[(Name)s] +Remove +m + +(Field)s +_get +m +s +(Field)s +_put +m + +(Value)s(Field)s +Clear +m + + +Submit +m + + diff --git a/gb.net.curl/src/gb.net.curl/.list b/gb.net.curl/src/gb.net.curl/.list new file mode 100644 index 000000000..8602e9904 --- /dev/null +++ b/gb.net.curl/src/gb.net.curl/.list @@ -0,0 +1 @@ +HttpForm diff --git a/gb.net.curl/src/gb.net.curl/.project b/gb.net.curl/src/gb.net.curl/.project new file mode 100644 index 000000000..d60bc4305 --- /dev/null +++ b/gb.net.curl/src/gb.net.curl/.project @@ -0,0 +1,10 @@ +# Gambas Project File 3.0 +# Compiled with Gambas 3.6.90 +Title=gb.net.curl +Startup=MMain +Version=3.6.90 +VersionFile=1 +Component=gb.net +Component=gb.net.curl +TabSize=2 +Packager=1 diff --git a/gb.net.curl/src/gb.net.curl/.src/HttpForm.class b/gb.net.curl/src/gb.net.curl/.src/HttpForm.class new file mode 100644 index 000000000..ffff9a6a2 --- /dev/null +++ b/gb.net.curl/src/gb.net.curl/.src/HttpForm.class @@ -0,0 +1,121 @@ +' Gambas class file + +Export + +Inherits HttpClient + +Private $cVal As New Collection +Private $aField As New String[] +Private $cFile As New Collection + +Public Sub Add(Field As String, Value As String) + + If Not $aField.Exist(Field) Then $aField.Add(Field) + $cVal[Field] = Value + +End + +Public Sub AddFile(Field As String, Path As String, Optional Name As String) + + If Left(Path) <> "/" Then Path = ".." &/ Path + If Not Exist(Path) Then Error.Raise("File does not exists") + + If Not Name Then Name = File.Name(Path) + Add(Field, Name) + $cFile[Field] = Path + +End + +Public Sub Remove(Field As String) + + Dim iPos As Integer + + iPos = $aField.Find(Field) + If iPos < 0 Then Return + + $aField.Remove(iPos) + $cVal.Remove(Field) + $cFile.Remove(Field) + +End + +Public Sub _get(Field As String) As String + + Return $cVal[Field] + +End + +Public Sub _put(Value As String, Field As String) + + Add(Field, Value) + +End + +Public Sub Clear() + + $cVal.Clear + $aField.Clear + +End + + +Public Sub Submit() + + Dim sBoundary As String + Dim sPath As Variant + Dim I As Integer + Dim sPost As String + Dim hPost As File + Dim sField As String + + Do + + sBoundary = "------" + For I = 1 To 4 + sBoundary &= Hex$(Int(Rnd(65536)), 4) + Next + + For Each sPath In $cFile + If InStr(File.Load(sPath), sBoundary) Then Continue + Next + + Break + + Loop + + sPost = Temp$() + + hPost = Open sPost For Create + hPost.EndOfLine = gb.Windows + + For Each sField In $aField + + Print #hPost, "--"; sBoundary + + sPath = $cFile[sField] + + If sPath Then + + Print #hPost, "Content-Disposition: form-data; name=\""; sField; "\"; filename=\""; $cVal[sField]; "\"" + Print #hPost, "Content-Type: application/octet-stream" + Print #hPost + Print #hPost, File.Load(sPath) + + Else + + Print #hPost, "Content-Disposition: form-data; name=\""; sField; "\"" + Print #hPost, "Content-Type: text/plain; charset=\"utf-8\"" + Print #hPost + Print #hPost, $cVal[sField] + + Endif + + Next + + Print #hPost, "--"; sBoundary; "--" + + hPost.Close + + Me.PostFile("multipart/form-data; boundary=" & sBoundary, sPost, ["Content-Length: " & CStr(Stat(sPost).Size)]) + +End diff --git a/gb.net.curl/src/gb.net.curl/.src/MMain.module b/gb.net.curl/src/gb.net.curl/.src/MMain.module new file mode 100644 index 000000000..c21a66e7b --- /dev/null +++ b/gb.net.curl/src/gb.net.curl/.src/MMain.module @@ -0,0 +1,5 @@ +' Gambas module file + +Public Sub Main() + +End diff --git a/gb.net.curl/src/gb.net.curl/.startup b/gb.net.curl/src/gb.net.curl/.startup new file mode 100644 index 000000000..eb9667abf --- /dev/null +++ b/gb.net.curl/src/gb.net.curl/.startup @@ -0,0 +1,9 @@ +MMain +gb.net.curl +0 +0 +3.6.90 + +gb.net +gb.net.curl +