2 Copyright (c) 2006-2008 MySQL AB, 2009 Sun Microsystems, Inc.
3 Use is subject to license terms.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; version 2 of the License.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #include <mysql_com.h>
24 Parse user value to user name and host name parts.
27 user_id_str [IN] User value string (the source).
28 user_id_len [IN] Length of the user value.
29 user_name_str [OUT] Buffer to store user name part.
30 Must be not less than USERNAME_LENGTH + 1.
31 user_name_len [OUT] A place to store length of the user name part.
32 host_name_str [OUT] Buffer to store host name part.
33 Must be not less than HOSTNAME_LENGTH + 1.
34 host_name_len [OUT] A place to store length of the host name part.
37 void parse_user(const char *user_id_str
, size_t user_id_len
,
38 char *user_name_str
, size_t *user_name_len
,
39 char *host_name_str
, size_t *host_name_len
)
41 char *p
= strrchr(user_id_str
, '@');
50 *user_name_len
= (uint
) (p
- user_id_str
);
51 *host_name_len
= (uint
) (user_id_len
- *user_name_len
- 1);
53 if (*user_name_len
> USERNAME_LENGTH
)
54 *user_name_len
= USERNAME_LENGTH
;
56 if (*host_name_len
> HOSTNAME_LENGTH
)
57 *host_name_len
= HOSTNAME_LENGTH
;
59 memcpy(user_name_str
, user_id_str
, *user_name_len
);
60 memcpy(host_name_str
, p
+ 1, *host_name_len
);
63 user_name_str
[*user_name_len
]= 0;
64 host_name_str
[*host_name_len
]= 0;