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 000000000..0b24e4643 Binary files /dev/null and b/gb.net.curl/src/gb.net.curl/.icon.png differ diff --git a/gb.net.curl/src/gb.net.curl/.info b/gb.net.curl/src/gb.net.curl/.info new file mode 100644 index 000000000..f79e59ef1 --- /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 +