Commits

Matt Emborsky committed 9f7ee1e

Pulling updates from tkoskine/ladybird into his initial oauth library for
continued development as a stand alone library.

Comments (0)

Files changed (7)

---
--- Copyright (c) 2011 Tero Koskinen <tero.koskinen@iki.fi>
---
--- Permission to use, copy, modify, and distribute this software for any
--- purpose with or without fee is hereby granted, provided that the above
--- copyright notice and this permission notice appear in all copies.
---
--- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
--- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
--- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
--- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
--- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
--- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
--- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
---
-
 with Ada.Strings.Fixed; use Ada.Strings.Fixed;
 with Ada.Text_IO; use Ada.Text_IO;
 with SHA;
 with SHA.Strings;
 with HMAC_SHA;
 with HTTP;
+with Hauki.Charbuf;
 
 package body OAuth.Easy is
+   use Hauki;
+   use Hauki.Charbuf;
+   
    function "+"(Str : String) return Unbounded_String
      renames To_Unbounded_String;
 
       Ctx : HMAC_SHA.HMAC_Context;
       Sig : Unbounded_String;
       H : Unbounded_String;
-      Result : Unbounded_String;
+      Result : Charbuf.Char_Buffer;
       R_Code : Long_Integer;
    begin
       Params := OAuth.Create_Parameter_List
             OAuth.Timestamp,
             To_String (Context.Key) & URL),
          Version      => "1.0");
+      OAuth.Parameter_List.Append (Params, (Key => +"oauth_callback",
+                                            Value => +"oob"));
 
       Base_Str := To_Unbounded_String (OAuth.Create_Base_String
         (Method, URL, Params));
       HMAC_SHA.Finalize (Result => Digest_Val,
                          Context => Ctx);
       Sig := +(String (SHA.Strings.B64_From_SHA (Digest_Val)));
+
       OAuth.Parameter_List.Append (Params, (Key => +"oauth_signature",
                                             Value => Sig));
       OAuth.Parameter_Sorting.Sort (Params);
          Header_Value => To_String (H),
          Contents => Result,
          Response_Code => R_Code);
+      Put_Line ("Result: " & To_String (Result));
       Parse_Request_Result
         (To_String (Result), Context.Token, Context.Token_Secret);
    end Request_Token;
       Ctx : HMAC_SHA.HMAC_Context;
       Sig : Unbounded_String;
       H : Unbounded_String;
-      Result : Unbounded_String;
+      Result : Charbuf.Char_Buffer;
       R_Code : Long_Integer;
    begin
       Params := OAuth.Create_Parameter_List
          Version      => "1.0");
       OAuth.Parameter_List.Append (Params, (Key => +"oauth_verifier",
                                             Value => +Verifier));
-
+      OAuth.Parameter_Sorting.Sort (Params);
       Base_Str := +(OAuth.Create_Base_String (Method, URL, Params));
       Put_Line ("Base string: " & To_String (Base_Str));
 
       OAuth.Parameter_Sorting.Sort (OAuth_Params);
       OAuth.Parameter_Sorting.Sort (Params);
       OAuth.Parameter_Sorting.Merge (Target => Params, Source => OAuth_Params);
-
       Base_Str := +(OAuth.Create_Base_String (Method, URL, Params));
-
+      Put_Line ("Base string: " & To_String (Base_Str));
       HMAC_SHA.Initialize
         (Key     => To_String (Context.Secret) & "&" & Temp_Secret,
          Context => Ctx);
       Sig := +(String (SHA.Strings.B64_From_SHA (Digest_Val)));
       OAuth.Parameter_List.Append (Params, (Key => +"oauth_signature",
                                             Value => Sig));
-      OAuth.Parameter_Sorting.Sort (Params);
       OAuth.Parameter_List.Prepend (Params, (Key => +"realm",
                                             Value => +""));
