vfs: check userland buffers before reading them.
[haiku.git] / docs / develop / servers / app_server / TokenHandler.htm
blobae7954b572e7f8ae1ce303b3312ffd9065cd9735
1 <HTML>
2 <HEAD>
3 <TITLE>TokenHandler.htm</TITLE>
4 <style type="text/css">
5 <!--
6 .Default {background-color: rgb(255,255,255); color: rgb(0,0,0); font-family: 'Dutch801 Rm BT'; font-size: 12pt}
7 .OBOS-Function-Def {background-color: rgb(255,255,255); color: rgb(0,0,0); font-family: 'Dutch801 Rm BT'; font-size: 16pt}
8 .OBOS-Title {background-color: rgb(255,255,255); color: rgb(0,128,0); font-family: 'Dutch801 Rm BT'; font-size: 24pt}
9 .Text-Background {background-color: rgb(255,255,255)}
10 .GR-Default {}
11 .Body {margin: 0px}
12 .Footer {margin: 0px}
13 .Header {margin: 0px}
14 .WP-Default {text-align: left; text-indent: 0px; margin-left: 0px; margin-right: 0px}
15 -->
16 </style>
17 </HEAD>
18 <BODY BGCOLOR="#ffffff">
19 <DIV class="sheet" id="Sheet 1">
20 <P class="Body" style="margin: 0px"><span class="OBOS-Title">TokenHandler class</span><span style="color: rgb(0,0,0); font-size: 24pt"></span></P>
21 <P class="Body" style="margin: 0px"><BR>
22 This is a simple way to provide tokens for various reasons. </P>
23 <P class="Body" style="margin: 0px"><BR>
24 <HR>
25 </P>
26 <P class="Body" style="margin: 0px"><BR>
27 Member Functions</P>
28 <P class="Body" style="margin: 0px"><BR>
29 </P>
30 <TABLE WIDTH=617 HEIGHT=113 BORDER=1 CELLPADDING=1 CELLSPACING=2>
31 <TR>
32 <TD WIDTH=203 HEIGHT=17>
33 <P class="Body" style="margin: 0px">TokenHandler(void)</P>
34 </TD>
35 <TD WIDTH=260 HEIGHT=17>
36 <P class="Body" style="margin: 0px">~TokenHandler(void)</P>
37 </TD>
38 </TR>
39 <TR>
40 <TD WIDTH=203 HEIGHT=17>
41 <P class="Body" style="margin: 0px">int32 GetToken(void)</P>
42 </TD>
43 <TD WIDTH=260 HEIGHT=17>
44 <P class="Body" style="margin: 0px">void Reset(void)</P>
45 </TD>
46 </TR>
47 <TR>
48 <TD WIDTH=203 HEIGHT=17>
49 <P class="Body" style="margin: 0px">void ExcludeValue(int32 value)</P>
50 </TD>
51 <TD WIDTH=260 HEIGHT=17>
52 <P class="Body" style="margin: 0px">void ResetExcludes(void)</P>
53 </TD>
54 </TR>
55 <TR>
56 <TD WIDTH=203 HEIGHT=17>
57 <P class="Body" style="margin: 0px">bool IsExclude(int32 value)</P>
58 </TD>
59 <TD WIDTH=260 HEIGHT=17>
60 &nbsp;
61 </TD>
62 </TR>
63 <TR>
64 <TD WIDTH=203 HEIGHT=17>
65 &nbsp;
66 </TD>
67 <TD WIDTH=260 HEIGHT=17>
68 &nbsp;
69 </TD>
70 </TR>
71 </TABLE>
72 <P class="Body" style="margin: 0px"><BR>
73 <BR>
74 <HR>
75 </P>
76 <P class="Body" style="margin: 0px"><span class="OBOS-Function-Def">TokenHandler(void)</span></P>
77 <P class="Body" style="margin: 0px"><BR>
78 1) Initialize the index to -1</P>
79 <P class="Body" style="margin: 0px">2) create the access semaphore</P>
80 <P class="Body" style="margin: 0px">3) create the exclude list with no items</P>
81 <P class="Body" style="margin: 0px"><BR>
82 <BR>
83 <span class="OBOS-Function-Def">~TokenHandler(void)</span></P>
84 <P class="Body" style="margin: 0px"><BR>
85 1) delete the access lock</P>
86 <P class="Body" style="margin: 0px">2) call ResetExcludes and delete the exclude list</P>
87 <P class="Body" style="margin: 0px"><BR>
88 <BR>
89 <span class="OBOS-Function-Def">int32 GetToken(void)</span></P>
90 <P class="Body" style="margin: 0px"><BR>
91 Returns a unique token which is not equal to any excluded values</P>
92 <P class="Body" style="margin: 0px"><BR>
93 1) create a local variable to return the new token</P>
94 <P class="Body" style="margin: 0px">2) acquire the access semaphore</P>
95 <P class="Body" style="margin: 0px">3) Increment the internal index</P>
96 <P class="Body" style="margin: 0px">4) while IsExclude(index) is true, increment the index</P>
97 <P class="Body" style="margin: 0px">5) assign it to the local variable</P>
98 <P class="Body" style="margin: 0px">6) release the access semaphore</P>
99 <P class="Body" style="margin: 0px">7) return the local variable</P>
100 <P class="Body" style="margin: 0px"><BR>
101 <BR>
102 <span class="OBOS-Function-Def">void Reset(void)</span></P>
103 <P class="Body" style="margin: 0px"><BR>
104 1) acquire the access semaphore</P>
105 <P class="Body" style="margin: 0px">2) set the internal index to -1</P>
106 <P class="Body" style="margin: 0px">3) release the access semaphore</P>
107 <P class="Body" style="margin: 0px"><BR>
108 <BR>
109 <span class="OBOS-Function-Def">void ExcludeValue(int32 value)</span></P>
110 <P class="Body" style="margin: 0px"><BR>
111 1) acquire the access semaphore</P>
112 <P class="Body" style="margin: 0px">2) if IsExclude(value) is false, add it to the exclude list</P>
113 <P class="Body" style="margin: 0px">3) release the access semaphore</P>
114 <P class="Body" style="margin: 0px"><BR>
115 <BR>
116 <span class="OBOS-Function-Def">void ResetExcludes(void)</span></P>
117 <P class="Body" style="margin: 0px"><BR>
118 1) acquire the access semaphore</P>
119 <P class="Body" style="margin: 0px">2) Iterate through the exclude list, removing and deleting each item</P>
120 <P class="Body" style="margin: 0px">3) release the access semaphore</P>
121 <P class="Body" style="margin: 0px"><BR>
122 <BR>
123 <span class="OBOS-Function-Def">bool IsExclude(int32 value)</span></P>
124 <P class="Body" style="margin: 0px"><BR>
125 1) create a boolean match flag and set it to false</P>
126 <P class="Body" style="margin: 0px">2) acquire the access semaphore</P>
127 <P class="Body" style="margin: 0px">3) iterate through the exclude list and see if the value matches any in the list</P>
128 <P class="Body" style="margin: 0px">4) If there is a match, set the match flag to true and exit the loop</P>
129 <P class="Body" style="margin: 0px">5) release the access semaphore</P>
130 <P class="Body" style="margin: 0px">6) return the match flag</P>
131 <DIV class="layer" id="Layer 1">
132 </DIV>
133 </DIV>
134 </BODY>
135 </HTML>