Temp

#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <string.h>
#include <direct.h >
#include <io.h>

#include "tools.h"
#include "urldecode.h"


void test(){
    char *t = "那个abcd你好吗,哈哈,ANMOL"; 
    int i = 0; 
    int j;
    int len;
    char *dec;
    char* enc;
    j = strlen(t); 
    enc = tl_base64_encode(t, j); 
    len = strlen(enc); 
    dec = tl_base64_decode(enc, len); 
    printf("\noriginal: %s\n", t); 
    printf("\nencoded : %s\n", enc); 
    printf("\ndecoded : %s\n", dec); 
    free(enc); 
    free(dec); 
}

/*
    获取post中的数据
*/
void http_post_data(){
    
    
    
    char *info=NULL;
    char* content = NULL;
    int lenstr=0;
    int i,length;
    char* dec;
    char result[1024];
    memset(result,0,1024);
    
    content = getenv("CONTENT_LENGTH");
    if(content!=NULL){
        int i;
        lenstr=atoi(content);
        info=(char *)malloc(lenstr+1);
        memset(info,0,lenstr+1);
        fread(info,1,lenstr,stdin);
        //printf("%s",info);
        //for(i = 0;i<lenstr;i++){
        //    printf("%d,",info[i]);
        //}
        
//        void URLDecode(const char* URL,char* result){    
//        URLDecode((const char*)info,result);    
//        printf("%s",result);
        /*
        length = strlen(info);
        dec = tl_base64_decode(info, length);
        printf("%s",dec); 
        free(dec);
        free(info);
        */
        //printf("%s",content);
        
        //printf("%d",lenstr);
        
        /*
        for(i = 0;i<lenstr;i++){
            printf("%s",info[i]);
        }
        */
        
        
        



    }else{
        printf("null");    
    }    
}

void main(int argc, char *argv[]){
    //struct LogStruct* _plog = NULL;
    //gLog = (struct LogStruct*)malloc(sizeof(struct LogStruct));
    //_plog = gLog;

    //_plog->fnType = -1;
    //memset(_plog->mapPath,0,G_BUFFER_256_SIZE);

    //获取exe执行路径
    //tl_get_exe_path(argv,_plog->mapPath);
        
    //printf("Content-Type:application/octet-stream;charset=gb2312\n\n");
    
    //http get获取数据
    //http_parse_getData(_plog);
    
    //http post获取数据    
    //http_post_data();
    
    //free(_plog);
    


    #define MAX_SIZE_BYTE 2048
    int i, n;
    int pos;
    char ch;
    char buffer[MAX_SIZE_BYTE];
    char data[MAX_SIZE_BYTE];
    printf("Content-type:text/plain;chatset=utf-8\n\n" );
    if( getenv("CONTENT_LENGTH"))    n = atoi( getenv("CONTENT_LENGTH"));
    else {
        n = 0;
        fprintf(stdout, "(NULL)");
        return;
    }
    if(n >= MAX_SIZE_BYTE)    {
        printf("bytes is overflow!");
        return;
    }
    memset(buffer,0,MAX_SIZE_BYTE);
    memset(data,0,MAX_SIZE_BYTE);
    for(i = 0; i<n;i++){
        ch = getc(stdin);
        buffer[i]=ch;
    }
//    printf("%s",buffer);
    #define _SEACH_STR_ "\"bytes\"; filename=\"\"\n"
    pos = tl_strpos(buffer,_SEACH_STR_,0) + strlen(_SEACH_STR_)+1;
    memcpy(data,buffer+pos,4);
    for(i = 0;i<4;i++){
        printf("%d,",data[i]);
    }
    //[0,0,74,121,]
}
/*
[
--mXXmuq1DOSsjeHlLejBd4C4IDjx59efK971gRKyv
Content-Type: text/plain; charset="utf-8"
Content-disposition: form-data; name="frameCount"

(3870)
--mXXmuq1DOSsjeHlLejBd4C4IDjx59efK971gRKyv
Content-Type: application/octet-stream
Content-disposition: form-data; name="bytes"; filename=""

ABab
--mXXmuq1DOSsjeHlLejBd4C4IDjx59efK971gRKyv--
????????????]
UnityEngine.MonoBehaviour:print(Object)
<screenAndUploadCoroutine>c__Iterator4:MoveNext() (at Assets/Script/Login.cs:83)
*/
using UnityEngine;
using System.Collections;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using System.Runtime.InteropServices;