+      OAuth.Parameter_Sorting.Sort (Params);
       Header := +(OAuth.Params_To_Header (Params));
    end As_Header;
 
---
--- Copyright (c) 2011 Tero Koskinen <tero.koskinen@iki.fi>
---
--- Permission to use, copy, modify, and distribute this software for any
--- purpose with or without fee is hereby granted, provided that the above
--- copyright notice and this permission notice appear in all copies.
---
--- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
--- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
--- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
--- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
--- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
--- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
--- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
---
-
 with Ada.Strings.Unbounded;
 
 use Ada.Strings.Unbounded;
---
--- Copyright (c) 2011 Tero Koskinen <tero.koskinen@iki.fi>
---
--- Permission to use, copy, modify, and distribute this software for any
--- purpose with or without fee is hereby granted, provided that the above
--- copyright notice and this permission notice appear in all copies.
---
--- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
--- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
--- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
--- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
--- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
--- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
--- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
---
-
 with Ada.Strings;
 with Ada.Strings.Fixed;
 with Interfaces;
    end Compare_Pairs;
 
    function URL_Encode (Str : String) return String is
-      Reserved : constant String := ":/?#[]@!$&'()*+,;= ";
+      Reserved : constant String := ":/?#[]@!$&'()*+,;= %";
       function Is_Reserved (Char : Character) return Boolean is
       begin
          for I in Reserved'Range loop
          if Is_First then
             Is_First := False;
          else
-            Append (Param_Str, URL_Encode ("&"));
+            Append (Param_Str, "&");
          end if;
          declare
             Pair_Str : Unbounded_String := Element (Pos).Key;
          begin
-            Append (Pair_Str, URL_Encode ("="));
+            Append (Pair_Str, "=");
             Append (Pair_Str, URL_Encode (To_String (Element (Pos).Value)));
-            Append (Param_Str, URL_Encode (To_String (Pair_Str)));
+            Append (Param_Str, To_String (Pair_Str));
          end;
          Next (Pos);
       end loop;
 
       return Method & "&" & URL_Encode (URL) & "&" &
-        To_String (Param_Str);
+        URL_Encode (To_String (Param_Str));
    end Create_Base_String;
 
    function Params_To_String (Request_Parameters : Parameter_List.List)
---
--- Copyright (c) 2011 Tero Koskinen <tero.koskinen@iki.fi>
---
--- Permission to use, copy, modify, and distribute this software for any
--- purpose with or without fee is hereby granted, provided that the above
--- copyright notice and this permission notice appear in all copies.
---
--- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
--- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
--- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
--- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
--- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
--- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
--- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
---
-
 with Ada.Strings.Unbounded;
 
 with Hauki.Containers.Doubly_Linked_Lists;
---
--- Copyright (c) 2011 Tero Koskinen <tero.koskinen@iki.fi>
---
--- Permission to use, copy, modify, and distribute this software for any
--- purpose with or without fee is hereby granted, provided that the above
--- copyright notice and this permission notice appear in all copies.
---
--- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
--- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
--- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
--- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
--- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
--- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
--- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
---
 with Ada.Strings.Unbounded;
 with Ada.Text_IO;
 with OAuth;
---
--- Copyright (c) 2011 Tero Koskinen <tero.koskinen@iki.fi>
---
--- Permission to use, copy, modify, and distribute this software for any
--- purpose with or without fee is hereby granted, provided that the above
--- copyright notice and this permission notice appear in all copies.
---
--- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
--- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
--- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
--- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
--- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
--- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
--- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
---
 with Ada.Text_IO; use Ada.Text_IO;
 
 package body Utils is
---
--- Copyright (c) 2011 Tero Koskinen <tero.koskinen@iki.fi>
---
--- Permission to use, copy, modify, and distribute this software for any
--- purpose with or without fee is hereby granted, provided that the above
--- copyright notice and this permission notice appear in all copies.
---
--- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
--- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
--- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
--- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
--- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
--- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
--- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
---
 with Interfaces;
 
 package Utils is