File: sciInterface.c

package info (click to toggle)
openmohaa 0.81.1%2Bdfsg-2
  • links: PTS, VCS
  • area: contrib
  • in suites: trixie
  • size: 29,124 kB
  • sloc: ansic: 270,865; cpp: 250,173; sh: 234; asm: 141; xml: 64; makefile: 7
file content (132 lines) | stat: -rw-r--r-- 4,317 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
#include "sciInterface.h"


/* PRIVATE INTERFACE FUNCTIONS -- SCMAIN.C CONTAINS PUBLIC INTERFACE */


///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

// This is declared as an extern so it can be overridden when testing
#define SC_SERVICE_URL_FORMAT   "http://%s.comp.pubsvs." GSI_DOMAIN_NAME "/CompetitionService/CompetitionService.asmx"
char scServiceURL[SC_SERVICE_MAX_URL_LEN] = "";


///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////


///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
SCResult sciInterfaceCreate(SCInterface** theInterfaceOut)
{
#ifdef GSI_SC_STATIC_MEM
	static SCInterface gStaticInterface;
#endif

	GS_ASSERT(theInterfaceOut != NULL);

	// Check to see if the availability check has been performed and if it has
	// set the service URL prepended with the gamename
	if (__GSIACResult == GSIACAvailable)
	{
		if (scServiceURL[0] == '\0')
			snprintf(scServiceURL, SC_SERVICE_MAX_URL_LEN, SC_SERVICE_URL_FORMAT, __GSIACGamename);
	}
	else
		return SCResult_NO_AVAILABILITY_CHECK;	

#ifdef GSI_SC_STATIC_MEM
	*theInterfaceOut = &gStaticInterface;
#else
	*theInterfaceOut = (SCInterface*)gsimalloc(sizeof(SCInterface));
	if (*theInterfaceOut == NULL)
	{
		return SCResult_OUT_OF_MEMORY;
	}
#endif

	GS_ASSERT(*theInterfaceOut != NULL);
	memset(*theInterfaceOut, 0, sizeof(SCInterface));
	return SCResult_NO_ERROR;
}


///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
SCResult sciInterfaceInit(SCInterface* theInterface)
{
	SCResult anInitResult = SCResult_NO_ERROR;

	GS_ASSERT(theInterface != NULL);

	anInitResult = sciWsInit(&theInterface->mWebServices, theInterface);
	if (anInitResult != SCResult_NO_ERROR)
	{
		return anInitResult;
	}

	memset(theInterface->mSessionId, 0, sizeof(theInterface->mSessionId));
	memset(theInterface->mConnectionId, 0, sizeof(theInterface->mConnectionId));

	theInterface->mInit = gsi_true;
	return SCResult_NO_ERROR;
}


///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
void sciInterfaceDestroy(SCInterface* theInterface)
{
	GS_ASSERT(theInterface != NULL);
	GS_ASSERT(theInterface->mInit);

	sciWsDestroy(&theInterface->mWebServices);

	memset(theInterface->mSessionId, 0, sizeof(theInterface->mSessionId));
	memset(theInterface->mConnectionId, 0, sizeof(theInterface->mConnectionId));
	theInterface->mSessionId[0] = 0xde;
	theInterface->mSessionId[1] = 0xad;
	theInterface->mConnectionId[0] = 0xde;
	theInterface->mConnectionId[1] = 0xad;

	theInterface->mInit = gsi_false;
}


///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
void sciInterfaceSetSessionId(SCInterface * theInterface, const char * theSessionId)
{
	GS_ASSERT(theInterface != NULL);

	if (theSessionId == NULL)
		theInterface->mSessionId[0] = '\0';
	else
	{
		GS_ASSERT(strlen(theSessionId) < sizeof(theInterface->mSessionId));
		strcpy((char *)theInterface->mSessionId, theSessionId);
	}
}


///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
void sciInterfaceSetConnectionId(SCInterface * theInterface, const char * theConnectionId)
{
	GS_ASSERT(theInterface != NULL);

	if (theConnectionId == NULL)
		theInterface->mConnectionId[0] = '\0';
	else
	{
		GS_ASSERT(strlen(theConnectionId) < sizeof(theInterface->mConnectionId));
		strcpy((char *)theInterface->mConnectionId, theConnectionId);
	}
}


///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////