1
by brian
clean slate |
1 |
/* Copyright (C) 2005 MySQL AB
|
2 |
||
3 |
This program is free software; you can redistribute it and/or modify
|
|
4 |
it under the terms of the GNU General Public License as published by
|
|
5 |
the Free Software Foundation; version 2 of the License.
|
|
6 |
||
7 |
This program is distributed in the hope that it will be useful,
|
|
8 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
9 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
10 |
GNU General Public License for more details.
|
|
11 |
||
12 |
You should have received a copy of the GNU General Public License
|
|
13 |
along with this program; if not, write to the Free Software
|
|
14 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
15 |
||
16 |
#include <my_user.h> |
|
17 |
#include <m_string.h> |
|
18 |
#include <mysql_com.h> |
|
19 |
||
20 |
/*
|
|
21 |
Parse user value to user name and host name parts.
|
|
22 |
||
23 |
SYNOPSIS
|
|
24 |
user_id_str [IN] User value string (the source).
|
|
25 |
user_id_len [IN] Length of the user value.
|
|
26 |
user_name_str [OUT] Buffer to store user name part.
|
|
27 |
Must be not less than USERNAME_LENGTH + 1.
|
|
28 |
user_name_len [OUT] A place to store length of the user name part.
|
|
29 |
host_name_str [OUT] Buffer to store host name part.
|
|
30 |
Must be not less than HOSTNAME_LENGTH + 1.
|
|
31 |
host_name_len [OUT] A place to store length of the host name part.
|
|
32 |
*/
|
|
33 |
||
34 |
void parse_user(const char *user_id_str, size_t user_id_len, |
|
35 |
char *user_name_str, size_t *user_name_len, |
|
36 |
char *host_name_str, size_t *host_name_len) |
|
37 |
{
|
|
38 |
char *p= strrchr(user_id_str, '@'); |
|
39 |
||
40 |
if (!p) |
|
41 |
{
|
|
42 |
*user_name_len= 0; |
|
43 |
*host_name_len= 0; |
|
44 |
}
|
|
45 |
else
|
|
46 |
{
|
|
47 |
*user_name_len= p - user_id_str; |
|
48 |
*host_name_len= user_id_len - *user_name_len - 1; |
|
49 |
||
50 |
if (*user_name_len > USERNAME_LENGTH) |
|
51 |
*user_name_len= USERNAME_LENGTH; |
|
52 |
||
53 |
if (*host_name_len > HOSTNAME_LENGTH) |
|
54 |
*host_name_len= HOSTNAME_LENGTH; |
|
55 |
||
56 |
memcpy(user_name_str, user_id_str, *user_name_len); |
|
57 |
memcpy(host_name_str, p + 1, *host_name_len); |
|
58 |
}
|
|
59 |
||
60 |
user_name_str[*user_name_len]= 0; |
|
61 |
host_name_str[*host_name_len]= 0; |
|
62 |
}
|