This commit is contained in:
parent
72b0312b81
commit
29c2c49b07
|
@ -0,0 +1,3 @@
|
|||
add_library(leoext SHARED lib.c)
|
||||
|
||||
set_target_properties(leoext PROPERTIES COMPILE_FLAGS "-m32" LINK_FLAGS "-m32")
|
|
@ -0,0 +1,60 @@
|
|||
#include <stdio.h>
|
||||
#include <curl/curl.h>
|
||||
|
||||
__attribute__((dllexport)) void RVExtension(char *output, int outputSize, const char *function);
|
||||
__attribute__((dllexport)) int RVExtensionArgs(char *output, int outputSize, const char *function, const char **argv, int argc);
|
||||
__attribute__((dllexport)) void RVExtensionVersion(char *output, int outputSize);
|
||||
|
||||
int strncpy_safe(char *output, const char *src, int size)
|
||||
{
|
||||
int i;
|
||||
size--;
|
||||
for (i = 0; i < size && src[i] != '\0'; i++)
|
||||
{
|
||||
output[i] = src[i];
|
||||
}
|
||||
output[i] = '\0';
|
||||
return i;
|
||||
}
|
||||
|
||||
void RVExtension(char *output, int outputSize, const char *function)
|
||||
{
|
||||
strncpy_safe(output, function, outputSize);
|
||||
printf("RVExtention: test call\n");
|
||||
}
|
||||
|
||||
int RVExtensionArgs(char *output, int outputSize,
|
||||
const char *function,
|
||||
const char **argv, int argc)
|
||||
{
|
||||
CURL *curl;
|
||||
CURLcode res;
|
||||
|
||||
/* get a curl handle */
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
/* First set the URL that is about to receive our POST. This URL can
|
||||
just as well be a https:// URL if that is what should receive the
|
||||
data. */
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "http://localhost:5000/post-test");
|
||||
/* Now specify the POST data */
|
||||
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "Arma3 request!");
|
||||
|
||||
/* Perform the request, res will get the return code */
|
||||
res = curl_easy_perform(curl);
|
||||
/* Check for errors */
|
||||
if(res != CURLE_OK)
|
||||
fprintf(stderr, "curl_easy_perform() failed: %s\n",
|
||||
curl_easy_strerror(res));
|
||||
|
||||
/* always cleanup */
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void RVExtensionVersion(char *output, int outputSize)
|
||||
{
|
||||
curl_global_init(CURL_GLOBAL_ALL);
|
||||
strncpy_safe(output, "Leo-Extension v0.1", outputSize);
|
||||
}
|
45
server.lisp
45
server.lisp
|
@ -2,6 +2,7 @@
|
|||
(ql:quickload :flexi-streams)
|
||||
(ql:quickload :file-types)
|
||||
(ql:quickload :cl-ppcre)
|
||||
(load "utils.lisp")
|
||||
|
||||
(defparameter +static-directory+ "~/arma3/static/")
|
||||
|
||||
|
@ -30,6 +31,13 @@
|
|||
`(200 (:content-type ,mime-string) ,file-path))
|
||||
(route-not-found))))
|
||||
|
||||
(defun route-display-post (env)
|
||||
(let* ((decoded-stream
|
||||
(flex:make-flexi-stream (getf env :raw-body) :external-format :utf-8))
|
||||
(result (read-string-stream decoded-stream)))
|
||||
(format t "~&post body:~A~%" result)
|
||||
(route-hello-world nil)))
|
||||
|
||||
(defun dispatch (request-path dispatch-table)
|
||||
;; path: request url
|
||||
;; dispatch-table: '(matcher function)
|
||||
|
@ -47,29 +55,26 @@
|
|||
|
||||
(defparameter +dispatch-table+
|
||||
`(("^/$" ,#'route-hello-world)
|
||||
("^/post-test$" ,#'route-display-post)
|
||||
(,(concatenate 'string "^" +static-prefix+ ".*$") ,#'serve-static-file)
|
||||
(nil ,#'route-not-found)))
|
||||
|
||||
(require :sb-sprof)
|
||||
|
||||
(sb-sprof:with-profiling
|
||||
(:max-samples 2000
|
||||
:report :flat
|
||||
:loop nil)
|
||||
(handler-case
|
||||
(woo:run
|
||||
(lambda (env)
|
||||
;;(print env)
|
||||
;;(print (type-of env))
|
||||
(if (eq :post (getf env :request-method))
|
||||
(let* ((post-stream (getf env :raw-body))
|
||||
(char-stream (flexi-streams:make-flexi-stream
|
||||
post-stream
|
||||
:external-format :utf-8)))))
|
||||
(if (not (find-package 'swank))
|
||||
(woo:run
|
||||
(lambda (env)
|
||||
;;(print env)
|
||||
;;(print (type-of env))
|
||||
(if (eq :post (getf env :request-method))
|
||||
(let* ((post-stream (getf env :raw-body))
|
||||
(char-stream (flexi-streams:make-flexi-stream
|
||||
post-stream
|
||||
:external-format :utf-8)))))
|
||||
;(format t (read-line char-stream))))
|
||||
;(format t "dispatching...")
|
||||
(let ((route-function (dispatch (getf env :request-uri) +dispatch-table+)))
|
||||
;(format t "select route: ~A~%" route-function)
|
||||
(funcall route-function env))))
|
||||
(condition () nil)))
|
||||
(let ((route-function (dispatch (getf env :request-uri) +dispatch-table+)))
|
||||
(format t "method:~A uri:~A route: ~A~%"
|
||||
(getf env :request-method)
|
||||
(getf env :request-uri)
|
||||
route-function)
|
||||
(funcall route-function env)))))
|
||||
|
||||
|
|
38
utils.lisp
38
utils.lisp
|
@ -4,3 +4,41 @@
|
|||
:element-type '(unsigned-byte 8))))
|
||||
(read-sequence buffer stream)
|
||||
buffer)))
|
||||
|
||||
(defun make-dynamic-string (&optional length)
|
||||
(make-array length :adjustable t
|
||||
:fill-pointer 0
|
||||
:element-type 'character))
|
||||
;; (let ((s (make-dynamic-string)))
|
||||
;; (vector-push-extend #\a s)
|
||||
;; (vector-push-extend #\b s)
|
||||
;; s)
|
||||
|
||||
(defmacro mvb-let* (bindings &body body)
|
||||
(let* ((exp (car bindings))
|
||||
(vars (butlast exp))
|
||||
(multi-val-exp (car (last exp)))
|
||||
(rest-bindings (cdr bindings)))
|
||||
(if rest-bindings
|
||||
`(multiple-value-bind ,vars ,multi-val-exp
|
||||
(mvb-let* ,rest-bindings ,@body))
|
||||
`(multiple-value-bind ,vars ,multi-val-exp
|
||||
,@body))))
|
||||
;; (defun test-binding-0 ()
|
||||
;; (values 1 2))
|
||||
;; (defun test-binding-1 ()
|
||||
;; (values 1 2 3))
|
||||
;; (mvb-let* ((a b (test-binding-0))
|
||||
;; (c d e (test-binding-1)))
|
||||
;; (list a b c d e))
|
||||
|
||||
(defun read-string-stream (stream)
|
||||
(let* ((buffer (make-string 5))
|
||||
(result-list '()))
|
||||
(do ((read-count (read-sequence buffer stream)
|
||||
(read-sequence buffer stream)))
|
||||
((= read-count 0) nil)
|
||||
(push (subseq buffer 0 read-count) result-list))
|
||||
(format nil "~{~a~}" (reverse result-list))))
|
||||
;; (with-input-from-string (s "0123456789012")
|
||||
;; (read-string-stream s))
|
||||
|
|
Loading…
Reference in New Issue