Browse Source

HTTP をモヂュール化

main
Miteruzo 1 year ago
parent
commit
464dcb0032
2 changed files with 74 additions and 40 deletions
  1. +52
    -0
      modules/http.mod.hsp
  2. +22
    -40
      modules/user.mod.hsp

+ 52
- 0
modules/http.mod.hsp View File

@@ -0,0 +1,52 @@
#ifndef __HTTP__
#define __HTTP__

#module \
Http

#enum STATUS_SUCCESS = 1
#enum STATUS_ERROR

#deffunc \
Fetch \
str p_url,\
local l_res,\
local l_size
HTTPLoad p_url

If stat = 0 {
Repeat
HTTPInfo l_res, HTTPINFO_MODE

Switch l_res
Case HTTPMODE_READY
Case HTTPMODE_NONE
Case HTTPMODE_ERROR
Break
SwEnd

Wait 5
Loop

If l_res = HTTPMODE_READY {
HTTPInfo l_size, HTTPINFO_SIZE

SDim data, l_size
HTTPInfo data, HTTPINFO_DATA

status = STATUS_SUCCESS

Return
}
}

HTTPInfo errMsg, HTTPINFO_ERROR

status = STATUS_ERROR

Return

#global

#endif ; not __HTTP__


+ 22
- 40
modules/user.mod.hsp View File

@@ -1,3 +1,9 @@
#include "./modules/http.mod.hsp"


#ifndef __USER__
#define __USER__

#module \
User

@@ -6,59 +12,35 @@ User

#deffunc local \
Create \
str p_name,\
local l_res,\
local l_size,\
str p_name,
local l_data
HTTPLoad CREATE_URL + "?name=" + p_name

If stat = 0 {
Repeat
HTTPInfo l_res, HTTPINFO_MODE

Switch l_res
Case HTTPMODE_READY
Case HTTPMODE_NONE
Case HTTPMODE_ERROR
Break
SwEnd

Wait 5
Loop

If l_res = HTTPMODE_READY {
HTTPInfo l_size, HTTPINFO_SIZE
Fetch@Http CREATE_URL + "?name=" + p_name

SDim l_data, l_size
If status@Http = STATUS_SUCCESS@Http {
Split data@Http, ",", l_data

HTTPInfo l_data, HTTPINFO_DATA
Split l_data, ",", l_data

id = l_data.0
pass = l_data.1
inheritanceCode = l_data.2

Return
}
id = Int (l_data.0)
pass = l_data.1
inheritanceCode = l_data.2
}
Else {
id = 0
pass = ""
inheritanceCode = ""
}

id = 0
pass = ""
inheritanceCode = ""

Return -1
Return

#deffunc local \
Fetch \
Auth \
int p_id,\
local l_data
id = userId@Setting
pass = userPasscode@Setting

HTTPLoad StrF ("%s?id=%d&pass=%s", CREATE_URL, id, pass)
HTTPInfo l_data

Return

#global

#endif ; not __USER__


Loading…
Cancel
Save