azawawi / perl6-net-curl Goto Github PK
View Code? Open in Web Editor NEWUse libcurl (client-side URL transfer library) API in Perl 6
License: MIT License
Use libcurl (client-side URL transfer library) API in Perl 6
License: MIT License
I'm trying to pass authentication headers through CURLOPT_HTTPHEADER with no luck using NativeCall API. Would be nice to get example about it :)
Note: I'm not reporting as a user, but just spotted this during unrelated testing
During installation (and possibly during use), warnings are generated on Rakudo brewed today. I believe this is due to changes in NativeCall:
==> Installing Net::Curl
Potential difficulties:
In '_curl_easy_setopt' routine declaration - Not an accepted NativeCall type for parameter [2] : int
--> For Numerical type, use the appropriate int32/int64/num64...
at /home/zoffix/.rakudobrew/moar-nom/install/share/perl6/site/sources/D0C7C55EB5D3510037DEEF0CE015FC1168499049:232
------> is symbol('curl_easy_setopt') { ... }⏏<EOL>
The returning type of '_curl_easy_setopt' --> int is erroneous. You should not return a non NativeCall supported type (like Int inplace of int32), truncating errors can appear with different architectures
at /home/zoffix/.rakudobrew/moar-nom/install/share/perl6/site/sources/D0C7C55EB5D3510037DEEF0CE015FC1168499049:232
------> is symbol('curl_easy_setopt') { ... }⏏<EOL>
In '_curl_easy_setopt_cb' routine declaration - Not an accepted NativeCall type for parameter [2] : int
--> For Numerical type, use the appropriate int32/int64/num64...
at /home/zoffix/.rakudobrew/moar-nom/install/share/perl6/site/sources/D0C7C55EB5D3510037DEEF0CE015FC1168499049:244
------> is symbol('curl_easy_setopt') { ... }⏏<EOL>
The returning type of '_curl_easy_setopt_cb' --> int is erroneous. You should not return a non NativeCall supported type (like Int inplace of int32), truncating errors can appear with different architectures
at /home/zoffix/.rakudobrew/moar-nom/install/share/perl6/site/sources/D0C7C55EB5D3510037DEEF0CE015FC1168499049:244
------> is symbol('curl_easy_setopt') { ... }⏏<EOL>
The returning type of 'curl_easy_perform' --> int is erroneous. You should not return a non NativeCall supported type (like Int inplace of int32), truncating errors can appear with different architectures
at /home/zoffix/.rakudobrew/moar-nom/install/share/perl6/site/sources/D0C7C55EB5D3510037DEEF0CE015FC1168499049:290
------> is export { ... }⏏;
In 'curl_easy_strerror' routine declaration - Not an accepted NativeCall type for parameter [1] : int
--> For Numerical type, use the appropriate int32/int64/num64...
at /home/zoffix/.rakudobrew/moar-nom/install/share/perl6/site/sources/D0C7C55EB5D3510037DEEF0CE015FC1168499049:296
------> is export { ... }⏏;
In 'curl_easy_getinfo' routine declaration - Not an accepted NativeCall type for parameter [2] : int
--> For Numerical type, use the appropriate int32/int64/num64...
at /home/zoffix/.rakudobrew/moar-nom/install/share/perl6/site/sources/D0C7C55EB5D3510037DEEF0CE015FC1168499049:308
------> is export { ... }⏏;
The returning type of 'curl_easy_getinfo' --> int is erroneous. You should not return a non NativeCall supported type (like Int inplace of int32), truncating errors can appear with different architectures
at /home/zoffix/.rakudobrew/moar-nom/install/share/perl6/site/sources/D0C7C55EB5D3510037DEEF0CE015FC1168499049:308
------> is export { ... }⏏;
In 'curl_global_init' routine declaration - Not an accepted NativeCall type for parameter [1] : int
--> For Numerical type, use the appropriate int32/int64/num64...
at /home/zoffix/.rakudobrew/moar-nom/install/share/perl6/site/sources/D0C7C55EB5D3510037DEEF0CE015FC1168499049:313
------> is export { ... }⏏;
The returning type of 'curl_global_init' --> int is erroneous. You should not return a non NativeCall supported type (like Int inplace of int32), truncating errors can appear with different architectures
at /home/zoffix/.rakudobrew/moar-nom/install/share/perl6/site/sources/D0C7C55EB5D3510037DEEF0CE015FC1168499049:313
------> is export { ... }⏏;
==> Successfully installed Net::Curl
$ perl6 -v
This is Rakudo version 2015.12-101-g75c6b9e built on MoarVM version 2015.12
implementing Perl 6.c.
I'm trying to write an uploader for http://oops.moe (documentation available there).
I don't know exactly what I'm doing wrong here, so let me just provide the code and errors:
(half-baked) code:
#!/usr/bin/env perl6
#
# oops - oops.moe uploader
# (c) ix 2016
#
## INCLUDES
use v6;
use strict;
use Net::Curl;
use JSON::Tiny;
## VARS
my $oopskey = slurp "%*ENV<HOME>/.oopsrc";
my %colors = (
'red' => '�[1;31m',
'reset' => '�[1;0m'
);
## SETUP
my $curl = curl_easy_init;
err "Failed to initialize libcurl!" unless $curl;
## SUBROUTINES
sub err($msg) { # pretty print errors
say "{%colors<red>}[ERR]{%colors<reset>} $msg";
exit 1;
}
sub usage() {
err "usage: oops [files]";
}
sub upload($file) { # upload that shit!
curl_easy_setopt($curl, CURLOPT_URL, 'http://oops.moe/upload.php');
curl_easy_setopt($curl, CURLOPT_POSTFIELDS, "key=$oopskey");
curl_easy_setopt($curl, CURLOPT_POSTFIELDS, "file=@$file");
curl_easy_setopt($curl, CURLOPT_POSTFIELDS, 'method="json"');
curl_easy_perform($curl);
}
sub remove($file) { # remove the file!
}
sub parse($json) { # parse json
}
## EXECUTE
sub MAIN($file?) {
without $file {
usage;
}
upload $file;
}
# vim: set ft=perl6 :
Error:
Cannot call curl_easy_setopt(NativeCall::Types::Pointer.new(109076464), 10002, "http://oops.moe/upload.php"); none of these signatures match:
(NativeCall::Types::Pointer $point, Int $ where { ... }, $value is rw --> int32)
(NativeCall::Types::Pointer $point, uint16 $code, Str $value --> uint8)
in sub upload at /home/arc/bin/oops line 39
in sub MAIN at /home/arc/bin/oops line 60
in block <unit> at /home/arc/bin/oops line 56
In many places size_t is incorrectly mapped to signed int, for example:
C signature
size_t write_callback(char *ptr, size_t size, size_t nmemb, void *userdata);
NativeCall signature
sub callback( Pointer $ptr , int $size, int $nmemb, OpaquePointer $wtf --> int )
According to C standard size_t is unsigned type.
Also it generally follows machine registers size.
So it should be more correctly mapped to ulong.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.