00001 /* Copyright (C) 2005 MySQL AB 00002 00003 This program is free software; you can redistribute it and/or modify 00004 it under the terms of the GNU General Public License as published by 00005 the Free Software Foundation; either version 2 of the License, or 00006 (at your option) any later version. 00007 00008 This program is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 GNU General Public License for more details. 00012 00013 You should have received a copy of the GNU General Public License 00014 along with this program; if not, write to the Free Software 00015 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 00016 00017 #include <my_user.h> 00018 #include <m_string.h> 00019 00020 00021 /* 00022 Parse user value to user name and host name parts. 00023 00024 SYNOPSIS 00025 user_id_str [IN] User value string (the source). 00026 user_id_len [IN] Length of the user value. 00027 user_name_str [OUT] Buffer to store user name part. 00028 Must be not less than USERNAME_LENGTH + 1. 00029 user_name_len [OUT] A place to store length of the user name part. 00030 host_name_str [OUT] Buffer to store host name part. 00031 Must be not less than HOSTNAME_LENGTH + 1. 00032 host_name_len [OUT] A place to store length of the host name part. 00033 */ 00034 00035 void parse_user(const char *user_id_str, uint user_id_len, 00036 char *user_name_str, uint *user_name_len, 00037 char *host_name_str, uint *host_name_len) 00038 { 00039 char *p= strrchr(user_id_str, '@'); 00040 00041 if (!p) 00042 { 00043 *user_name_len= 0; 00044 *host_name_len= 0; 00045 } 00046 else 00047 { 00048 *user_name_len= p - user_id_str; 00049 *host_name_len= user_id_len - *user_name_len - 1; 00050 00051 memcpy(user_name_str, user_id_str, *user_name_len); 00052 memcpy(host_name_str, p + 1, *host_name_len); 00053 } 00054 00055 user_name_str[*user_name_len]= 0; 00056 host_name_str[*host_name_len]= 0; 00057 }
1.4.7