public class Login : MonoBehaviour
{
    // This example assumes that the user has entered his name into a
    // variable called name and that score contains the user's current
    // score.
    /*
    string highscore_url = "http://127.0.0.1/cgi-bin/savelog.cgi";
    string playName = "Player 1";
    int score = -1;
    */

    [DllImport("Test")]
    private static extern int addT (int a, int b);

    public UIButton TestButton;

    void Awake(){
        UIEventListener.Get (TestButton.gameObject).onClick = onClickHandle;
    }

    void onClickHandle(GameObject go){
        if(go == TestButton.gameObject){
/*
            Debug.Log(Time.frameCount.ToString());

            //Debug.Log (addT (10, 3).ToString ());
            WWWForm form = new WWWForm ();
            byte[] bs = new byte[] {10,0,121,252};
            string str = Convert.ToBase64String (bs.ToArray ());
            //form.AddBinaryData("a", bs, "application/octet-stream");
            //string str = string.Join(",",bs.Select(t=>t.ToString()).ToArray());
            //form.AddBinaryData ("p.png", bs);
            form.AddField ("a", str);
            WWW www = new WWW ("http://127.0.0.1/cgi-bin/savelog.cgi", form);
            StartCoroutine (WaitForRequestRegister (www));
*/
            StartCoroutine(screenAndUpload());
        }
    }

    IEnumerator screenAndUpload(){
        Texture2D tex = new Texture2D(Screen.width,Screen.height);
        yield return new WaitForEndOfFrame();
        tex.ReadPixels(new Rect(0,0,Screen.width,Screen.height),0,0);
        tex.Apply();
        byte[] bytes = tex.EncodeToPNG();
        Destroy(tex);
        WWWForm form = new WWWForm ();
        form.AddField ("frameCount","("+Time.frameCount.ToString()+")");
//        byte[] _uploadBytes = testBytes;
        form.AddBinaryData ("bytes", testBytes,"");//_uploadBytes.Length.ToString()
        string url = "http://127.0.0.1/cgi-bin/savelog.cgi" + "?" + UnityEngine.Random.Range (0.0f, 1.0f);
        //Debug.Log (url);
        WWW w = new WWW (url, form);
        StartCoroutine (screenAndUploadCoroutine(w));
    }

    byte[] testBytes{
        get{
            byte[] bytes = new byte[] {65,66,97,98};

            send = new ArrayList();
            addInt(19065);
            byte[] ss = (byte[])send.ToArray(typeof(byte));
            for(int i = 0;i <ss.Length;i++){
                print(ss[i].ToString());
            }

            return ss;
//            return bytes;
        }
    }


    IEnumerator screenAndUploadCoroutine(WWW w){
        yield return w;
        if (!String.IsNullOrEmpty (w.error)){
            //print (w.error);
        }else{
            //print ("Finished Uploading ScreenShot!");
            print("["+w.data+"]");
        }
    }

    void Start ()
    {
        
    }

    IEnumerator WaitForRequestRegister (WWW www)
    {
        yield return www;    
        if (www.error != null) {
            Debug.Log (www.error);
        } else {
            if (www.isDone) {
                Debug.Log ("from sever:("+www.data+")");
                //Debug.Log(www.bytes.Length);
                //byte[] result=Convert.FromBase64String(www.data);
                //for(int i = 0;i < result.Length;i++){
                //    Debug.Log(result[i]+",");
                //}
            }
        }
    }

    // Update is called once per frame
    void Update ()
    {
    
    }

    ArrayList send = new ArrayList();
    void addInt(int s){
        send.Add((byte) ((0xff000000 & s) >> 24));
        send.Add((byte) ((0xff0000 & s) >> 16));
        send.Add((byte) ((0xff00 & s) >> 8));
        send.Add((byte) (0xff & s));
    }
}

 

posted @ 2015-06-25 01:50  泥潭里的金鱼  阅读(282)  评论(0)    收藏  举报